   DX Declaration/Vertex Buffer issue.
  The following code should run correctly.Sometimes, On release, the game crashes and when I try to click the debug button, it will take me to this part:(* ((LPD3DXVECTOR3)(data + VertexOffset))).z = - (* ((LPD3DXVECTOR3)(data + VertexOffset))).z;saying something about trying to access an invalid memory!all i do then is just rebuild the solution and re-try and it works.On Debug mode, it works perfectly, I reviewd the code many times and cannot figure out what is mising, maybe someone can help me, this is the full code:D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE];HRESULT res= object->g_pMesh->GetDeclaration(Declaration);int TextureOffset = 0 , VertexOffset = 0, NormalOffset = 0;bool NormalExists = false;for(int i =0; i  < MAX_FVF_DECL_SIZE; ++i){if(Declaration.Usage == D3DDECLUSAGE_TEXCOORD&& Declaration.Type == D3DDECLTYPE_FLOAT2){TextureOffset = Declaration.Offset;/*textures index*/}elseif(Declaration.Usage == D3DDECLUSAGE_POSITION&& Declaration.Type == D3DDECLTYPE_FLOAT3){VertexOffset = Declaration.Offset;}elseif(Declaration.Usage == D3DDECLUSAGE_NORMAL&& Declaration.Type == D3DDECLTYPE_FLOAT3){NormalExists = true;NormalOffset = Declaration.Offset;}}/*create the texture and normals buffers:*///vertexTextureCoordinates = new UV[numberOfVertices];//vertexNormals = new D3DXVECTOR3[numberOfVertices];object->minBounds = D3DXVECTOR3(1000.0f,1000.0f,1000.0f);object->maxBounds = D3DXVECTOR3(-1000.0f,-1000.0f,-1000.0f);/*retrieve the vertices, normals and textures from the vertex buffer:*/PBYTE data = 0;object->g_pMesh->LockVertexBuffer(D3DLOCK_READONLY, (PVOID*)&data);for(int i =0; i < numberOfVertices; ++i){//move to RH CSif((LPD3DXVECTOR3)(data + VertexOffset)){(* ((LPD3DXVECTOR3)(data + VertexOffset))).z = - (* ((LPD3DXVECTOR3)(data + VertexOffset))).z;D3DXVECTOR3 vertex = (* ((LPD3DXVECTOR3)(data + VertexOffset)));if (vertex.x < object->minBounds.x) object->minBounds.x=vertex.x;if (vertex.x > object->maxBounds.x) object->maxBounds.x=vertex.x;if (vertex.y < object->minBounds.y) object->minBounds.y=vertex.y;if (vertex.y > object->maxBounds.y) object->maxBounds.y=vertex.y;if (vertex.z < object->minBounds.z) object->minBounds.z=vertex.z;if (vertex.z > object->maxBounds.z) object->maxBounds.z=vertex.z;//vertices = * ((LPD3DXVECTOR3)(data + VertexOffset));}/*vertexTextureCoordinates.U = (*((LPD3DXVECTOR2)(data + TextureOffset))).x;vertexTextureCoordinates.V = (*((LPD3DXVECTOR2)(data + TextureOffset))).y;if(NormalExists){vertexNormals = * ((LPD3DXVECTOR3)(data + NormalOffset));}*/data += object->g_pMesh->GetNumBytesPerVertex();}/*unlock the buffer*/object->g_pMesh->UnlockVertexBuffer();for now all i am doing is just reversing the z value to transform the models to Right CS, and calculating the bbox per model. I commented the rest because it is not needed now.   
  There's one thing obviously wrong with your code: you're locking with D3DLOCK_READONLY and then changing the data. I have no idea if this is the source of the particular problem, but it's definitely wrong.   ;Quote:Original post by ZeRaWThe following code should run correctly.Sometimes, On release, the game crashes and when I try to click the debug button, it will take me to this part:*** Source Snippet Removed ***saying something about trying to access an invalid memory!all i do then is just rebuild the solution and re-try and it works.On Debug mode, it works perfectly, I reviewd the code many times and cannot figure out what is mising, maybe someone can help me, this is the full code:*** Source Snippet Removed ***for now all i am doing is just reversing the z value to transform the models to Right CS, and calculating the bbox per model. I commented the rest because it is not needed now.First of all, can't you replace that statement with:(* ((LPD3DXVECTOR3)(data + VertexOffset))).z *= -1;Nextly for the purposes of debugging, try breaking this up into a series of smaller statements and see if the debugger raises an error one of these (this gives even more specific info about where the problem is). You could begin by declaring a vector pointer and setting it equal to the data pointer. Nextly increment the vector pointer by the offset and so on....;  Thanks for both inputs.I do not know how i missed the read only flag. this seems the problem.should i replace it by D3DLOCK_NOSYSLOCK?   ;  I think you should only use D3DLOCK_NOSYSLOCK if you know the locking could be long.   