How to survive / prevent a memory access violation crash ?

Windows specific questions.
Post Reply
K128
Posts: 33
Joined: Jun 14, 2011 3:23
Location: Kathmandu, Nepal

How to survive / prevent a memory access violation crash ?

Post by K128 »

I have 'On error goto __' also tried with TRY CATCH Implementation from Cherry but my app crashes whenever it violates memory access.

Actually nothing to hide about, I am making a Library in FB which contains many exported functions one of which is an attempt to port 'C' language's VMDetect to FB and that's where the problem occurs it violates memory access and results in the app being crashed. Is there anyway to prevent the crash or do I have to abandon this attempt ?

Thanks....
cha0s
Site Admin
Posts: 5319
Joined: May 27, 2005 6:42
Location: USA
Contact:

Post by cha0s »

Hey K128, check out GDB which is a debugger. Perhaps you'll be able to gain some insight by crashing the program inside the debugger.

http://www.freebasic.net/wiki/wikka.php ... gerRunning
SARG
Posts: 1770
Joined: May 27, 2005 7:15
Location: FRANCE

Post by SARG »

Why not try Fbdebugger ;-)

There is a possibility to change some values on fly in case of crash.

http://www.freebasic.net/forum/viewtopic.php?t=13935
K128
Posts: 33
Joined: Jun 14, 2011 3:23
Location: Kathmandu, Nepal

Post by K128 »

Thanks @cha0s And @SARG for your reply.

I will surely try the debuggers too but I have a deep feeling that debugging wont help, because VMDetect makes an intentional memory access violation and Exception Handling is intentionally used to catch any exception that may occur if it is not a Virtual Machine. So, I think debugging wont help me much in this. Is there any method in FB to catch memory access violation error(s) and continue the program excution?

Thanks...
Mihail_B
Posts: 273
Joined: Jan 29, 2008 11:20
Location: Romania
Contact:

Post by Mihail_B »

K128 wrote:Thanks @cha0s And @SARG for your reply.

I will surely try the debuggers too but I have a deep feeling that debugging wont help, because VMDetect makes an intentional memory access violation and Exception Handling is intentionally used to catch any exception that may occur if it is not a Virtual Machine. So, I think debugging wont help me much in this. Is there any method in FB to catch memory access violation error(s) and continue the program excution?

Thanks...
IPC - inter process comunication - "modularize" your program(s) ...
(Make from one exe more exes each inter-commed with each other ...)

when one app crashes ... the main module is still alive and it can re-load that module ...

You can try to see how [airport/train/life support] control applications are made ...

(in dos you can hook a cwsdpmi error handler ... if you have enough knowledge of PM mode apps ... there's got to be a way too for win32 if you just want to catch the error)
Cherry
Posts: 358
Joined: Oct 23, 2007 12:06
Location: Austria
Contact:

Post by Cherry »

Please show me the code you used to catch the memory access violations with my try...catch implementation, because it simply can't crash this way, unless the exception handler gets messed up (which is unlikely).


You have to use it like this:

Code: Select all

#include "windows.bi"
#include "exceptions.bi"

Try(MyHandler) ' you can use *any* name instead of "MyHandler"
    ' put the code here which might crash
Catch(MyHandler, Else) ' "Else" will catch all exceptions. If you want to catch access violations only, use "EXCEPTION_ACCESS_VIOLATION" instead.
    ' if you want, put some code here which gets executed when the other code crashed, otherwise put no code here - but you still have to use a "Catch" block!
EndTry(MyHandler)
Post Reply