Page 1 of 1

Irrlicht crashes when drawing 2d tile

Posted: Tue Sep 23, 2008 3:08 am
by cecil0812
I'm working on a little sprite based RPG using Irrlicht (great engine btw).

I've got these tile based maps that I load for the player to walk on. Everything seems to work ok most of the time.

However, on full screen mode, the call to draw2DImage() causes my game to crash. I'm not sure what I'm doing wrong that is causing this. Here's the code that calls that:

Code: Select all

for (size_t i = 0; i < curMap->mapHeight; ++i)
{
     for (size_t j = 0; j < curMap->mapWidth; ++j)
     {
           mapPosX += 22; // Tiles are 22 pixels in width

           //This is the line that crashes.
           driver->draw2DImage(curMap->mapLayout[i][j].tileImg, 
                       core::position2d<s32>(mapPosX, mapPosY), 
                       core::rect<s32>(0, 0, 22, 15), 0, video::SColor(255, 255, 255, 255), true);
     }

     mapPosX = 0;
     mapPosY += 15; // Tiles are 15 pixels in height.
}
Basically I just go through my array and call the appropriate tile to draw. curMap->mapLayout[j].tileImg is a irr::video::ITexture* which gets loaded like so:

Code: Select all

curMap->mapLayout[i][j].tileImg = driver->getTexture("someTexture.png");
So... I'm a little lost as to why this would be crashing in full screen mode. It also seems to crash hard on my laptop as well. Currently I'm using Irrlicht's Software Driver for testing and not an actual graphics driver... could that be the problem? Any suggestions on where to start looking?

Posted: Tue Sep 23, 2008 7:22 am
by JP
Are the texture's dimensions power of two? (e.g. 256x512, 64x64, 1024x512 etc)

That could be a problem i guess...

But anyway it sounds like it could be an invalid pointer you're passing to draw2DImage.. i don't know if draw2DImage checks the ITexture* for being NULL or not but possibly it doesn't. Before using the ITexture* check if it's NULL.

Re: Irrlicht crashes when drawing 2d tile

Posted: Tue Sep 23, 2008 7:22 am
by rogerborg
cecil0812 wrote:Any suggestions on where to start looking?
Uh... the call stack?

Are you verifying that each tileImg is valid, and/or checking the log for any warnings about missing textures?

Posted: Tue Sep 23, 2008 7:25 am
by hybrid
draw2dimage does check the pointer. However, if it gets invalid pointers there's no chance to recognize it...

Posted: Tue Sep 23, 2008 3:41 pm
by cecil0812
The ITexture* is not null and is pointing to a valid texture. I wish it was something that easy! :)

The call stack is less than helpful because I'm using the compiled version of Irrlicht (for Windows). I guess I could just dig into the Irrlicht code but I'd rather not do that at this time.

The texture is NOT power of two, (22x15). I know that is bad, but at this stage in the game I was more interested in getting textures and such to show up than the speed you get from the power of two texture. Think that could cause a crash though? I could change it.

Posted: Thu Sep 25, 2008 1:13 am
by cecil0812
So I went through and made sure all textures were power of two and it's still giving me problems :(

I'm going to try switching back to the old version of Irrlicht just to narrow it down. I'm sure it will still crash but we'll see.

Any other suggestions?

Posted: Thu Sep 25, 2008 7:07 am
by hybrid
Did you try with other dirvers? What are you using after all, D3D?

Posted: Thu Sep 25, 2008 8:05 am
by rogerborg
cecil0812 wrote:I guess I could just dig into the Irrlicht code but I'd rather not do that at this time.
But presumably you're OK with us doing it for you?

I'll happily debug this if you provide code and resources, but I'm not interested in playing 20 Questions.

Posted: Thu Sep 25, 2008 3:04 pm
by bitplane
cecil0812 wrote: The call stack is less than helpful because I'm using the compiled version of Irrlicht (for Windows). I guess I could just dig into the Irrlicht code but I'd rather not do that at this time.
If you're using VC8/9 then Irrlicht is incredibly easy to get built in debug mode, you'll need the windows platform sdk and directx sdk, then simply double click the project file in /source/Irrlicht/, choose "debug" from the drop down in the menu and press the compile button.

Posted: Thu Sep 25, 2008 5:12 pm
by cecil0812
Yeah, I finally just opened up the Irrlicht source code, compiled it in debug mode and went into it. Let me just say that the Irrlicht source code is really well written and easy to understand. I was a little hesitant to go into the source because a lot of source code for libraries like this looks like it was written to be as incomprehensible as possible.

Anyway, after going through it, I noticed some memory getting clobbered right before it was getting passed in to the draw2DImage(). I made a change to how that memory was getting allocated, made sure nothing else was leaking, and voila, it's working great now.

Thanks to everyone who contributed some useful information :)

Posted: Thu Sep 25, 2008 5:14 pm
by hybrid
So that means that you wrote past your array bounds, or did you find some problem in the engine code?

Posted: Thu Sep 25, 2008 5:15 pm
by cecil0812
No problem in the engine code, just a pointer allocation problem in my code. Going into the Irrlicht source code helped me find it though.