CuteAlien wrote:When you compile in debug you should on the crash already see in which line it crashes and the values of all variables at that moment.
I'm using Code::Blocks, and all the debugger is telling me is information I already know and which I cannot use to solve the problem. It's telling me that:
1) the program receives a SIGSEGV signal
2) when it does, it's executing the function CreateWorld().
It's not telling me anything more than that.
And here's the function CreateWorld().
Code: Select all
void CreateWorld(void)
{
unsigned int i;
camera = smgr->addCameraSceneNodeFPS(0,100.0f,0.05f,-1,keyMap,4,false,0.f);
camera->setFarValue(1000);
camera->setNearValue(0.01);
mainlight=smgr->addLightSceneNode(0, core::vector3df(0,100,-100), video::SColorf(1.0f,1.0f,1.0f,1.0f), 500.0f);
MakeSkybox();
//Meshes
mesh[0] = smgr->getMesh("media/1405_duke.md3");
mesh_buffer[0]=mesh[0]->getMeshBuffer(0);
// Textures
duketexture = driver->getTexture("media/1405_duke.png");
rpgtexture = driver->getTexture("media/0023_rpg.png");
// this is the line that makes it CRASH!
mesh_buffer[0]->getMaterial().setTexture(0, duketexture);
// The objects are created, textured and placed
node[0] = smgr->addAnimatedMeshSceneNode( mesh[0] );
node[0]->setMaterialFlag(EMF_LIGHTING, true);
node[0]->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
node[0]->setMaterialFlag(video::EMF_GOURAUD_SHADING, true);
}
If I remove the line that makes it crash, it doesn't crash anymore, and, as expected, all I get is a completely untextured Duke model.
If, instead, I modify that line like this...
Code: Select all
if (!mesh_buffer[0])
return;
else
mesh_buffer[0]->getMaterial().setTexture(0, duketexture);
it doesn't crash anymore, and, as expected, I get an empty scene, because the function returns before placing the model.
So I know it crashes because mesh_buffer[0] remains at zero even after the execution of the getMeshBuffer function, contrary to expectations, and this is already more than what the debugger is telling me.
I even thought that maybe I'm not supposed to use 0 as a parameter for getMeshBuffer, so I changed this line
Code: Select all
mesh_buffer[0]=mesh[0]->getMeshBuffer(0);
into this:
Code: Select all
for (i=0; i<65535 && !mesh_buffer[0]; i++)
mesh_buffer[0]=mesh[0]->getMeshBuffer(i);
if (!mesh_buffer[0])
return;
and it
still returns before placing the model, because no matter what parameter I use for getMeshBuffer, the value of mesh_buffer[0] always remains zero.
At this point, there are 3 possible explanations:
1) there's something wrong with the model (unlikely, because it's textured correctly in Duke Nukem 3D and it can be textured in Deep Exploration, although its animations cannot be exported for a limitation of the program)
2) there's something wrong with the implementation of getMeshBuffer (unlikely, because someone would have probably found out before me, although it could be... possible?)
3) there's something wrong with one of the assumptions I followed while writing the functions (but what? I have no idea).