Sigh, Access Violation... Rendering a mesh...

Started by
3 comments, last by oxygen_728 20 years ago
My goodness, this is just never ending tonight. 2 hours spent on one problem immediately followed by 90 minutes on this problem now. This very same code, exactly the same code, runs just fine in another directory on my system. There may be some solution settings that differ (though I have checked all I can to make sure they are the same). I created a new solution, and imported my .cpp files and .h file and started fresh. (I was originally editing a SDK tutorial.) I Think I have everything setup correctly... However, In the following code... I get an Access Violation at the indicated line: I don't expect anybody to go through my code... but I'm at a total loss by now... It's 3:30 AM and im about to pass out and I've been staring at this junk for almost 5 hours. I somply wanted to move my Solution from one directory to another... and 5 hours later... it still doesn't work. And it works in my old directory! Please if you have any ideas... I'll be checking replies when I wake up. Thank you! VOID CBall::Render(LPDIRECT3DDEVICE9 pd3dDevice) { SetupMatrices(pd3dDevice); for( DWORD i = 0; i < dwNumMaterials; i++ ) { // Set the material and texture for this subset pd3dDevice->SetMaterial( &pMaterials ); pd3dDevice->SetTexture( 0, pTextures ); <— THIS LINE // Draw the mesh subset pMesh->DrawSubset( i ); } } </i> it gets an error when trying to access pTextures, I think… I tried "stepping into" this line and it just went to the next line and gave an error. What happens when I change pTextures to 0? (SetTexture( 0, 0) ) No error on that line, but pMesh->DrawSubset Doesn't work. It Also manages to get an access violation. What do I know? 1. The mesh was successfully loaded 2. The material buffer was properly filled 3. There are no textures for this mesh I'd settle for SetTexture( 0,0 ) … but I didn't have to do this in my other project… and besides DrawSubset doesn't work on the mesh! Here is where pTextures is declared… (in CInterface.h) LPDIRECT3DTEXTURE9* pTextures; and defined CurMeshTextures = new LPDIRECT3DTEXTURE9[NumOfMaterials]; CurMeshTextures is declared as LPDIRECT3DTEXTURE9* &CurMeshTextures and is the parameter that pTextures is passed to… here is the whole function: ///////////////////////////////////////////////////////////// HRESULT CMesh::CreateMesh(LPDIRECT3DDEVICE9 pd3dDevice, LPCSTR path, LPD3DXMESH& CurrentMesh, LPDIRECT3DTEXTURE9* &CurMeshTextures, D3DMATERIAL9* &CurMeshMaterials, DWORD& NumOfMaterials ) { LPD3DXBUFFER pMaterialBuffer; HRESULT res, res2; res = D3DXLoadMeshFromX( path , D3DXMESH_SYSTEMMEM, pd3dDevice, NULL, &pMaterialBuffer, NULL, &NumOfMaterials, &CurrentMesh ); if( FAILED( res ) ) { MessageBox(NULL, " Unable to load Mesh ", "Meshes.exe", MB_OK); return E_FAIL; } // get pointer to the buffer… D3DXMATERIAL* TheMaterials = (D3DXMATERIAL*)pMaterialBuffer->GetBufferPointer(); CurMeshMaterials = new D3DMATERIAL9[NumOfMaterials]; CurMeshTextures = new LPDIRECT3DTEXTURE9[NumOfMaterials]; for( DWORD i=0; i<NumOfMaterials; i++ ) { // Copy the material CurMeshMaterials = TheMaterials.MatD3D; // Set the ambient color for the material (D3DX does not do this) CurMeshMaterials.Ambient = CurMeshMaterials.Diffuse; if( TheMaterials.pTextureFilename != NULL && lstrlen(TheMaterials.pTextureFilename) > 0 ) { // Create the texture if( FAILED( D3DXCreateTextureFromFile( pd3dDevice, TheMaterials.pTextureFilename, &CurMeshTextures ) ) ) { MessageBox(NULL, "Couldn't find material","Couldn't find material",MB_OK); } } else { CurMeshTextures = NULL; } } pMaterialBuffer->Release(); return S_OK; } //////////////////////////////////////////////////// </i> <SPAN CLASS=editedby>[edited by - oxygen_728 on March 27, 2004 4:35:11 AM]</SPAN> <SPAN CLASS=editedby>[edited by - oxygen_728 on March 27, 2004 4:37:06 AM]</SPAN>
Advertisement
Oh my goodness that code did not paste well...

My Visual Studio 2003 Project is posted:

www.oxygen728.com/brian.zip

Thank you very much for your help if you can spare it!
I''m pretty new here, how do I make those nice scrolly boxes to paste code in? =)

Gotta sleep now, I''ll check posts asap in the morning
To paste your code in those nice source code blocks, you need to put your code in between source code tags. They look like this: [ source ] and [ / source ]. Just take out the extra space inside the brackets and it will work.

As far as your code goes, I haven't taken a look inside it but what kind of values does the pTextures array have? If you say that there are no textures with this mesh, then all slots in this array should have NULL.

One way you could get an access violation would be that the slots in your texture array have some kind of garbage address where there really is no texture loaded.

Check those values and make sure they're valid.

neneboricua

[edited by - neneboricua19 on March 27, 2004 4:04:34 PM]
Hi mate, about the access violation, make sure that the last parameter of ur D3DFVFCreateMesh function has an ampersand (&) in front of it and also make sure that ur not allocatig less vertex and triangle memory than u are attempting to fill.

This topic is closed to new replies.

Advertisement