My game keeps crashing and i have no idea why. The worst thing is, it keeps crashing on different locations in the code. Sometimes it just freezes and the music keeps playing, sometimes it straight out closes. This happens most when i try to end a level and sometimes when i try to load a level after it was closed. I managed to pinpoint the location of the crash to multiple places and one that stuck out was when i try to delete an array of struct containing XMVECTOR.
From what i heard before i understand that i can't just new and delete structs that contain __m128 where XMVECTOR is typedef of this. I found a solution for this by redefining operators new and delete for these structs:
struct afKeyFrame
{
XMVECTOR vector;
float time;
void* operator new(size_t i)
{
return _mm_malloc(i, 16);
}
void* operator new[](size_t i)
{
return _mm_malloc(i, 16);
}
void operator delete(void* p)
{
_mm_free(p);
}
void operator delete[](void* p)
{
_mm_free(p);
}
};
// also later in the code
aPosition = new afKeyFrame[mNumPositionKeys];
SAFE_DELETE_ARRAY(aPosition);
My question is: Is this the correct way create dynamic arrays for structs that contain __m128 variables?