PocketMatrix forums

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

Question about Intersect and possible fix suggestion

Well, I just spent the better part of a day debugging a 5-line piece of code. My head hurts.

However, it may wind up being something to fix in GD, but a question first...

If I do an Intersect test, and one of my surface pointers is bad (i.e., null, or some gibberish), will Intersect return any specific error code?

That's what my problem was... I had an array of surfaces*, and I was checking intersects on them with another surface. Turns out that under certain specific circumstances, my array bounds was overshot and I was passing God knows what to the Intersect function.

I didn't bother checking the return code because as soon as I realized the path through my code was doing that, I fixed it and was happy (read: RELIEVED AS HELL!).

So, if it DOESN'T return a specific code Johan, you may want to add such a test as a trivial rejection. If it does already do this, obviously ignore this, I'll just have to check the return code next time if I'm doing something "risky" like dealing with arrays of surfaces with a changing index.
Rule 1: Always check return codes - thats what they are there for.

Rule 2: Invest in a memory checker. I swear by BoundsChecker - it has found enough array overruns in the Warlords code to save me weeks of debugging time.
fzammetti: All parameters in GapiDraw are verified in a couple of dozen different ways depending on the function. All pointers are always checked for NULL, and every function will return GDERR_INVALIDPARAMS if one should be NULL.
Yes, BoundsChecker looks very nice. Unfortunately, like most tools in that category it's simply too expensive for a small-time developer like me. I'm just going to have to keep bashing my head against walls. More painful, but cheaper.

Your right about checking return codes of course. I really should get myself into that habit more than I am now (which frankly is usually only when I'm debugging a problem).

Thanks Johan, it's good to know GD is checking that stuff. I assumed it was, but it's good to hear it for sure none the less.