Hi!
I have a a backbuffer rendering approach that fills a buffer with rendering primitives for the platform to render after a frame.
The "problem" is that I don't fully understand why I have to call memcpy for the following code to not crash.
| RenderCommandRect *rect = RenderBufferAlloc(renderCommandsBuffer, RenderCommandRect);
rect->pos = pos * M2P_FACTOR;
rect->size = size * M2P_FACTOR;
#if 1
// TODO(Hakan): why is this necessary?
memcpy(&rect->color, &color, sizeof(hmm_vec4));
#else
// This throws 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
rect->color = color;
#endif
rect->thickness = thickness;
|
I assume this is a problem because the hmm_vec4 is stored using SSE intrinsic?
The hmm_vec4 uses the default assignment operator, which to my understanding does a copy of each member(?)
| // Note this is somewhat simplified
typedef union hmm_vec4
{
float Elements[4];
__m128 InternalElementsSSE;
} hmm_vec4;
|
This is the generated assembly where it crashes on the last assembly instruction.
The value of xmm0 is as expected and the pointers in rax and rcx looks valid as well.
So then where does the alleged read from 0xFFFFFFFFFFFFFFFF occur? Could the debugger be reporting some sort of false-positives?
| rect->color = color;
00007FF905448243 mov rax,qword ptr [rect]
00007FF905448248 mov rcx,qword ptr [&color]
00007FF905448250 movups xmm0,xmmword ptr [rcx]
00007FF905448253 movdqa xmmword ptr [rax+10h],xmm0
|