dbLoadObject fails to load a .x file. Originally, I was attempting to load the scout model included with DarkGDK samples ([DarkGDK]/Samples/bin/Media/media/scout) which I had copied into my project's binary environment path ([myproject]/Debug/assets/models/scout). The compiled sample that uses this model file appears to load it without error. However, in my project, the model does not load. Futhermore, a call to dbObjectExist with that model's id causes a buffer overrun exception (crash).
Here's my code:
#include "DarkGDK.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
dbSyncOn();
dbSyncRate(60);
char msg[256] = "";
int planetId = 1;
int shipId = 2;
int skyId = 3;
int shipMapId= 1;
SetCurrentDirectory("assets\\models\\");
dbSetCameraRange (100.0f, 6000.0f);
// Setup Planet
dbLoadObject ("planet\\Planet.X", planetId);
dbSetObjectLight (planetId, 0);
dbSetObjectTexture (planetId, 3, 2);
dbPositionObject (planetId, 0.0f, 0.0f, 0.0f);
// Setup Ship
// dbLoadObject ("ship\\Ship.X", shipId);
// dbLoadObject ("cube.x", shipId);
dbLoadObject ("scout\\scout2.x", shipId);
dbSetObjectLight (shipId, 0);
dbSetObjectTexture (shipId, 3, 2);
dbPositionObject (shipId, 0.0f, 0.0f, -600.0f);
// Setup SkySphere (space)
dbLoadObject ("space\\ss.x", skyId);
dbSetObjectLight (skyId, 0);
dbSetObjectTexture (skyId, 3, 2);
dbPositionObject (skyId, 0.0f, 0.0f, 0.0f);
// Position Camera
dbPositionCamera (0.0f, 0.0f, -720.0f);
dbRotateCamera (0.0f, 0.0f, 0.0f);
// now we come to our main loop, we call LoopGDK so some internal
// work can be carried out by the GDK
while ( LoopGDK ( ) )
{
sprintf(msg, "Planet: %d | Ship: %d | Sky: %d",
dbObjectExist(planetId),
dbObjectExist(shipId),
dbObjectExist(skyId));
dbText(0, dbScreenHeight() - 20, msg);
// move the camera forwards
if (dbUpKey()) { dbMoveCamera(10); }
// move the camera backwards
if (dbDownKey()){ dbMoveCamera(-10); }
// here we make a call to update the contents of the screen
dbSync();
}
sprintf(msg, "");
// before quitting delete our objects
if (dbObjectExist(planetId)){ dbDeleteObject(planetId); }
if (dbObjectExist(shipId)) { dbDeleteObject(shipId); }
if (dbObjectExist(skyId)) { dbDeleteObject(skyId); }
// and now everything is ready to return back to Windows
return;
}
* The buffer overrun exception does not occur until after exiting the main loop (it occurs in the delete objects section).
* The text output to the screen states: "Planet: 1 | Ship: 0 | Sky: 1"
* The planet and sky models load without error. They were taken from [DarkGDK]/Media/Modes/Planet and [DarkGDK]/Samples/bin/media/sky respectively.
* The two commented lines below // Setup Ship:
// dbLoadObject ("ship\\Ship.X", shipId);
// dbLoadObject ("cube.x", shipId);
were attempts at loading other models. The "ship\\Ship.X" model (from [DarkGDK]/Media/Models/Ship) loads without error.
The "cube.x" file is a model I created from the default cube object that loads with every new Blender project. I simply added a UV Texture and exported it as DirectX file (.x). This model does not load and cause the same buffer overrun exception as mentioned above. I also tried using the DirectX utility: MeshConvert to convert it to binary. This did not work either. Here is the contents of cube.x in text form:
xof 0303txt 0032
template VertexDuplicationIndices {
<b8d65549-d7c9-4995-89cf-53a9a8b031e3>
DWORD nIndices;
DWORD nOriginalVertices;
array DWORD indices[nIndices];
}
template XSkinMeshHeader {
<3cf169ce-ff7c-44ab-93c0-f78f62d172e2>
WORD nMaxSkinWeightsPerVertex;
WORD nMaxSkinWeightsPerFace;
WORD nBones;
}
template SkinWeights {
<6f0d123b-bad2-4167-a0d0-80224f25fabb>
STRING transformNodeName;
DWORD nWeights;
array DWORD vertexIndices[nWeights];
array float weights[nWeights];
Matrix4x4 matrixOffset;
}
Frame RootFrame {
FrameTransformMatrix {
1.000000,0.000000,0.000000,0.000000,
0.000000,1.000000,0.000000,0.000000,
0.000000,0.000000,1.000000,0.000000,
0.000000,0.000000,0.000000,1.000000;;
}
Frame Cube {
FrameTransformMatrix {
1.000000,0.000000,0.000000,0.000000,
0.000000,1.000000,0.000000,0.000000,
0.000000,0.000000,1.000000,0.000000,
0.000000,0.000000,0.000000,1.000000;;
}
Mesh {
24;
1.000000; 1.000000; -1.000000;,
1.000000; -1.000000; -1.000000;,
-1.000000; -1.000000; -1.000000;,
-1.000000; 1.000000; -1.000000;,
1.000000; 1.000000; 1.000000;,
-1.000000; 1.000000; 1.000000;,
-1.000000; -1.000000; 1.000000;,
1.000000; -1.000000; 1.000000;,
1.000000; 1.000000; -1.000000;,
1.000000; 1.000000; 1.000000;,
1.000000; -1.000000; 1.000000;,
1.000000; -1.000000; -1.000000;,
1.000000; -1.000000; -1.000000;,
1.000000; -1.000000; 1.000000;,
-1.000000; -1.000000; 1.000000;,
-1.000000; -1.000000; -1.000000;,
-1.000000; -1.000000; -1.000000;,
-1.000000; -1.000000; 1.000000;,
-1.000000; 1.000000; 1.000000;,
-1.000000; 1.000000; -1.000000;,
1.000000; 1.000000; 1.000000;,
1.000000; 1.000000; -1.000000;,
-1.000000; 1.000000; -1.000000;,
-1.000000; 1.000000; 1.000000;;
6;
4; 0, 1, 2, 3;,
4; 4, 5, 6, 7;,
4; 8, 9, 10, 11;,
4; 12, 13, 14, 15;,
4; 16, 17, 18, 19;,
4; 20, 21, 22, 23;;
MeshMaterialList {
2;
6;
1,
1,
1,
1,
1,
1;;
Material mat_cube {
0.800000; 0.800000; 0.800000;1.0;;
0.500000;
1.000000; 1.000000; 1.000000;;
0.0; 0.0; 0.0;;
} //End of Material
Material Mat1 {
1.0; 1.0; 1.0; 1.0;;
1.0;
1.0; 1.0; 1.0;;
0.0; 0.0; 0.0;;
TextureFilename { "tex_cube.tga"; }
} // End of Material
} //End of MeshMaterialList
MeshNormals {
24;
0.577349; 0.577349; -0.577349;,
0.577349; -0.577349; -0.577349;,
-0.577349; -0.577349; -0.577349;,
-0.577349; 0.577349; -0.577349;,
0.577349; 0.577349; 0.577349;,
-0.577349; 0.577349; 0.577349;,
-0.577349; -0.577349; 0.577349;,
0.577349; -0.577349; 0.577349;,
0.577349; 0.577349; -0.577349;,
0.577349; 0.577349; 0.577349;,
0.577349; -0.577349; 0.577349;,
0.577349; -0.577349; -0.577349;,
0.577349; -0.577349; -0.577349;,
0.577349; -0.577349; 0.577349;,
-0.577349; -0.577349; 0.577349;,
-0.577349; -0.577349; -0.577349;,
-0.577349; -0.577349; -0.577349;,
-0.577349; -0.577349; 0.577349;,
-0.577349; 0.577349; 0.577349;,
-0.577349; 0.577349; -0.577349;,
0.577349; 0.577349; 0.577349;,
0.577349; 0.577349; -0.577349;,
-0.577349; 0.577349; -0.577349;,
-0.577349; 0.577349; 0.577349;;
6;
4; 0, 1, 2, 3;,
4; 4, 5, 6, 7;,
4; 8, 9, 10, 11;,
4; 12, 13, 14, 15;,
4; 16, 17, 18, 19;,
4; 20, 21, 22, 23;;
} //End of MeshNormals
MeshTextureCoords {
24;
0.481280;-0.512000;,
0.481280;-0.062321;,
0.031601;-0.062321;,
0.031601;-0.512000;,
0.481280;-0.961679;,
0.031601;-0.961679;,
0.031601;-0.512000;,
0.481280;-0.512000;,
0.481280;-0.512000;,
0.481280;-0.961679;,
0.031601;-0.961679;,
0.031601;-0.512000;,
0.481280;-0.512000;,
0.481280;-0.961679;,
0.031601;-0.961679;,
0.031601;-0.512000;,
0.481280;-0.512000;,
0.481280;-0.961679;,
0.930959;-0.961679;,
0.930959;-0.512000;,
0.481280;-0.512000;,
0.481280;-0.062321;,
0.031601;-0.062321;,
0.031601;-0.512000;;
} //End of MeshTextureCoords
}
}
}
* All models mentioned above load in the DirectXViewer app.
Given that the sample included with DarkGDK loads the scout model, I suspect the issue is with the libraries linked to my project. I am using August 2007 DirectX 9.0c SDK as referenced on the DarkGDK download page (installed with dxsdk_aug2007.exe) and this is the only DirectX SDK installed on my system (or referenced in Visual Studio C++ library directories). Could this be an issue with the DarkGDK libraries? ... or does anyone have any other ideas?
Thanks in advance,
Andrew