Thread: .X File format and DirectX. Crashing, but why? Damn this world!

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    73

    .X File format and DirectX. Crashing, but why? Damn this world!



    My program is crashing, but I really cannot pinpoint the problem. Tried commenting stuff out... debugging, etc...

    By the way I was following the example that shipped with DirectX9 SDK on loading meshes.

    I've pinpointed the problem to this section of code:
    Code:
    g_pD3DDevice9->BeginScene();
    	
    D3DXMATRIXA16 xmatWorld, xmatTemp1, xmatTemp2;
    
    D3DXMatrixTranslation(&xmatWorld, 0.0f,	-2.0f, 10.0f);
    
    D3DXMatrixRotationY(&xmatTemp1, g_fRotAngleY);
    
    D3DXMatrixRotationX(&xmatTemp2, g_fRotAngleX);
    
    xmatWorld = xmatTemp1 * xmatTemp2 * xmatWorld;
    
    g_pD3DDevice9->SetTransform(D3DTS_WORLD, &xmatWorld);	
    														for(DWORD i = 0; i < g_dwNumMaterials; i++)
    {
      g_pD3DDevice9->SetMaterial(&g_pMeshMaterials[i]);
      g_pMesh->DrawSubset(i);
    }
    
    g_pD3DDevice9->EndScene();
    
    g_pD3DDevice9->Present(NULL, NULL, NULL,  NULL);
    Code:
    bool LoadObjects()
    {
      LPD3DXBUFFER pD3DXMtrlBuffer;
    	
      D3DXLoadMeshFromX("box.x", D3DXMESH_SYSTEMMEM, g_pD3DDevice9, NULL, &pD3DXMtrlBuffer,	NULL, &g_dwNumMaterials, &g_pMesh);
    	
      D3DXMATERIAL *meshData = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
    
      g_pMeshMaterials = new D3DMATERIAL9[g_dwNumMaterials];
    
      for (DWORD i = 0; i < g_dwNumMaterials; i++)
      {
        g_pMeshMaterials[i] = meshData[i].MatD3D;
        g_pMeshMaterials[i].Ambient = g_pMeshMaterials[i].Diffuse;
     }
    
     pD3DXMtrlBuffer->Release();
    
     return true;
    }
    Code:
    g_pMesh->DrawSubset(i);
    The above line seems to be my problem. On the first pass through I get the following message but the program continues.
    Code:
    First-chance exception in Test.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
    Second time through I get
    Code:
    First-chance exception in Test.exe: 0xC0000005: Access Violation.
    and my program crashes. Anyone know what this means?

    3DStudioMax7 using Plugin shipped with DirectX9 SDK
    Microsoft Visual C++ 6.0

    I'm befuddled as when I use the file shipped with the tutorial the program works perfectly fine. (tiger.x)

    My box.x is just a simple cube, no materials.

    Any ideas? I'm quite peeved at this troublesome problem
    Last edited by Deo; 06-03-2005 at 01:49 PM.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Post up the x file you're using and I'll have a look at it later tonight.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    73
    Box.x file is attached. (Renamed to .h just for upload purposes)

    It is significantly different from the .x that shipped with DirectX9.0 SDK. I've thought about trying to alter box.x to look more like tiger.x but don't know where to begin.

    So much unnecessary info in box.x such as animation, but nothing I can do about it.. just the way the exporter (3d studio max plugin) is doing things...

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Interesting problem. It does seem to be an error with that particular mesh. Either the exporter is handling a case incorrectly or you are upon creation. Maybe there are some settings you need to modify in the plugin. I think there are texcoords but no texture? Odd. Anyway turn your DirectX to debug libraries and debug output all the way up and you'll get this information:

    Quote Originally Posted by Debug Output
    Direct3D9: Decl Validator: X284: (Element Error) (Decl Element [4]) Declaration can't map to fixed function FVF because a usage+index pair (D3DDECLUSAGE_TANGENT,0) that is not valid for fixed function appears between two vertex elements that have usage+index pairs valid for fixed function. For a vertex declaration to map to fixed function, all individual elements that are valid for fixed function must appear contiguously starting from the first element. Remaining elements at the end do not have to be valid for fixed function, as long as there are few enough that they can be aliased internally to texcoord(n), texcoord(n+1) etc. up to max. texcoord7 (thereby appearing to conform to an FVF, although the aliased values should not be used).

    First-chance exception at 0x7c81eb33 in WinMain.exe: Microsoft C++ exception: long @ 0x0012f6d4.
    Direct3D9: (ERROR) :DrawIndexedPrimitive failed.

    Unhandled exception at 0x7c901230 in WinMain.exe: User breakpoint.
    So that would indicate a vertex declaration problem. I haven't used this plugin before but you should double check all the settings and make sure you are only exporting streams that you need.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  5. #5
    Registered User
    Join Date
    May 2005
    Posts
    73
    Plugin doesn't seem to have any settings.. atleast not from what I see... wish I could change streams as I don't want that animation crap and stuff...

    Code:
    Anyway turn your DirectX to debug libraries
    Thnx. Much better

    Code:
    I think there are texcoords but no texture?
    Well. Got some progress. Decided to investigate and it seems when an object is created MAPPING COORDINATES are automatically created.. when I disabled I was able to get a plain cube mesh to work. However, anything else, simple diffuse material or texture even when I set the UVW mapping myself results in the same crash.. DAMN DAMN DAMN DAMN DAMN.. microsoft documentation is garbage.

    So if I want a plane sphere/cube mesh I'm golden.. anything else and BOOM. What a cool game I'm gonna make

    Thnx for the help though.. guess I'll just have to get lucky and hopefully find some faq on the NET with 3DStudio Max 7 and this plugin..

  6. #6
    Registered User
    Join Date
    May 2005
    Posts
    73
    Hmm.. nevermind I think I fixed my problem.. The .X exporter that ships with DirectX 9.0 SDK sucks ass.. bombs like crazy even though the MSDN documentation clearly states it works with 3D Studio Max R7. Follow their instructions step by step and where does it get u? Confused and ........ed!

    Found a exporter that works just fine PandaX or something like that.

    http://www.andytather.co.uk/Panda/di...downloads.aspx


    Hours of anger just to find out Microsofts exporter was ........ED!
    MICROSOFT STRIKES AGAIN!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is there a .dds file format converter availible for Mac OS X
    By joeprogrammer in forum Game Programming
    Replies: 2
    Last Post: 04-29-2006, 05:00 PM