Page 1 of 1

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

Posted: Sun Jun 09, 2013 4:15 pm
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.

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

Posted: Sun Jun 09, 2013 4:32 pm
by hendu
Well that's a pretty clear error, your m_cars array only has 11 spots allocated.

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

Posted: Mon Jun 10, 2013 12:18 pm
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..

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

Posted: Mon Jun 10, 2013 1:57 pm
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.

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

Posted: Fri Aug 16, 2013 6:52 pm
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.

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

Posted: Sat Aug 17, 2013 11:15 am
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.

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

Posted: Sun Aug 18, 2013 2:09 am
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.

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

Posted: Sun Aug 18, 2013 10:58 am
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).