You haven't given us all the types and class/structure definitions involved. You are also using a mess of casts and potential aliasing issues. You have to know what you are doing and be very careful to get this kind of stuff right.
anbluemoon wrote:
MD2Mesh::Frame* md2Frame = (MD2Mesh::Frame*)buffer;
Apparently, buffer is a SomeType_T *buffer
set to the address of a block of allocated memory. What is SomeType_T? How big a block of memory? What is a MD2Mesh::Frame? How big is a MD2Mesh::Frame? Also if MD2Mesh::Frame is not a pod type, you are dead without properly constructing it via its constructor.
anbluemoon wrote:
uint8* tmp = buffer + 40; MD2Mesh::Vertex* vtx = (MD2Mesh::Vertex*)tmp;
Your magic number could be subject to breakage due to changes. Additionally, it hides your intent. Also don't forget about alignment issues and padding that the compiler can insert in structs. md2Frame now points to the beginning of the buffer. vtx now points inside the buffer.
anbluemoon wrote:
md2Frame->vertices = vtx;
You have now changed part of the contents of the buffer. vtx has not changed at all. It is however a pointer, and what it points to in the buffer has changed because you wrote code to change it. Evidently, MD2Mesh::Frame.vertices is 40 * sizeof(SomeType_T) bytes from the beginning of the structure.
Please do not read this signature.