Sign in to follow this  
Citizen Erased

.x file problems

Recommended Posts

Citizen Erased    122
Hi, I've been trying to set up a system that loads an .x file so that the code for loading the .x file is located in the constructor for a class (so that it is created along with an instance of the class). However whenever I try to run the program I get the error catching message that the file has failed to load (or at least that the function for loading the file has failed). Here's the code for the constructor: ship::ship(IDirect3DDevice9* Device, ID3DXMesh* player, std::vector<D3DMATERIAL9>* Mtrls, std::vector<IDirect3DTexture9*>* Textures) { ID3DXBuffer* adjBuffer = 0; ID3DXBuffer* mtrlBuffer = 0; DWORD numMtrls = 0; HRESULT hr; hr = D3DXLoadMeshFromX( "p1ship.x", D3DXMESH_MANAGED, Device, &adjBuffer, &mtrlBuffer, 0, &numMtrls, &player); if(FAILED(hr)) { ::MessageBox(0, "D3DXLoadMeshFromX() - FAILED ", 0, 0); } and here's the call for the instance of ship and the declaration of the things it uses: IDirect3DDevice9* Device = 0; ... std::vector<D3DMATERIAL9> Mtrls(0); std::vector<IDirect3DTexture9*> Textures(0); ... ID3DXMesh* player = 0; ... ship theShip(Device, player, &Mtrls, &Textures); Anyone have any idea what might be causing the failure to load? It's probably something glaringly obvious but the program compiles and builds fine so I don't have any clues to go on. [Edited by - Citizen Erased on March 15, 2006 6:13:10 AM]

Share this post


Link to post
Share on other sites
Calin    419
I assume you pass an initializied Device to your function.

Also you can use 'hr' to get aditional information about the error.

Quote:

from MSDN:

If the function fails, the return value can be one of the following values.


D3DERR_INVALIDCALL The method call is invalid. For example, a method's parameter may have an invalid value.
E_OUTOFMEMORY Microsoft Direct3D could not allocate sufficient memory to complete the call.

Share this post


Link to post
Share on other sites
Citizen Erased    122
Quote:
Original post by Calin
I assume you pass an initializied Device to your function.

Also you can use 'hr' to get aditional information about the error.

Quote:

from MSDN:

If the function fails, the return value can be one of the following values.


D3DERR_INVALIDCALL The method call is invalid. For example, a method's parameter may have an invalid value.
E_OUTOFMEMORY Microsoft Direct3D could not allocate sufficient memory to complete the call.


The device is initialised. That HR info is handy but I can't get it to return anything as it's in a constructor. I may take the code out of the constructor though and see what it returns. Thanks for that

Quote:
Original post by DXnut
Can you make the p1ship.x file available for us to check out?


At the moment it is just a renamed copt of bigship1.x which comes with the SDK as a placeholder while my mate finishes off the player model.

Share this post


Link to post
Share on other sites
Citizen Erased    122
Interesting update: I took all the code out of the constructor and placed it into the setup portion of the main CPP and it now works. What could be causing this to fail when it's put in the constructor?

[Edited by - Citizen Erased on March 15, 2006 1:59:14 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this