Jump to content
  • Advertisement
Sign in to follow this  
chbrules

Inter-class pointer issues

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

So I have a base class w/ a struct in it, I inherit it off to 2 more classes, which in turn create pointer objects each. One I create a whole new arrays of information, the other I assign it the memory reference of the other in the other class w/ the data. So when I go to assign an integer variable the value of it, it comes up with a run-time error during execution: System.NullReferenceException. It compiles just fine, using debug mode I can see the values are there. How come when it hits the part to read the int value from the pointed to int array it crashes?
int temp = Map[y].tile_ID[x]; //<---pointer error crap going on
I can see in debug mode that the values of tile_ID[x] is there, but it still crashes.
struct sMap{ int *tile_ID; bool *clip; };
Map is a struct array and tile_ID is a int array. Help please! =(

Share this post


Link to post
Share on other sites
Advertisement
Obvious question I admit: are you sure that tile_ID points to a correctly allocated array of integers? int * tile_ID will not allocate any memory by itself, you have to create your own array in memory and have tile_ID point to it. (Same question for Map).

Share this post


Link to post
Share on other sites
Yes, as I said, I can see the values properly in RAM during a debug sessession. Wouldn't you think I'd get a compiler error if I didn't? Converterting a int* to int doesn't go smoothly usually.

Share this post


Link to post
Share on other sites
This kind of call crashes if you read memory that doesn't belong to you. This can happen if one of your pointers points to memory that hasn't been allocated, or if one of your indices is out of bounds.

Also, a compiler cannot check if you always initialize your values correctly before using them. This is the job of a static semantical analysis program, which costs a lot and takes hours to complete.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!