2

我的问题是,有时在关闭游戏时,可能会出现以下两种情况之一:

  1. 进程留在内存中,必须手动终止
  2. 游戏崩溃

我不确定这两个是相关的还是完全独立的问题。这两种情况都很少发生,但我必须消除这些情况。

至于崩溃,我做了一个转储,它说崩溃发生在 PeekMessage() 函数中。代码如下所示:

bool running = true;

/// Reset timer
Timer.Reset();

MSG msg;
ZeroMemory(&msg, sizeof(msg));

/// message pump
while(running)
{
    int msg_count = 10;
    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) && msg_count-->0)
    {
        ::TranslateMessage(&msg);
        ::DispatchMessage(&msg);

        if (msg.message == WM_QUIT)
        {
            running = false;
            break;
        }
    }

    if (ApplicationActive)
    {
        PrepareFrame();
        RenderFrame();
    }
    else
        Sleep(1);

    Sleep(1);
}

据我所知,消息处理例程每次循环迭代最多处理 10 条消息。崩溃是否可能是消息队列溢出的结果?留在内存中的进程是“未到达”退出消息的结果,因为它在队列中太远了?如果有帮助,这里是转储的调用堆栈:

ntdll.dll!_KiFastSystemCallRet@0()  
ntdll.dll!_ZwWaitForSingleObject@12()  + 0xc bytes  
ntdll.dll!_RtlpWaitOnCriticalSection@8()  + 0xc8 bytes  
ntdll.dll!_RtlEnterCriticalSection@4()  - 0x4b84 bytes  
ntdll.dll!_LdrLockLoaderLock@12()  + 0x6b bytes 
ntdll.dll!_LdrLoadDll@16()  + 0xd8 bytes    
kernel32.dll!_LoadLibraryExW@12()  + 0xf7 bytes 
user32.dll!___ClientLoadLibrary@4()  + 0x60 bytes   
ntdll.dll!_KiUserCallbackDispatcher@12()  + 0x2e bytes  
user32.dll!_NtUserPeekMessage@20()  + 0xc bytes 
user32.dll!__PeekMessage@24()  + 0x2d bytes 
user32.dll!_PeekMessageA@20()  + 0x572 bytes    

SchoolBus.exe!VCasualApp::Run() 第 229 行 + 0x12 字节 C++ SchoolBus.exe!wWinMain(HINSTANCE__ * form =0x00400000, HINSTANCE * form =0x00400000, HINSTANCE * form =0x00400000, HINSTANCE * form=0x00400000) 第 61 行 C++ SchoolBus .exe!__tmainCRTStartup() 第 578 行 + 0x1c 字节 C kernel32.dll!@BaseThreadInitThunk@12() + 0x12 字节
ntdll.dll!
RtlUserThreadStart@8() + 0x27 字节
ntdll.dll!
_RtlUserThreadStart@8() + 0x1b 字节

4

0 回答 0