关闭或进程停留在内存时,游戏有时会崩溃

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

  • 进程保留在内存中,并且必须手动终止
  • 游戏崩溃
  • 我不确定这两者是相关还是完全独立的问题。 这两种情况都很少发生,但我必须消除这些情况。

    至于这次崩溃,我做了一个转储,它表示崩溃发生在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条消息。 崩溃是否可能是消息队列溢出的结果? 而进入内存的进程是“未到达”退出消息的结果,因为它在队列中太远了? 如果有帮助,以下是来自dump的调用堆栈:

    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()Line 229 + 0x12 bytes C ++ SchoolBus.exe!wWinMain(HINSTANCE__ * formal = 0x00400000,HINSTANCE * formal = 0x00400000,HINSTANCE * formal = 0x00400000,HINSTANCE * formal = 0x00400000)Line 61 C ++ SchoolBus .exe!__ tmainCRTStartup()第578行+ 0x1c字节C kernel32.dll!@ BaseThreadInitThunk @ 12()+ 0x12字节
    ntdll.dll中! RtlUserThreadStart @ 8()+ 0x27字节
    ntdll.dll!_RtlUserThreadStart@8()+ 0x1b字节

    链接地址: http://www.djcxy.com/p/95501.html

    上一篇: Game sometimes crashes when closing or process stay in memory

    下一篇: .NET Activex control access violation in MFC application