all the gui turns white I'd say that's rather a sign of leaking of display context handles
See this code, each BeginPaint must be closed with EndPaint:
switch (uMsg)
{
...
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
}
If between BeginPaint and EndPaint some exception occurs, the EndPaint might be skipped.
Also each GetDC/GetWindowDC call must be closed with ReleaseDC. If you use MFC all of that is handled automatically. You can implement your own scope guards, a class that calls EndPaint in the constructor.
Using SEH frames is also an option, it part of WinAPI and works for both, C and C++, see more info here:
Structured Exception Handling (C/C++) | Microsoft Docs[
^]