Skip to main content
GameDev.net gamedev.net
🔒 Locked

Why does this fail?

Started by ScuzzMeister Apr 9, 2002 at 7:26 PM 9 replies 650+ views
Original Post
ScuzzMeister
ScuzzMeister

  
HRESULT GetCBox()
{
	if( FAILED( g_pCar->GetVertexBuffer( &g_pCVertexBuffer ) ) )
	{
		MessageBox( NULL, "g_pCar->GetVertexBuffer: Function Call Failed", NULL, NULL );
		return E_FAIL;
	}
	//g_pCar->GetIndexBuffer( &g_pCIndexBuffer );


	if( g_pCar->GetNumVertices() )
		g_dwCNumVertices+=sizeof(float);

	if( g_pCar->GetFVF() )
		g_dwCFVF+=sizeof(float);	
	
	if( FAILED( D3DXComputeBoundingBox( (PVOID)g_pCVertexBuffer, g_dwCNumVertices, g_dwCFVF, &D3DXVECTOR3( g_CXMin, g_CYMin, g_CZMin ), &D3DXVECTOR3( g_CXMax, g_CYMax, g_CZMax ) ) ) )
	{
		MessageBox( NULL, "D3DXComputeBoundingBox: Function Call Failed", NULL, NULL );
		return E_FAIL;
	}

	return S_OK;
}

HRESULT GetCBoxIntersects()
{
	
	if( FAILED( D3DXIntersect( g_pTrack, &D3DXVECTOR3( g_CXMax/2+g_CarXPos, g_CYMax/2+g_CarYPos, g_CZMin+g_CarZPos ), &D3DXVECTOR3( 0, 0, -1 ), NULL, NULL, NULL, NULL, &g_pGDist, NULL, NULL ) ) )
	{
		MessageBox( NULL, "D3DXIntersect(Ground Distance): Function Call Failed", NULL, NULL );
		return E_FAIL;
	}

	return S_OK;
}
  
Ok, for some reason the D3DXIntersect function call is failing. What could be causing this and how can I fix it? Thanks for your help.
ScuzzMeister
ScuzzMeister
The funny thing is though, was that everything was working fine and I didn''t change a thing. Then one day I go back and execute it without changing a thing and get the error. Why would it work for a while and than stop working all of a sudden? Well, anyway, what should I do exactly? Try to change the g_pTrack vertex buffer so it is readable?
ScuzzMeister
ScuzzMeister
Ok, here is what I've tried to make the vertex buffer readable:

      
if( FAILED( g_pTrack->GetVertexBuffer( &g_pTVertexBuffer ) ) )
{
MessageBox( NULL, "g_pTrack->GetVertexBuffer: Function Call Failed", NULL, NULL );
return E_FAIL;
}

if( FAILED( g_pTVertexBuffer->Lock( 0, 0, NULL, D3DLOCK_READONLY ) ) )
{
MessageBox( NULL, "g_pTVertexBuffer->Lock: Function Call Failed", NULL, NULL );
return E_FAIL;
}

if( FAILED( g_pTVertexBuffer->Unlock() ) )
{
MessageBox( NULL, "g_pTVertexBuffer->Unlock: Function Call Failed", NULL, NULL );
return E_FAIL;
}


But when I lock it, the program crashes. Here's my .x file loading function.


  
HRESULT InitMesh( char *filename, LPD3DXMESH &pMesh, DWORD &dwNumMaterials, D3DMATERIAL8* &pMeshMaterials, LPDIRECT3DTEXTURE8* &pMeshTextures )
{
LPD3DXBUFFER pD3DXMtrlBuffer;

// Load the mesh from the specified file

if( FAILED( D3DXLoadMeshFromX( filename, D3DXMESH_SYSTEMMEM,
g_pd3dDevice, NULL,
&pD3DXMtrlBuffer, &dwNumMaterials,
&pMesh ) ) )
{
if( filename=="track.x" )
MessageBox( NULL, "Unable to load track mesh", NULL, NULL );
if( filename=="car(blue).x" )
MessageBox( NULL, "Unable to load car mesh", NULL, NULL );
return E_FAIL;
}

// We need to extract the material properties and texture names from the

// pD3DXMtrlBuffer

D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
pMeshMaterials = new D3DMATERIAL8[dwNumMaterials];
pMeshTextures = new LPDIRECT3DTEXTURE8[dwNumMaterials];

for( DWORD i=0; i<dwNumMaterials; i++ )
{
// Copy the material

pMeshMaterials[i] = d3dxMaterials[i].MatD3D;

// Set the ambient color for the material (D3DX does not do this)

pMeshMaterials[i].Ambient = pMeshMaterials[i].Diffuse;

// Create the texture

if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice,
d3dxMaterials[i].pTextureFilename,
&pMeshTextures[i] ) ) )
{
pMeshTextures[i] = NULL;
}
}

