🔒 Locked
Ray Intersection Error - HELP
Advertisement
Original Post
I get this error when I try to preform an Intersect test on a mesh.
Unhandled exception at 0x10001c1a (BIEngine.dll) in Halo TCW.exe: 0xC0000005: Access violation reading location 0xbaadf00d.
This is the call I use to text my mesh for a ray intersection. This Ray is produced by the absolute mouse coords.
BOOL Hit;
D3DXIntersect(Quad,&normRay->Origin,&normRay->Direction, &Hit,0,0,0,0,0,0);
This is the function I use to create a blank mesh that I can prefrom a Intersect test on.
BIQuad::BIQuad(double Size, double Z, char* QN, char* QT)
{
Quad=NULL;
Tex=NULL;
QuadName=QN;
TexPath=QT;
Vertex* v;
D3DXCreateMeshFVF(2,4,D3DXMESH_DYNAMIC,BIFVF,lpDevice,&Quad);
Quad->LockVertexBuffer(D3DLOCK_DISCARD, (void**)&v);
v[0] = Vertex(-Size, -Size, Z, D3DCOLOR_XRGB(255,255,255), 0.0f, 1.0f);
v[1] = Vertex( -Size, Size, Z, D3DCOLOR_XRGB(255,255,255), 0.0f, 0.0f);
v[2] = Vertex( Size, Size, Z, D3DCOLOR_XRGB(255,255,255), 1.0f, 0.0f);
v[3] = Vertex( Size, -Size, Z, D3DCOLOR_XRGB(255,255,255), 1.0f, 1.0f);
Quad->UnlockVertexBuffer();
LPVOID ppID;
WORD * pIDArray = new WORD[Quad->GetNumFaces()*2];
for(int i = 0; i != (Quad->GetNumFaces()*2); i++)
{
pIDArray = i;
}
Quad->LockIndexBuffer(D3DLOCK_DISCARD, &ppID);
memcpy(ppID, pIDArray, (Quad->GetNumFaces()*2));
Quad->UnlockIndexBuffer();
SetTexture(QT);
RotateQuad(0);
}
This is rather baffling too me since I have tried alot of different states (eg. "D3DXMESH_DYNAMIC", etc) most seem to fail (ie. wont create the mesh), Any thoughts or help would be greatly apreciated since this is my final project for my game class.
What is this meant to do?
As I understand it, ppID is just a void pointer, so memcpy has nothing to copy into.
It''s been a while between memory managing stints for me, so I could be wrong.
Steele.
quote:
LPVOID ppID;
WORD * pIDArray = new WORD[Quad->GetNumFaces()*2];
for(int i = 0; i != (Quad->GetNumFaces()*2); i++)
{
pIDArray = i;
}
Quad->LockIndexBuffer(D3DLOCK_DISCARD, &ppID);
memcpy(ppID, pIDArray, (Quad->GetNumFaces()*2));
Quad->UnlockIndexBuffer();
As I understand it, ppID is just a void pointer, so memcpy has nothing to copy into.
It''s been a while between memory managing stints for me, so I could be wrong.
Steele.
An access violation usually means that the system is trying to follow an invalid (or NULL) pointer. I think the reason it's not working is because your call to D3DXIntersect doesn't supply all the necessary parameters.
You MUST supply variables for the index of the face hit, the u and v parameters, and the distance to the point of intersection. I think that you can safely pass the last two parameters as NULL but the others need to be there. The access violation is probably because the function D3DXIntersect is trying to assign values to variables that do not exist.
Also, as the above poster has noted, you need to change the data type of ppID from LPVOID to WORD* and then cast ppID to be a void pointer when you lock the index buffer.
neneboricua
[edited by - neneboricua19 on January 29, 2004 9:05:00 PM]
You MUST supply variables for the index of the face hit, the u and v parameters, and the distance to the point of intersection. I think that you can safely pass the last two parameters as NULL but the others need to be there. The access violation is probably because the function D3DXIntersect is trying to assign values to variables that do not exist.
Also, as the above poster has noted, you need to change the data type of ppID from LPVOID to WORD* and then cast ppID to be a void pointer when you lock the index buffer.
neneboricua
[edited by - neneboricua19 on January 29, 2004 9:05:00 PM]
Well thats the exact memory location that I get when I try to lock my buffer for reading elsewhere. I still get the same error with the variables that you suggested BTW.
[edited by - IDirect3D9 on January 31, 2004 2:44:23 PM]
[edited by - IDirect3D9 on January 31, 2004 2:44:23 PM]
OK. I think I see why now. When you create the mesh, you specify that there are 2 faces and 4 vertices. This would be fine if you were using a triangle strip or a triangle fan, but meshes expect all data to be in the form of triangl lists.
You need to make your index buffer 6 elements long and reference the right vertices to make your quad. The elements of your index buffer should be like this:
0,1,2,0,2,3
Hope this helps,
neneboricua
You need to make your index buffer 6 elements long and reference the right vertices to make your quad. The elements of your index buffer should be like this:
0,1,2,0,2,3
Hope this helps,
neneboricua
Nope same exact error, im pretty sure that this is occuring when D3DXInteresct tries to lock the VB for reading. Its like im setting the wrong D3DXMESH state.
[edited by - IDirect3D9 on January 31, 2004 5:10:11 PM]
[edited by - IDirect3D9 on January 31, 2004 5:10:11 PM]
As you can see, it tried to use "0xbaadf00d" as a pointer. This usually means you''re using an uninitialized memory location, as that''s one of the "magic cookies" that memory allocators put in un-initialized memory, or between memory blocks.
I suggest looking at the assembly around the crash and figuring out where the data was coming from. Then make sure that it gets the right data.
I suggest looking at the assembly around the crash and figuring out where the data was coming from. Then make sure that it gets the right data.
It seems fairly obvious hat its not getting the data, but why is completely baffling me. I have the state properly set. The Data has been properly set. It renders perfectly, i just cant do a pick test.
[edited by - IDirect3D9 on January 31, 2004 6:07:46 PM]
[edited by - IDirect3D9 on January 31, 2004 6:07:46 PM]
Hmmm.. At this point, I''m going to just take a stab in the dark.
Maybe try using OptimizeInPlace on the mesh. Could be that D3DXIntersect needs other parts of the internal state of the mesh than just the vertex and index buffers? The docs say that OptimizeInPlace creates an attribute buffer. Maybe it also sets other things internally in the mesh that D3DXIntersect needs but that aren''t necessarily needed for rendering?
Also, try calling D3DXValidMesh on the mesh you''ve created just to make sure that it''s playing nice with the D3D runtime.
neneboricua
Maybe try using OptimizeInPlace on the mesh. Could be that D3DXIntersect needs other parts of the internal state of the mesh than just the vertex and index buffers? The docs say that OptimizeInPlace creates an attribute buffer. Maybe it also sets other things internally in the mesh that D3DXIntersect needs but that aren''t necessarily needed for rendering?
Also, try calling D3DXValidMesh on the mesh you''ve created just to make sure that it''s playing nice with the D3D runtime.
neneboricua
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement