Reputation: 11
I have created a Windows application. It should be noted that this issue only occurs on certain computers (it runs fine on mine). I create the window as follows:
RECT wr = {0, 0, rOp->resX, rOp->resY};
AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hAppInst;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = L"App";
if (!RegisterClass(&wc))
{
return false;
}
hAppWnd = CreateWindow( L"App", lpWindowName, WS_VISIBLE | WS_OVERLAPPED, 0, 0, wr.right - wr.left, wr.bottom - wr.top, NULL, NULL, hAppInst, NULL );
On the PCs of two of my friends, this crashes when the window is displayed. If I remove WS_VISIBLE, the application continues to run fine until ShowWindow is called, upon which time it crashes. My friends report seeing a white window immediately before it crashes, so the window appears to be being displayed.
Does anyone have any theories as to why this might be happening?
EDIT: WndProc is as follows:
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
reng->draw();
return 0;
case WM_ERASEBKGND:
return 1;
default:
return reng->DefProc(hWnd, Msg, wParam, lParam);
}
}
DefProc is a function pointer to this:
LRESULT CALLBACK DefProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
case GM_NEWGAME:
newGame();
return 0;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
}
(GM_NEWGAME is a user-defined message)
The DefProc function pointer is always set before the window is created.
Upvotes: 1
Views: 826
Reputation: 2113
As the code you have posted here has nothing that can explicitly cause a crash, and as it only happens when the window is actually shown, it looks like the bug is inside the draw() method.
The best solution would be to build a debug version of your application and ask your friend to create a dump file with task manager when it crashes. They you can open it in Visual Studio and see the exact line in your code that caused the crash.
Upvotes: 1
Reputation: 93
The must be in your wndproc. Maybe there is a synchronization problem between an object creation and its use in there.
Upvotes: 1