Loading Meshes: Assertion `!(index>=used)' failed

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Loading Meshes: Assertion `!(index>=used)' failed

Post by dejai »

Code: Select all

 
../../include/irrArray.h:308: T& irr::core::array<T, TAlloc>::operator[](irr::u32) [with T = irr::core::vector3d<float>, TAlloc = irr::core::irrAllocator<irr::core::vector3d<float> >, irr::u32 = unsigned int]: Assertion `!(index>=used)' failed.
I am getting the above runtime error, causing a segmentation fault when I begin to load my scene as I attempt to load a series of meshes, that I want to use.

Code: Select all

 
  IMeshSceneNode* node;
  for (int i = 1; i <= 20; i++) {
    std::stringstream ss;
    ss << "data/media/cars/" << i << ".lwo";
    std::string filepath = ss.str();
    m_cars[i - 1] = m_smgr->getMesh(filepath.c_str());
    //m_cars.push_back(m_smgr->getMesh(filepath.c_str());
  }
 
Odly enought when the range is to (i <= 11) it works fine, the cars load and the program runs as usal. Moving the ordering of the files (as in swapping 12.lwo to something else has no effect). However for i > 11 no matter what combination the application segmentation faults on the error above.
Programming Blog: http://www.uberwolf.com
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Loading Meshes: Assertion `!(index>=used)' failed

Post by hendu »

Well that's a pretty clear error, your m_cars array only has 11 spots allocated.
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Re: Loading Meshes: Assertion `!(index>=used)' failed

Post by dejai »

It actually has enough for 50. This is why I posted this here, also please read the type that the compiler is complaining. It isn't the type m_car holds..
Programming Blog: http://www.uberwolf.com
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Loading Meshes: Assertion `!(index>=used)' failed

Post by hendu »

That's pretty hard to do when you haven't posted the full code. Let me just check my crystal ball on how you initialized m_cars, what type, and how you reserved space.

A full backtrace would also be helpful.
chronologicaldot
Competition winner
Posts: 685
Joined: Mon Sep 10, 2012 8:51 am

Re: Loading Meshes: Assertion `!(index>=used)' failed

Post by chronologicaldot »

Try this:

Code: Select all

 
irr::core::array<IMesh*> m_cars(50);
/* constructor calls m_cars.reallocate(50); */
 
irr::s32 i = 0;
std::stringstream ss;
 
for( ; i < 20; i++ )
{
    ss << "data/media/cars/" << i << ".lwo";
    std::string filepath = ss.str();
    m_cars.push_back(m_smgr->getMesh(filepath.c_str());
}
 
Just for future note, stick to using push_back and push_front for adding elements to the array. [] is more for accessing data that already exists in the array (allocated slot space doesn't count).

And just to be sure - make sure all of those files exist, otherwise you get returns of 0. If that every happens and you try [] for assignment, one slot will be skipped, resulting in the index>=used error that you got above.
CuteAlien
Admin
Posts: 9643
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Loading Meshes: Assertion `!(index>=used)' failed

Post by CuteAlien »

We can't try this as we don't have your models. Just passing 0 instead of whaever pointers you get works - so the problem is not the array. The error also hints at that. Meaning it looks like a problem in the model loader. Which is why we would need the backtrace like hendu mentioned. Could it be it crashes for example always when loading the same model? You could try loading model "1.lwo" instead x times.
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
chronologicaldot
Competition winner
Posts: 685
Joined: Mon Sep 10, 2012 8:51 am

Re: Loading Meshes: Assertion `!(index>=used)' failed

Post by chronologicaldot »

Hahahaha
@CuteAlien - Are you talking to me (chronologicaldot) or the OP (dejai)? I was giving dejai a suggestion.
Also, I did not know passing 0 to the array would still work, but I wouldn't do it anyways.

Since I also have a (what I believe is a functional) .lwo file, I may test this myself to see if I get the same error dejai does.
CuteAlien
Admin
Posts: 9643
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Loading Meshes: Assertion `!(index>=used)' failed

Post by CuteAlien »

@chronologicaldot: Ow, sorry - I got confused there and for some reason thought the first and last post would be by the same person. Ehm, I really should stop writing posts directly after waking up when my brain is still sleeping (which I am doing again right now.. hehe).
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
Post Reply