c++ or irrlicht bug!?

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
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

c++ or irrlicht bug!?

Post by omar shaaban »

i dont need to post my code for this one(i wont anyway :P ) so my program runs fine but when i replace this code:

Code: Select all

  std::cout <<"ended \n";
with this code:

Code: Select all

  std::cout <<a.tcount<<"ended \n";
the program crashes!!
where a.tcount is just a long double, not a method.

and it crashes at that line

Code: Select all

      nodes[i]= sll->addSphereSceneNode(1);
//just bascilly creates sphere nodes for array node(and i doesnt get out of range,as all i changed in code is to printalong double :P
but if i replaced my first code(the one that caused theproblem, with this code:

Code: Select all

  std::cout <<a.tcount<<"ended \n";  std::cout <<a.tcount<<"ended \n";
basiclly just copied it :D the error disappears
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: c++ or irrlicht bug!?

Post by CuteAlien »

If you have crashes which come and dissappear when you add/remove independent lines it's often because you trashed your memory earlier on and the crash is just a follow-up problem.
The trick to find that kind of troubles is first looking really hard at your code and maybe check the stack in the debugger and look if variable values around there are sane.
And if that does not help then start removing everything before that code while keeping the crash. As soon as it no longer crashes add code back in (and maybe remove another part). Until you find the line which is really the problem.
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
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Re: c++ or irrlicht bug!?

Post by omar shaaban »

well i began to move the code :

Code: Select all

std::cout <<a.tcount<<"ended \n";
up the line, and still the crash happened, untill i moved it up the line :

Code: Select all

  pres=new particle[n];
where before the class i identified "pres" as

Code: Select all

particle * pres;
//so it just a pointer to object particle that will be used topoint to an array
then the crash stopped happeneing so what is the problem? is it that i used a very large memory or because somehow the memory refrences gets mixed up when i call my line ?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: c++ or irrlicht bug!?

Post by hybrid »

Are you sure that n is not 0 or negative? That would be one possible memory corruption thing. Otherwise, dynamic allocation should usually return 0 in case of a failure (or even throw). If you weren't using dynamic allocation, good chance would be a stack overrun. But that's also pretty unlikely in this case, unless you have only a few kb RAM available. So maybe you are accessing beyond the array boundaries. Do you access pres[n] somewhere? That would then overwrite some code and maybe invalidate the a object you are calling your methods on.
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Re: c++ or irrlicht bug!?

Post by omar shaaban »

i guess the problem was that i defined pres array as particle[n] where it should be particle[n+1] because in my code i acess press[n] later on...but shouldnt it give me an array out of boundry error?
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Re: c++ or irrlicht bug!?

Post by omar shaaban »

hybrid wrote:Are you sure that n is not 0 or negative? That would be one possible memory corruption thing. Otherwise, dynamic allocation should usually return 0 in case of a failure (or even throw). If you weren't using dynamic allocation, good chance would be a stack overrun. But that's also pretty unlikely in this case, unless you have only a few kb RAM available. So maybe you are accessing beyond the array boundaries. Do you access pres[n] somewhere? That would then overwrite some code and maybe invalidate the a object you are calling your methods on.
i didnt see ur reply first but yeah i accessed press[n] but since i defined press as particle [n] then there should be only elements from 0 to n-1. but as i said above shouldnt it give me an array out of boundry exception error?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: c++ or irrlicht bug!?

Post by CuteAlien »

No, writing outside arrays is valid code in c++ ;-)
If you want checked array access - the irrlicht array creates some assert when compiled in debug. And std::vector has the function "at" that signals when you are outside the boundaries. Also I think when you enable /GS in Visual Studio it might check that. Under Linux valgrind has similar tests.
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
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Re: c++ or irrlicht bug!?

Post by omar shaaban »

yup, great thanks to cute alien and hybird! :)
Post Reply