// Done with the material buffer

pD3DXMtrlBuffer->Release();

return S_OK;
}


A solution or hint to where I'm going wrong would be most appreciated. Thank you.

[edited by - ScuzzMeister on April 10, 2002 3:14:38 PM]

[edited by - ScuzzMeister on April 10, 2002 3:16:00 PM]
DanMan
DanMan
Have you cranked up your debug output all the way and watched for DX error messages? That''s the first thing I do whenever I get a crash or unexpected value...

If you''ve tried that, what are the last few messages that get written to the debug output?
ScuzzMeister
ScuzzMeister
Here's the message I get:

Unhandled exception in racinggame.exe (D3D8.DLL): 0xC0000005: Access Violation.

[edited by - ScuzzMeister on April 10, 2002 6:08:33 PM]
Tessellator
Tessellator
If that is the error you are getting, then it looks like you are using the retail version of the d3d8 drivers (the d3d8.dll rather than d3d8d.dll gives it away.. . Run the DX8 install, and choose to install the debug version of the dlls. (If you have 8.1, I think there will be an option in the start menu to change them for you without having to run the installer..)

After this, go into the control panel and have a look at your directx setup. In the direct3d tab, ramp the debug setting upto More (maximum), and rebuild your app. You should get a decent error message, that will hopefully point you to the problem.

Hope that helps,
T
ScuzzMeister
ScuzzMeister
Alright, I've done everything you've said Tessellator, and have fixed the problem with locking the vertex buffer but I still have the problem with the D3DXIntersect function. I get the message box popping up, but no detailed debug info on why it is failing.

Although there is this:

Direct3D8: (ERROR) :Memory still allocated! Alloc count = 84
Direct3D8: (ERROR) :Current Process (pid) = 000005c8
....
Direct3D8: (ERROR) :Total Memory Unfreed From Current Process = 2333215 bytes

I read in the docs that if D3DXIntersect fails, it might return E_OUTOFMEMORY. Could it be I'm running out of memory? Here is my clean up function that runs after the program quits:

  
VOID Cleanup()
{
if( g_lpDIDevice != NULL ){
g_lpDIDevice->Unacquire();
g_lpDIDevice->Release();
}

if( g_lpDI != NULL )
g_lpDI->Release();

if( g_pCVertexBuffer != NULL )
g_pCVertexBuffer->Release();

if( g_pCarMaterials != NULL )
delete[] g_pCarMaterials;

if( g_pCarTextures )
{
for( DWORD a = 0; a < g_dwCNumMaterials; a++ )
{
if( g_pCarTextures[a] )
g_pCarTextures[a]->Release();
}
delete[] g_pCarTextures;
}
if( g_pCar != NULL )
g_pCar->Release();

if( g_pTrackMaterials != NULL )
delete[] g_pTrackMaterials;

if( g_pTrackTextures )
{
for( DWORD b = 0; b < g_dwTNumMaterials; b++ )
{
if( g_pTrackTextures[b] )
g_pTrackTextures[b]->Release();
}
delete[] g_pTrackTextures;
}
if( g_pTrack != NULL )
g_pTrack->Release();

if( g_pd3dDevice != NULL )
g_pd3dDevice->Release();

if( g_pD3D != NULL )
g_pD3D->Release();
}




[edited by - ScuzzMeister on April 10, 2002 7:16:28 PM]
ScuzzMeister
ScuzzMeister
Anyone have any ideas why this is failing?
S1CA
S1CA
Link with d3dx8d.lib or d3dx8dt.lib instead of d3dx8.lib - otherwise D3DX won''t report any error messages to the debug window.

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
ScuzzMeister
ScuzzMeister
I linked with both d3dx8d.lib and d3dx8dt.lib and found no difference in debug output.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.