Irrlicht crashes when drawing 2d tile

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
cecil0812
Posts: 12
Joined: Tue Jul 29, 2008 4:57 pm

Irrlicht crashes when drawing 2d tile

Post 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?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post 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.
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Re: Irrlicht crashes when drawing 2d tile

Post 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?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

draw2dimage does check the pointer. However, if it gets invalid pointers there's no chance to recognize it...
cecil0812
Posts: 12
Joined: Tue Jul 29, 2008 4:57 pm

Post 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.
cecil0812
Posts: 12
Joined: Tue Jul 29, 2008 4:57 pm

Post 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?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Did you try with other dirvers? What are you using after all, D3D?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post 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.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post 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.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
cecil0812
Posts: 12
Joined: Tue Jul 29, 2008 4:57 pm

Post 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 :)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

So that means that you wrote past your array bounds, or did you find some problem in the engine code?
cecil0812
Posts: 12
Joined: Tue Jul 29, 2008 4:57 pm

Post 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.
Post Reply