Sign in to follow this  

help catching a bug

This topic is 3774 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having problems with an annoying bug in my game lately. I use the ogre engine for my graphics and a PHYSX wrapper called NXOgre. The problem occurs when I delete one of my projectile objects. I believe that PhysX is trying to use a null pointer somewhere. I get a crash in debug pointing to this line of code. for(Actors::Iterator it = mActors.items.begin();it != mActors.items.end();++it) { (*it).second.first->simulate(time); } I'm not asking for expert insight into how physx or NXOgre works. I posted in their forums already. I'm really asking for help in debugging in general. I use Visual studio 2005 and i like the debug feature but truthfully I'm not very versed at using it's full functionality. Is there a way i can go back in the source to see what the program was doing before it crashed? Is there a way i can get more information on what data is bad? How do i interpret the local variables at the bottom of the visual studio debugger. Like this: !first CXX0030: Error: expression cannot be evaluated My problem is really annoying because i don't know when the app crashes lol. I don't know how to recreate the crash. 99% of the time when i delete a projectile it works as planned but sometimes when i delete one i get a crash... truthfully i am not even sure its when i delete a projectile i only know i get crashes when i am shooting and i believe its because of a null pointer. sigh... well any insight is welcome... i would be glad for some good debugging advice... Thank you to all who help in advance

Share this post


Link to post
Share on other sites
One of the things you could do at that point in time is use the debugger watches to look at the data structure and see if there seems to be any oddities in it, like uninitialized or null pointers.
As for not being able to evaluate variables, you're not trying to debug a release build, are you?

As a possible cause of your error: From the looks of your iteration there, I would guess you're using a map. Note that operator[] on maps default construct a value if no key exists.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zao
One of the things you could do at that point in time is use the debugger watches to look at the data structure and see if there seems to be any oddities in it, like uninitialized or null pointers.

As a possible cause of your error: From the looks of your iteration there, I would guess you're using a map. Note that operator[] on maps default construct a value if no key exists.


wow thx for the quick reply (6mins at 3am lol)

I myself am not using the map the line of code i submitted earlier is part of the PhysX wrapper i am using. From what the creator tells me... it should be crash free if i delete the object correctly from my end of the code:


void Projectile::Destroy()
{
//if(mBody->isAutoDeletable())

mScene->destroyBody(mBody->getName());

if(GraphicType=="Billboard")
MyBillboardSet->removeBillboard(MyBillboard);

if(TargetNode!=NULL)
{
GetSceneMgr()->destroySceneNode(name+ "TargetNode");
}
}




I keep all my projectiles as a list of pointers to my projectile objects.

as for watching the data structure... sadly i don't know how to do this exactly or even what it does. Can you please be more specific?

Quote:
Original post by Zao
As for not being able to evaluate variables, you're not trying to debug a release build, are you?


im not too sure on this either but i believe i am. At the top of visual studio it does have release selected. Is there a problem with this?

Share this post


Link to post
Share on other sites
I'd highly suggest just using the debugger's callstack and your watch or locals window to track down what is causing the crash (this should be easy. It's most likely that either "it" is a null pointer, or one of the other three things it's dereferencing in one line are garbage.

To make debugging this easier, instead of doing it all in one line, try storing parts in local variables and using asserts.

(Note, I don't know what second or first are so I'll just pretend they're Actors).

i.e.


for(Actors::Iterator it = mActors.items.begin();it != mActors.items.end();++it) {
Assert(it);

Actor first = (*it).second.first;
Assert(first);

first->simulate(time);
}




(of course you'd replace the variable types with the actual types and the asserts with whatever macro you are using).

Share this post


Link to post
Share on other sites
@dashurc I believe our posts overlaped (1 min apart lol) but the code i submitted is not mine, it is from the PhysX wrapper i use. But i believe the error IS generated in my code because i am nulling a pointer SOMEWHERE lol. Read above for details

Quote:
Original post by dashurc
I'd highly suggest just using the debugger's callstack and your watch or locals window to track down what is causing the crash


This might be what i am looking for but i am very unfamiliar with the debugger right now. Could you please be more specific? I know the locals window at the bottom of the screen while i debug but the information i get is very scarce (in my opinion) I don't know which projectile has the null pointer.

Share this post


Link to post
Share on other sites
Quote:
Original post by jchmack Is there a way i can go back in the source to see what the program was doing before it crashed?


Yes, use the callstack tab (alt+7). Only visible when breaked in debug mode.

Quote:
Original post by jchmack Is there a way i can get more information on what data is bad?


Just hover your mouse cursor over the variables until you see something wrong. In your case
(*it).second.first->simulate(time);
hovering over second might give a good pointer, but hovering over first might show you 0 (null) that mean whatever is in "first" got deleted and you try to call simulate on nothing.

Quote:
Original post by jchmack How do i interpret the local variables at the bottom of the visual studio debugger. Like this:

!first CXX0030: Error: expression cannot be evaluated


The local tab automatically add local variables into the panel, the watch tab allow you to insert your own variable watch. In your case you might need to write
(*it).second.first to see the value of first.

Share this post


Link to post
Share on other sites
Thank you all for the help. I am trying many of the methods mentioned and still have no new insights into what is going on with my bug. I believe that i am going to look at some tutorials on how to use the debugger and all its features.

i have one final question about this post:
Quote:
Original post by Zao
As for not being able to evaluate variables, you're not trying to debug a release build, are you?


i noticed that when i run in debug mode my game is MUCH lower framerate wise. What does debug mode do exactly?

Share this post


Link to post
Share on other sites
When compiled in debug mode, few, if any optimizations are active.
That means no inlining, no return value optimization, checked iterators, padded memory allocations, filling deallocated memory with special patterns.

As for having issues debugging in release mode, the output the compiler produces for a release build is quite different from the source code you passed in, so it's rather common to get invalid or no results at all in the debugger.

Share this post


Link to post
Share on other sites

This topic is 3774 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this