Texture coding a segmentation fault
Texture coding a segmentation fault
Hi,
I'm having some problems when loading textures in Irrlicht.
Currently when using driver->getTexture("filename") it causes a segmentation fault, but only for some textures and only on loading the second texture (some of the time). There is no other error message (such as a "Could not load texture"), and it never gets to the next line of code.
I'm using Irrlicht 1.6.1.
The textures are PNGs, and currently block colours.
I have checked the filename and most of the other things, thought I would post here to see if anyone had any other ideas...
Thanks in advance.
I'm having some problems when loading textures in Irrlicht.
Currently when using driver->getTexture("filename") it causes a segmentation fault, but only for some textures and only on loading the second texture (some of the time). There is no other error message (such as a "Could not load texture"), and it never gets to the next line of code.
I'm using Irrlicht 1.6.1.
The textures are PNGs, and currently block colours.
I have checked the filename and most of the other things, thought I would post here to see if anyone had any other ideas...
Thanks in advance.
Sorry, that is not enough information to be able to help you. We need some code to reproduce it. If the same png loads when loaded as first texture then it's probably not a problem of the loader.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
The function below causes our problem, specifically the line in bold.
The function will be fine for the first texture but will bail on the second run of the function.
If you need more information feel free to ask.
The function will be fine for the first texture but will bail on the second run of the function.
If you need more information feel free to ask.
Code: Select all
std::string wall = pick_wall(diff, game_type);
if (wall.find(QU_WALLS_DIR) != std::string::npos) {
cout << "Using a question wall...\n";
wallMeshFile = QU_WALLS_DIR + "question.obj";
wallTex = wall + ".png";
wallOverlay = QU_WALLS_DIR + "bg" + FORMAT_EXT;
wallCompare = QU_WALLS_DIR + "ans_" + wall.at(wall.length()-1) + FORMAT_EXT;
} else {
wallMeshFile = wall + ".obj";
wallTex = wall_texs.at(rand() % wall_texs.size());
wallOverlay = wall + FORMAT_EXT;
wallCompare = wallOverlay;
}
cout << "Using wall mesh " << wallMeshFile << "\n";
cout << "Using wall tex " << wallTex << "\n";
cout << "Using wall overlay " << wallOverlay << "\n";
cout << "Using wall compare " << wallCompare << "\n";
if (cv_text_mgr) {
cv_text_mgr->setBG(wallOverlay);
}
cout << "TEX\n";
[b]wall_tex = driver->getTexture(wallTex.c_str());[/b]
cout << "TEX DONE\n";
if (!wall_tex) {
cerr << "BAD TEX!!! " << wallTex << "\n";
}
if (!added_wall_mesh) {
addWall();
added_wall_mesh = true;
} else {
cout << "MESH\n";
wall_node->setMesh(sceneManager->getMesh(wallMeshFile.c_str()));
cout << "DONE MESH\n";
// FIXME bails on this line
//wall_tex = driver->getTexture(wallTex.c_str());
if (!wall_tex) {
cerr << "BAD TEX!!! " << wallTex << "\n";
} else {
cout << "SET TEX\n";
wall_node->setMaterialTexture( 0, wall_tex);
cout << "SET TEX DONE\n";
}
resetWall();
}
}
Try just loading the texture in question twice without doing _anything_ else. When that crashes it's an Irrlicht problem, otherwise you probably have some bug in your code. I don't see anything obvious, but could be anything - for example wall_texs being messed up somewhere.
If you can reduce it to an example where we can just compile & reproduce it then someone can probably help. Otherwise you might have to compile Irrlicht in debug (just open the project file and select the debug setting and re-compile) and try again - this time with the debugger running so you see where it really crashes.
If you can reduce it to an example where we can just compile & reproduce it then someone can probably help. Otherwise you might have to compile Irrlicht in debug (just open the project file and select the debug setting and re-compile) and try again - this time with the debugger running so you see where it really crashes.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Thanks for the reply.
We have moved to 32-bit (as we have had to move to using IrrKlang).
Now there are no more seg faults (as of yet, we haven't had time to properly test it), but now the textures don't load.
The first texture is fine, then the rest don't appear, but they say they are loaded!
I've done what you suggested, every texture can be loaded by getTexture(...), so it just seems it can't be applied to the mesh. I used the debugger, but as the program doesn't crash now, it's hard to see what to look out for...
I'm going to try applying the textures in a empty environment, and see if I can see them then...
Any other advice in the mean time would be greatly appreciated!
We have moved to 32-bit (as we have had to move to using IrrKlang).
Now there are no more seg faults (as of yet, we haven't had time to properly test it), but now the textures don't load.
The first texture is fine, then the rest don't appear, but they say they are loaded!
I've done what you suggested, every texture can be loaded by getTexture(...), so it just seems it can't be applied to the mesh. I used the debugger, but as the program doesn't crash now, it's hard to see what to look out for...
That's the problem it isn't just one texture fileTry just loading the texture in question twice
I'm going to try applying the textures in a empty environment, and see if I can see them then...
Any other advice in the mean time would be greatly appreciated!
I finally had a seg fault when loading a texture caused by...
COpenGLTexture.cpp:477
COpenGLTexture.cpp:477
Code: Select all
glGenTextures(1, &TextureName);
First point:
Why are you trying to output a NULL pointer?
**EDIT**
My mistake.. the names are all too similar!
And are you sure you are not messing the string up somewhere.. you are using many strings and doing all sorts of crap I don't know..
Code: Select all
wall_tex = driver->getTexture(wallTex.c_str());
cout << "TEX DONE\n";
if (!wall_tex) {
cerr << "BAD TEX!!! " << wallTex << "\n";
}
**EDIT**
My mistake.. the names are all too similar!
And are you sure you are not messing the string up somewhere.. you are using many strings and doing all sorts of crap I don't know..
Well, now that you have it crashing again, set some break points before the crash part, and check the values of your parameters manually.I used the debugger, but as the program doesn't crash now, it's hard to see what to look out for...
I can hear birds chirping
I live in the Eye of Insanity.
I live in the Eye of Insanity.
Thanks for posting this, I've also run into the same problem. Seemingly it's impossible to use mesh loaders (in my case I was trying to load a .3ds) in a separate thread. When I try to do so, the program segfaults at glGenTextures.
As for this I'll need to implement a loader in the engine's thread which can be called by others.
As for this I'll need to implement a loader in the engine's thread which can be called by others.
beer->setMotivationCallback(this);