PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

About Pointers

I am currently developing a simple game and have a question about pointers.

I have created the following struct which contains information about the sprites I am using:

typedef struct SPRITE
{
CGapiSurface *surface;
signed int xpos;
signed int ypos;
DWORD direction;
DWORD speed;

} SPRITE;

I then use this struct in an array of size 10.

In the processnextframe function I have 2 game states. In the first state I want to draw the first 5 sprites from the array - so I have used a for loop from i=0 to i<5.
In the second state I want to draw the last 5 sprites so I have used a for loop from i=5 to i<10.

Initially this appears to work fine, when I move from state 1 to state 2. However when I move back from state 2 to state 1 my game exits - I assume this is a null pointer exception of some sort but I don't know why.

Any advice would be greatly appreciated.

Thanks.
Can you give us more info? What type of exception are you seeing? Have you ran it in debug mode to see if you can get the exact line the error is occuring on? What you describe doesn't strike as a null pointer exception... assuming you don't modify the pointers in the structs, and assuming the structs themselves aren't somehow wiped out, and further assuming that it works the first go-round (which I think you said it does), then it doesn't really make sense that the pointer would get messed up (unless your doing something else that you haven't mentioned that could be).
Thanks for your quick response!

As far as I know I'm not modifying the pointers in any way. You have, however, highlighted another of my problems - debugging. Whenever I try to debug my application I get the following error from eVC 3.0:

LINK : fatal error LNK1104: cannot open file "gd203.lib"

I have used the remote file viewer to place it in the windows directory of the Smartphone emulator (the same place where I put the dll for normal execution). Is this correct? If I can get the debugging working I think I'll have more chance of finding my own error!!

Thanks again.
Do you have access to Visual C++ 6.0? If so, I very highly recommend using it rather than eVC++ to do your work. You'll find it better in a number of ways, including debugging. You won't need to bother with an emulator that may or may not be buggy, and its faster in general all-around.

However, the link error means that the lib file can't be found when compiling your application. Take a peak around in the Project... Settings menu. You can specify compile configuration information for each type of build, and my guess is that you only set it up for a release build. In short, you will have to tell the linker where to find the lib file for a debug build (or for all builds, which is an option). I could walk you through it, but frankly I'm being lazy and don't want to go look :) More importantly though, I can tell you from experience that solving problems like this without too much help is a great way to learn how the compile/link process works in eVC or VC6. These types of errors tend to pop up from time to time for us all, and knowing how to solve them goes a long way to saving your sanity (check my posts, you'll see a few with very similar errors... but now I tend to be able to solve them on my own in a few minutes).

With your original issue, if your relatively sure your not touching the pointers, and from what you wrote I don't see how you could, then something else is going on and we'll need more info to try and help you.
Once again, thanks for your quick reply.

I've read all about how much better VC 6.0 is compared to eVC but it costs a whole lot more money!! Anyway, I'll have a look round the compile settings as you suggested and see if I can work it out.
Yes, I know what you mean. I was lucky in that when I got my MCSD, MS was still giving us MSDN subscriptions, so I got all that software for free. They stopped doing that I think a year ago, so I'm not in any hurry to update my certification now that the main benefit in my book is gone :)

(Digression over, we now return you to your regularly scheduled forum posts)
If you're not going to be debugging under VS6 (or even if you are, the following is an excellent tool), check out STLog at

http://www.pocketpcdn.com/articles/stlogfile.html

This will allow you to easily dump debugging info to a logfile. I started using STLog to monitor the AI in Warlords, but I now use it for everything.

Feel free to post your structure initialization code and ProcessNextFrame method and we'll see if we can find anything.
Wow, fantastic post... I didn't know about STLog, nor did I know about PPC Developer's Network. Sweet!
Are you compiling this as C++ or C? If its C++ you don't need the typedef, and if its C, it seems you have a name clash. It would seem they clash regardless, so is this the exact code you are using?
Thanks for your help everyone. I have now got the debugger working - which is nice.

My orginal problem was to do with a null pointer but it was actually to do with the array I use to store the result of a collision detection.

Anyway, thanks again for everyone's help.