Texture coding a segmentation fault

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Mewtwo
Posts: 6
Joined: Fri Apr 23, 2010 12:26 pm

Texture coding a segmentation fault

Post by Mewtwo »

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.
CuteAlien
Admin
Posts: 9679
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

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
Mewtwo
Posts: 6
Joined: Fri Apr 23, 2010 12:26 pm

Post by Mewtwo »

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.

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();
	}
}
CuteAlien
Admin
Posts: 9679
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

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.
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
Mewtwo
Posts: 6
Joined: Fri Apr 23, 2010 12:26 pm

Post by Mewtwo »

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...
Try just loading the texture in question twice
That's the problem it isn't just one texture file :(

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!
Mewtwo
Posts: 6
Joined: Fri Apr 23, 2010 12:26 pm

Post by Mewtwo »

I finally had a seg fault when loading a texture caused by...

COpenGLTexture.cpp:477

Code: Select all

glGenTextures(1, &TextureName);
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Aha :o I guess your system is simply borked. Either you have some memory corruption somewhere, or your drivers/hardware are going to die.
Mewtwo
Posts: 6
Joined: Fri Apr 23, 2010 12:26 pm

Post by Mewtwo »

hybrid wrote:Aha :o I guess your system is simply borked. Either you have some memory corruption somewhere, or your drivers/hardware are going to die.
It does it on another machine, (and this one before we went 32-bit).

Anything else we can do..?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, the memory corruption does not need to be hardware caused. Could also be that you're overwriting the stack or something. Try a memory checker such as valgrind.
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

First point:

Code: Select all

wall_tex = driver->getTexture(wallTex.c_str());
cout << "TEX DONE\n"; 
if (!wall_tex) { 
   cerr << "BAD TEX!!! " << wallTex << "\n"; 
} 
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..
I used the debugger, but as the program doesn't crash now, it's hard to see what to look out for...
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 can hear birds chirping
:twisted:

I live in the Eye of Insanity.
Mewtwo
Posts: 6
Joined: Fri Apr 23, 2010 12:26 pm

Post by Mewtwo »

Hi guys

We spent a few hours trying to sort this problem out and we think it was due to multiple threads (with the BOOST library) running in our game so it wasn't really anything to do with irrlicht!

thanks for the help
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

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.
beer->setMotivationCallback(this);
Post Reply