[Fix] Freeze when moving window

08/25/2015 21:46 Ahoru#1
Hi !

As many have noticed when we move Neuz window the game freeze, ie game loop isn't running.
This can cause several problems with network, calculation of monsters positions, etc ...

Here is a short homemade tutorial to correct this ;)

File: _DirectX\d3dapp.h

After lines:
Code:
class CD3DApplication
{
Add:
Code:
private:
    bool m_movingOrSizingWindow;
It's a simple variable to indicate when user is moving the window.

File: _DirectX\d3dapp.cpp

After lines:
Code:
CD3DApplication::CD3DApplication()
{
Add:
Code:
m_movingOrSizingWindow = false;
To initialize our variable.

Then in function LRESULT CD3DApplication::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) replace lines:
Code:
     case WM_ENTERSIZEMOVE:
            // Halt frame movement while the app is sizing or moving
            Pause( true );
            break;
By:
Code:
    case WM_ENTERSIZEMOVE:
        // Halt frame movement while the app is sizing or moving
        //Pause(true);
        SetTimer(hWnd, 1, USER_TIMER_MINIMUM, NULL);
        m_movingOrSizingWindow = true;
        break;
        
    case WM_TIMER:
        if (wParam == 1 && m_bActive)
        {
              if (FAILED(Render3DEnvironment()))
                  SendMessage(m_hWnd, WM_CLOSE, 0, 0);
        }
        break;
And lines:
Code:
       case WM_EXITSIZEMOVE:
            Pause( false );
            HandlePossibleSizeChange();
            break;
By:
Code:
case WM_EXITSIZEMOVE:
        //Pause(false);
        //HandlePossibleSizeChange(); // We can't resize Neuz window
        KillTimer(hWnd, 1);
        m_movingOrSizingWindow = false;
        break;
When user moves the window, the game loop isn't running but the function MsgProc is still called for WM_TIMER messages so we just have to use a timer to update the game.

To finish in function HRESULT CD3DApplication::Render3DEnvironment() replace line:
Code:
if( IsDrawTiming() )
By:
Code:
if (IsDrawTiming() || m_movingOrSizingWindow)
It seems IsDrawTiming doesn't work when the window is moving and I don't know why, so I added this and it works fine.

Edit: If you got an error with USER_TIMER_MINIMUM non identified, replace it by 0x0000000A :)

There you go ! ;)
08/25/2015 22:47 kevinkraus#2
...\Source\_DirectX\d3dapp.cpp(580): error C2065: 'USER_TIMER_MINIMUM' : undeclared identifier

Where i need to do this :O?

Ty for the Release :)!

yours truly,
- Kevin
08/25/2015 23:00 Ahoru#3
I think it depends of your WinUser version... Try to replace it by 0x0000000A :)
08/25/2015 23:47 kevinkraus#4
Thank you ^^ Worked.

yours truly,
- Kevin
08/26/2015 00:36 julioclitwin#5
@Ahoru
Thanks! This fix is very important.
08/26/2015 19:48 n5xda#6
Thanks Nice *-*
09/01/2015 16:17 aoyamananami#7
what this fix can do?
09/01/2015 17:33 - DK#8
Quote:
Originally Posted by aoyamananami View Post
what this fix can do?
When you move the neuz in window mode there can freez.. This was the fix for it.
09/02/2015 10:05 aoyamananami#9
Quote:
Originally Posted by .ACE. View Post
When you move the neuz in window mode there can freez.. This was the fix for it.
i see :) .. this would be help . tnx ;)
07/17/2021 15:52 2ez4kiks#10
there's no if( IsDrawTiming() ) in HRESULT CD3DApplication::Render3DEnvironment()? Where can i search for that for cpp. or h?