Jump to content
  • Advertisement
Sign in to follow this  
NukeCorr

odd C++ bug(?)

This topic is 3203 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

Okay, I have no idea what's happening here.
...
#define DEFAULT_KILLSMSG 6
...
int killsMsgWep[DEFAULT_KILLSMSG];
...
// init()
// this for() loop, crashes the program
// but if I replace -1 with 0 or something else, it does not crash
for(int i=0;i<DEFAULT_KILLSMSG;i++)
{
   killsMsgWep = -1;
}
...
// then i decided to check which of them crashes it
killsMsgWep[0] = -1;
killsMsgWep[1] = -1; // <--- this one, when it's -1, it crashes the program
killsMsgWep[2] = -1;
killsMsgWep[3] = -1;
killsMsgWep[4] = -1;
killsMsgWep[5] = -1;
...

Those are the only places "killsMsgWep" variable is used, nowhere else. So how can the initializion crash the program with such simple variable? Am I missing something here or what's this about :S

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by NukeCorr
Okay, I have no idea what's happening here.

*** Source Snippet Removed ***
Those are the only places "killsMsgWep" variable is used, nowhere else.
So how can the initializion crash the program with such simple variable?
Am I missing something here or what's this about :S


That works completely fine when run in isolation, what compiler are you using? I'm guessing there must be something else in your code causing this, perhaps memory has been corrupted somewhere else in your code.

Share this post


Link to post
Share on other sites
I'm using MSVC++ 6.0 (yes I know I should get the latest one).

If it's corrupted memory, how do I fix or prevent that, and what might be causing it?

EDIT: the program has over 40 files of source, could that affect in it too?

Share this post


Link to post
Share on other sites
Is that array defined globally like your example indicates, or is it actually part of a class or something in your actual code?

Share this post


Link to post
Share on other sites
Quote:
Original post by grekster
Is that array defined globally like your example indicates, or is it actually part of a class or something in your actual code?


it's part of a class under public:

Share this post


Link to post
Share on other sites
Quote:
Original post by NukeCorr
Quote:
Original post by grekster
Is that array defined globally like your example indicates, or is it actually part of a class or something in your actual code?


it's part of a class under public:


And the init() function is too? In that case is the instance of the class you're calling init() on valid? if not then that could easily cause a crash.

If init() isn't part of the class, what instance are you accessing the array on?

Share this post


Link to post
Share on other sites
init() is in the same class as the array, and the class has many other defined variables and functions (bool, int, etc). And the others work just fine, but this new array I added causes failure

Share this post


Link to post
Share on other sites
Yes but is the actual instance of the class you are calling init() on valid?

Also it may be helpful to show some more actual code, like the whole of the init function plus where it gets called from.

Share this post


Link to post
Share on other sites
Sorry, I don't understand your question..

anyway, I removed the array just to test does the rest of the code work and now it doesn't, it did earlier though.
When I run debugger it gives me this:
http://img17.imageshack.us/img17/2447/acsv.png

Share this post


Link to post
Share on other sites
It seems to me like the class instance you are actually calling init on is invalid, possibly a null pointer or just uninitialized e.g.:

MyClass myInstance;
myInstance.init(); // <-- good, valid instance of the class!

MyClass* myInstance;
myInstance->init(); // <---- bad! uninitialized pointer, not a real instance of 'MyClass'

Quote:
Also it may be helpful to show some more actual code, like the whole of the init function plus where it gets called from.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!