Error Within GetTexture()

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
pwierz
Posts: 59
Joined: Sun Aug 20, 2006 3:32 pm

Error Within GetTexture()

Post by pwierz »

I am getting an access violation when I call GetTexture(). But I think I may be trying to do something I'm not allowed to do. Here's some pseudocode of what I'm doing wrong:

Code: Select all

	
/*Here we load all the models and texture for the welcome menu.  Here GetTexture works fine*/
driver = device->GetVideoDriver();
LoadWelcomeMenu(driver );

/*Draw the welcome menu until they pick a level*/
while(device->run() && !LevelPicked() )
  if (device->isWindowActive())
  {
    driver->beginScene(true, true, video::SColor(0,200,200,200));
    smgr->drawAll();
    driver->endScene();
  }

/*Now that a level has been picked, let's load its geometry and textures.  Here is where GetTexture fails even though the driver pointer is valid and we're trying to load a texture that does exist.*/
LoadLevel(driver);

/*Now draw the level but I never make it this far*/
while(device->run() && !LevelPicked() )
  if (device->isWindowActive())
  {
    driver->beginScene(true, true, video::SColor(0,200,200,200));
    smgr->drawAll();
    driver->endScene();
  }
The Load functions are just simple commands like:

Code: Select all

	video::ITexture* map = driver->getTexture("texutre.jpg");
 
So before I start putting up all the actual code, I just want to make sure that I'm allowed to split up the draw loop like that? Are there cleaner or more efficient ways to do it? Is the error because I should be dropping and recreating an irrlicht object before I start loading for a second draw loop? Thanks for your help.

EDIT: Changed to make code more concise.
Last edited by pwierz on Tue Feb 06, 2007 1:38 am, edited 2 times in total.
Jeremiah Griffin
Posts: 6
Joined: Tue Jan 23, 2007 7:55 am
Location: Yucca Valley, California, USA
Contact:

Post by Jeremiah Griffin »

You should be creating the video driver before using getTexture. It should be created in main() or WinMain() and not be recreated for different usages. First, create the video driver directly after creating the device, or setting the device's caption, then add an IVideoDriver parameter to the texture loading routines, and use that in them instead of creating a driver just for that.
pwierz
Posts: 59
Joined: Sun Aug 20, 2006 3:32 pm

Post by pwierz »

Jeremiah Griffin wrote:You should be creating the video driver before using getTexture. It should be created in main() or WinMain() and not be recreated for different usages. First, create the video driver directly after creating the device, or setting the device's caption, then add an IVideoDriver parameter to the texture loading routines, and use that in them instead of creating a driver just for that.
Sorry I didn't add that to the pseudocode. I get the driver before the first loop and use the same one throughout.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, you close the device in between (otherwise device->run woul not return false) and then it's closed and gone. You cannot reactivate it by simply using it. You have to create a new one. Better use several scene managers to switch between scenes.
pwierz
Posts: 59
Joined: Sun Aug 20, 2006 3:32 pm

Post by pwierz »

But if I use several scene managers, won't that still require that I load everything at startup? I don't want to do that because it takes about a minute to load a level. I only want to load it when they select it so that I won't waste time.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

But that's a completely different problem. You asked why your program crashes, and that's because you kill the device and use it afterwards. Simply stop your loop without stopping hte device and you should be fine with every solution you find.
pwierz
Posts: 59
Joined: Sun Aug 20, 2006 3:32 pm

Post by pwierz »

Sorry to sound like a total noob but which line is killing the device?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Now, with !LevelPicked you might come along. But without you have to close device->close() which would kill it.
pwierz
Posts: 59
Joined: Sun Aug 20, 2006 3:32 pm

Post by pwierz »

The !levelPicked() has been there. The driver doesn't give an error until I do the second load. I never call device->close() and the driver pointer appears valid. Is that right?
Post Reply