Exception Access Violation: Why?

BlitzMax Forums/BlitzMax Beginners Area/Exception Access Violation: Why?

Michiel(Posted 2011) [#1]
Hello,

I just started messing around with BlitzMax but seem to stumble upon the same error over and over again. Must be something pretty basi I do wrong but I get the error:

"EXCEPTION ACCESS VIOLATION"

quite often and I can't seem to figure out why. It seems that is has something to do with me creating classes/types in the wrong manner, but I would like to know what exactly triggers this error to pop up, so I can figure out how NOT to have it show up... Googling only resulted in one (pretty old) hit, so I'm just going to post this probably very noobish question right here.

So if anyone could explain to me what is happening exactly, I would really appreciate that.

Thanks!

Michiel.


ima747(Posted 2011) [#2]
To boil it down. An access violation occurs when a program attempts to access un-allocated, or restricted memory. This violation of the memory space causes an exception (fatal error).

So what's causing it could be anything that's accessing the wrong thing at the wrong time... pretty vague. Chances are something isn't properly initialized before you're using it, or has been released and you're still trying to access it. Again, pretty vague.

Fundamentally there's an allocation or management problem somewhere. Where it is, what it is, why it's throwing an exception, etc. are impossible to guess at since there's no way to know what or how you're doing things.

It could also be driver or OS related, in that there could be a DLL or graphics driver that's not behaving right and causing the problem. It could be a module with a glitch, etc.


col(Posted 2011) [#3]
Use Debug Mode to prevent the EAV and stop program execution at the line of the error. This may not be the real fault though, look in the variables on the right to find the real fault.

Debug Mode is in the Menus under Program/Build, make sure Debug Build is ticked.


Michiel(Posted 2011) [#4]
@ ima747

Thanks, it indeed seems to be related to me accessing something that hasn't been instantiated (correctly) yet. Guess I'll just need to keep experimenting a lot more before actually trying to create something useful. Thanks again for the pointers!


Michiel(Posted 2011) [#5]
@ col

And thanks to you too :) With the debugging on, things get quite a lot more understandable; now I get "Unhandled Exception: Attempt to access field or method of Null object". And that IS something I can wrap my head around :P

Thanks a lot!


col(Posted 2011) [#6]
You're welcome :-)
The debugger will stop at the line that has the 'Null' variable, and in your variables on the right hand side you can also see which one it is.

The debugger is the most valuable tool, although its not flawless when you start getting into real avanced stuff, but its still a very good debugger that can aid in narrowing down most general faults.


Czar Flavius(Posted 2011) [#7]
If you are creating an array of types, you also need to new each individual element of the array too. Could that be it?