Need debug info...
BlitzMax Forums/BlitzMax Beginners Area/Need debug info...
| ||
When your program halts for an out-of-bounds array, why does it not tell you what the element of the array equalled? for example, this line: scenery[lastSlot].CollisionMap [xS,yS]= (argb Shl 24) Shr 24 ...goes out of bounds, but I have no idea what part is out of bounds. I could write a Proceed() to test each variable in each loop, but I'd be hitting 'Ok' a thousand times before getting the error. What other debug methods would be useful in this situation? [edit] By the way, what can Throw/catch/assert do that a simple If-Statement can't? |
| ||
Before the line, add Debuglog lastSlot;debuglog xS+", "+xY... but there's probably better methods I don't treat myself to. =] |
| ||
Yeah, that's pretty useful. It does the job. |
| ||
You could use assert lastSlot >= 0 and lastslot < len(scenery) else "lastSlot is out of bound" assert xs >= 0 and xs < size_x else "xs is out of bound" assert ys >= 0 and ys < size_y else "ys is out of bound" In debug this will give you a runtime error with the specified message when it gets ouf of bound. |
| ||
Is that all assert does? Why do we have it? It's just another way of writing an If-Then statement, isn't it? |
| ||
No Its a debug only construct to check values for correctness. With assert you can guarantee that a function does exactly what you specified them to do. If usage for this kind is a very bad programming style (the last one that did so was microsoft with Win98 which lead to many many bad probs so they dropped the if-error-workaround programming again ;)) |
| ||
I think you cand try catch the exception and print all the debug info you need, too |
| ||
try catch is to catch errors. Assert is to garuantee functionality specification. So this 2 aren't connected to each other normally (as long as you don't use try catch for the same bad programming style as if checks on input). Assert has the pro that it does not exist in Release Build, only in Debug, while try catch is normally especially in release build to have a usefull error handling possibility (because a MAV isn't a usefull error message if you want to get the problem out ouf your program) [edit] on the edit in the base posting: Edit is bound to the program flow and atual stack. With try catch you are not bound to that stack (ie if you do try catch you can catch errors that happen in a function that is called by a function you called in the block of try - end try. This makes it a very powerfull error handling technique) and assert has the pro of only being in there in debug build |
| ||
When your program halts for an out-of-bounds array, why does it not tell you what the element of the array equalled? That's what the debug panel is for. |
| ||
Ok Dreamora, so Assert doesn't get compiled with the program. Nice. And if I understand you correctly, Try-Catch ignores scope? Alright, cool. Thank you all. You've been very helpful. TwoEyedPete, I'm not sure what you mean. The debug panel shows arrays as "Array[...]" and that's it. |
| ||
Debug panel will tell you what xs and ys equals. |
| ||
Yes, but I suppose I worded my original question wrong, hehe. What I really want to know is the value of CollisionMap[xS,yS], not xS or yS. |
| ||
Since xS or yS is out of bounds, CollisionMap[xS,yS] is invalid. |
| ||
That's ok, because I would then know that scenery[lastslot] is not out of bounds. The problem is that I don't know which one of the arrays is array is out of bounds and if the debugger could tell me the values of the valid ones, I could figure it out much quicker. scenery[lastSlot].CollisionMap [xS,yS]= (argb Shl 24) Shr 24 |
| ||
Or you could just look at xS, yS AND lastSlot and figure it out yourself =] I do agree with you, though! |