I've got a strange crash that only occurs in a Release build and so its very difficult to debug the problem.
If I try single stepping through the code, the current instruction jumps around all over the place (Presumably the code is being reordered as an optimization), and when the crash does occur the debugger put the current instructions somewhere completely illogical, I don't think this is a genuine stack corruption issue, I think the debugger just isn't very good when working with release builds.
Anyway, getting to the point....
The code is a text rendering code (Originally written by MJP), which I've adapted to work with DirectXMath, and sure enough this is where the problem seems to lie.
I the text rendering class I have this structure defined:
struct SpriteDrawData
{
XMMATRIX Transform;
XMFLOAT4 Color;
XMFLOAT4 DrawRect;
};
Then I have this member that uses this struct:
SpriteDrawData m_TextDrawData[constMaxBatchSize];
(Where constMaxBatchSize == 1000)
Then in the actual code I do this for each character:
m_TextDrawData[currentDraw].Transform = XMMatrixMultiply(transform, XMMatrixTranslation(x_offset, y_offset, 0.0f));
m_TextDrawData[currentDraw].Color = color;
m_TextDrawData[currentDraw].DrawRect.x = desc.X;
m_TextDrawData[currentDraw].DrawRect.y = desc.Y;
m_TextDrawData[currentDraw].DrawRect.z = desc.Width;
m_TextDrawData[currentDraw].DrawRect.w = desc.Height;
currentDraw++;
However, the first line causes a crash.
If I comment out the first line then it doesn't crash.
I've even tried changing it to this:
m_TextDrawData[currentDraw].Transform = XMMatrixIdentity();
m_TextDrawData[currentDraw].Color = color;
m_TextDrawData[currentDraw].DrawRect.x = desc.X;
m_TextDrawData[currentDraw].DrawRect.y = desc.Y;
m_TextDrawData[currentDraw].DrawRect.z = desc.Width;
m_TextDrawData[currentDraw].DrawRect.w = desc.Height;
currentDraw++;
But it still crashes (Even when currentDraw == 0, so its not that currentDraw is overflowing).
I thought it might be an alignment problem, so I changed the structure definition to:
__declspec(align(32)) struct SpriteDrawData
{
XMMATRIX Transform;
XMFLOAT4 Color;
XMFLOAT4 DrawRect;
};
But that didn't help, and I don't think its necessary as XMMATRIX is already defined with 16 byte alignment.
Its really strange. It doesn't do it in a debug build, and if I comment out the code then the release build is fine too but obviously I don't see any text.
Any help would be appreciated.
Thanks
Ben