access violations
In almost every game I''ve tried to write some kind of random "access violation" has popped up. What the hell is an access violation and how do avoid/fix it? Any help would be greatly appreciated.
Access violation means you are trying to read/write memory that does not belong to your app. It means there is a bug somewhere in the code, usually a pointer bug. Something like this:
The ugly part is that occasionally uninitialized pointer will contian a legal memory address or memory referenced by a dangling pointer will still be available to your app even after you released it. Then by pure luck your app kinda sorta works. That''s why these bugs appear "random". To fix it first thing to do is to get rid of the randomness. Use debug build, initialize all variables when you declare them, set pointers to NULL right after you call delete, use asserts, etc. This won''t fix access violations but will make them more visible and will help you to find which line actually causes it.
As for avoiding bugs - well, you can start by reading Writing Solid Code.
Good luck!
//// uninitialized pointer//long* pfoo; // pfoo points to a random memory locationlong foo = *pfoo; // access violation - we are reading from random memory address//// dangling pointer//long *pbar = new long;delete pbar;long fbar = *pbar; // access violation - we are reading from memory we''ve already released
The ugly part is that occasionally uninitialized pointer will contian a legal memory address or memory referenced by a dangling pointer will still be available to your app even after you released it. Then by pure luck your app kinda sorta works. That''s why these bugs appear "random". To fix it first thing to do is to get rid of the randomness. Use debug build, initialize all variables when you declare them, set pointers to NULL right after you call delete, use asserts, etc. This won''t fix access violations but will make them more visible and will help you to find which line actually causes it.
As for avoiding bugs - well, you can start by reading Writing Solid Code.
Good luck!
quote:
As for avoiding bugs - well, you can start by reading Writing Solid Code.
You mean Microsoft has people that know how to write solid code?
HAHAHAHAHAHA!
j/k
-Coleco
~ c o l ec o ~
Rock the cradle of love!
You stupid WANKER!
mmmmmmmmmmkay
--HASBRO SUCKS--
thier code is generally not too bad, its thier designs that suck.
Like the scan disk program for 9x, that designer needs a public execution.
Like the scan disk program for 9x, that designer needs a public execution.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement