Be a Supporter!

C++ pointer, crash to desktop?

  • 449 Views
  • 9 Replies
New Topic Respond to this Topic
LordAba
LordAba
  • Member since: Nov. 2, 2000
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
C++ pointer, crash to desktop? 2005-05-09 11:43:04 Reply

Okay, I'm making a game but there is a line of code that crashes the game to the desktop, and I have no idea why. The line is:

shotHead->next = NULL;

The structure is:

struct shotNode
{
shot item;
shotNode *next;
};

I know I'm being vague right now, but anyone experiance trouble with this before? I'll try to post more about it later... Right now I have a meeting to go to.


What may man within him hide, though angel on the outward side.

BBS Signature
ManateeGod
ManateeGod
  • Member since: May. 26, 2004
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to C++ pointer, crash to desktop? 2005-05-09 12:57:53 Reply

Are you getting a null pointer exception/error? (forgive my java speak)
If that's the case, your pointer is trying to access a method (function?) of the next node. However, because it's null, there's nothing to access. To fix, make sure your code checks that shot.next != null; before attempting to try shot.next.somtfucntion().

If that's not it, are there anymore details you could give?

LordAba
LordAba
  • Member since: Nov. 2, 2000
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to C++ pointer, crash to desktop? 2005-05-09 15:36:45 Reply

At 5/9/05 12:57 PM, ManateeGod wrote: Are you getting a null pointer exception/error? (forgive my java speak)

Oh, it's not a problem with that, I know pointers like the back of my hand.
It's just there is one cpp file that if I try to manipulate a pointer in any way it crashes to the desktop. I have no idea what is happening, either.

Here is everything: www.uwplatt.edu/~ronczkaa/shooter.zip
That includes the project etc. Done in VC++ 6.0 and all that jazz.

WAIT A MINUTE! How does one change the security settings of a computer in terms of .net again? I did it before but I'm not sure... Cause it seems like the problem only exists on my work computer.


What may man within him hide, though angel on the outward side.

BBS Signature
Ravens-Grin
Ravens-Grin
  • Member since: Jun. 3, 2003
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to C++ pointer, crash to desktop? 2005-05-09 16:50:51 Reply

You might want to include this in your code:

Either

#define WIN32_LEAN_AND_MEAN
or
#define VC_EXTRALEAN

Here's a MSDN site to explain it MSDN

It basically doesn't include headers that are usually not used from the <windows.h> header.

Ravens-Grin
Ravens-Grin
  • Member since: Jun. 3, 2003
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to C++ pointer, crash to desktop? 2005-05-09 16:53:18 Reply

I was looking at the shot.cpp file, all of the other cpp files have it.... my bad

LordAba
LordAba
  • Member since: Nov. 2, 2000
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to C++ pointer, crash to desktop? 2005-05-09 20:57:57 Reply

Man.... WTF WTF WTF SHIT ASS BITCH, ETC.

Yeah, so it just dies at the work computer, but at home it pops up a very general "An error has occured" message.

OMGOMG! After writing the above, I just learned that I can't manipulate a pointer IN ANY FILE! I'm freakin' out man!


What may man within him hide, though angel on the outward side.

BBS Signature
CronoMan
CronoMan
  • Member since: Jul. 19, 2004
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to C++ pointer, crash to desktop? 2005-05-10 05:26:24 Reply

At 5/9/05 08:57 PM, Lord_Aba wrote: Man.... WTF WTF WTF SHIT ASS BITCH, ETC.
Yeah, so it just dies at the work computer, but at home it pops up a very general "An error has occured" message.

OMGOMG! After writing the above, I just learned that I can't manipulate a pointer IN ANY FILE! I'm freakin' out man!

What "any file"?

Can you point out the line where you actually manipulate the pointer?
I'm too lazy to download the file.

You might be referencing a bad pointer (like 0xcdcdcdcd (aka no-mans-land) or something) to an API function call, that can cause programs to crash to desktop sometimes (since it's not the code of the program itself that causes it to crash)


"no sound in ass"

LordAba
LordAba
  • Member since: Nov. 2, 2000
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to C++ pointer, crash to desktop? 2005-05-10 08:52:16 Reply

At 5/10/05 05:26 AM, CronoMan wrote: What "any file"?

Can you point out the line where you actually manipulate the pointer?
I'm too lazy to download the file.

You might be referencing a bad pointer (like 0xcdcdcdcd (aka no-mans-land) or something) to an API function call, that can cause programs to crash to desktop sometimes (since it's not the code of the program itself that causes it to crash)

Any file as in any .cpp file in my project. Even though I can manipulate them in the .h files.

In one of my classes I declare a struct as:
struct shotNode
{
int item;
shotNode *next;

shotNode(int i, shotNode *n)
{
item = i;
next = n;
}
};

Then decalre a global variable:
shotNode *shotHead;

Then in code I do:
shotHead = new shotNode(5, NULL);

This line of code causes it to crash to the desktop after raising a very generic error. It has to be something stupid I'm missing, but I don't see it right now. Specially since I got the game to work the exact same way before...


What may man within him hide, though angel on the outward side.

BBS Signature
LordAba
LordAba
  • Member since: Nov. 2, 2000
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to C++ pointer, crash to desktop? 2005-05-10 11:44:54 Reply

Yeah, I suck at life. Not only did I use the Draw_Text_GDI wrong, but yeah... You're sposed to new something before you use it.


What may man within him hide, though angel on the outward side.

BBS Signature
CronoMan
CronoMan
  • Member since: Jul. 19, 2004
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to C++ pointer, crash to desktop? 2005-05-11 05:15:02 Reply

At 5/10/05 11:44 AM, Lord_Aba wrote: Yeah, I suck at life. Not only did I use the Draw_Text_GDI wrong, but yeah... You're sposed to new something before you use it.

Hehe, even the best make that mistake. I bet John Carmack and Ken Silverman do that all the time


"no sound in ass"