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

时间:2013-02-11 11:17:11

标签: c++ winapi

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

  1. 进程停留在内存中,必须手动终止
  2. 游戏崩溃
  3. 我不确定这两者是否相关或完全独立。这两种情况很少发生,但我必须消除这些情况。

    至于崩溃,我做了一个转储,并说它发生在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__ * formal = 0x00400000,HINSTANCE * formal = 0x00400000,HINSTANCE * formal = 0x00400000,HINSTANCE * 形式= 0x00400000)第61行C ++       SchoolBus.exe!__ tmainCRTStartup()第578行+ 0x1c字节C.       kernel32.dll!@ BaseThreadInitThunk @ 12()+ 0x12 bytes
          ntdll.dll!
    RtlUserThreadStart @ 8()+ 0x27字节
          ntdll.dll!
    _RtlUserThreadStart @ 8()+ 0x1b bytes

0 个答案:

没有答案