access violation in WM_PAINT not caught

前端 未结 6 804
伪装坚强ぢ
伪装坚强ぢ 2020-12-17 01:30

To test this problem I have written a minimal windows application. If I force an access violation in the WM_PAINT handler this exception never gets to the debug

相关标签:
6条回答
  • 2020-12-17 01:51

    DispatchMessage seems to now contain a SEH try catch block that inhibits exceptions generated by window procs.

    You can still catch these exceptions in the debugger - depending on your visual studio version you need to open the debug->exceptions dialog and tick the "Break when an exception is thrown" column for all Win32 exceptions, or at least exception 0xc0000005

    0 讨论(0)
  • 2020-12-17 02:04

    I've noticed that, when you have Aero enabled (which is by default in Vista), resizing windows tends to create many, many page faults. These aren't normal virtual memory-needs-to-be-paged-in faults, either. I suspect (though it's just a theory), that Aero redirects the graphics output to a protected chunk of memory, and catches the faults in order to know which bits of the visible surface need to be recomposited on the desktop. Perhaps that is eating other access violations as well.

    0 讨论(0)
  • 2020-12-17 02:07

    As a workaround I remove all registered exception handlers in my window procedure. Quite ugly.

    LRESULT CALLBACK window_proc( 
        HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
    {
        // get thread information block
        NT_TIB* tib;
        __asm {
            mov EAX, FS:[18h]
            mov [tib], EAX
        }
        // old exception handler list
        _EXCEPTION_REGISTRATION_RECORD* old_exception_handler = tib->ExceptionList;
        // remove all exception handler with exception of the default handler
        while( tib->ExceptionList->Next != (_EXCEPTION_REGISTRATION_RECORD*)-1 ) {
            tib->ExceptionList = tib->ExceptionList->Next;
        }
    
        LRESULT result = DefWindowProc( hwnd, uMsg, wParam, lParam );
    
        // restore old exception handler
        tib->ExceptionList = old_exception_handler;
    
        return result;
    }
    
    0 讨论(0)
  • 2020-12-17 02:07

    Starting from XP, the Vector Exception Handling functionality can be used. It has priority over all other kinds of exceptions. In my example, it correctly caught the Access Violation in the WM_PAINT message. Unfortunately, it also catches all other kinds of exceptions, which I should probably solve by checking for the exception code.

    0 讨论(0)
  • 2020-12-17 02:09

    Exception will be thrown in WinXP and in Vista. I've just tested this in Vista in Debug and Release configurations. Do you have the same issue in new Win32 Application project?

    0 讨论(0)
  • 2020-12-17 02:16

    It's a known defect. Check the hotfix. http://support.microsoft.com/kb/976038

    0 讨论(0)
提交回复
热议问题