[2.2] Bug centering window in OgreWin32Window.cpp

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
m00ggi
Gnoblar
Posts: 12
Joined: Wed Feb 12, 2020 3:16 pm

[2.2] Bug centering window in OgreWin32Window.cpp

Post by m00ggi »

Hey there,
I had trouble finding a strange bug which caused the renderwindow to increase in size by 1 pixel each dimension. I was surprised because everything worked well in 2.1. So I debugged many files and noticed changes in OgreWin32Window.cpp. To be precise in Win32Window::create lines 355-359.
If one doesn't use the miscParams "externalWindowHandle", "left" and "top" (for centering) and step further inside the if( !mIsExternal ) branch, there is some code to center the window.
In 2.1 the code was

Code: Select all

            // No specified top left -> Center the window in the middle of the monitor
            if (left == -1 || top == -1)
            {               
                int screenw = monitorInfoEx.rcWork.right  - monitorInfoEx.rcWork.left;
                int screenh = monitorInfoEx.rcWork.bottom - monitorInfoEx.rcWork.top;

                unsigned int winWidth, winHeight;
                adjustWindow(width, height, &winWidth, &winHeight);

                // clamp window dimensions to screen size
                int outerw = ((int)winWidth < screenw) ? (int)winWidth : screenw;
                int outerh = ((int)winHeight < screenh) ? (int)winHeight : screenh;

                if (left == -1)
                    left = monitorInfoEx.rcWork.left + (screenw - outerw) / 2;
                else if (monitorIndex != -1)
                    left += monitorInfoEx.rcWork.left;

                if (top == -1)
                    top = monitorInfoEx.rcWork.top + (screenh - outerh) / 2;
                else if (monitorIndex != -1)
                    top += monitorInfoEx.rcWork.top;
But in 2.2.4 the code is

Code: Select all

		//Center window horizontally and/or vertically, on the right monitor.					
                uint32 screenw = monitorInfoEx.rcWork.right  - monitorInfoEx.rcWork.left;
                uint32 screenh = monitorInfoEx.rcWork.bottom - monitorInfoEx.rcWork.top;
												 
                uint32 outerw = (winWidth < screenw) ? winWidth : screenw;
                uint32 outerh = (winHeight < screenh) ? winHeight : screenh;

                if( left == INT_MAX ) <<<<<<<
                    left = monitorInfoEx.rcWork.left + (screenw - outerw) / 2;
                else if( monitorIndex != -1 )
                    left += monitorInfoEx.rcWork.left;

                if( top == INT_MAX ) <<<<<<<
                    top = monitorInfoEx.rcWork.top + (screenh - outerh) / 2;
                else if( monitorIndex != -1 )
                    top += monitorInfoEx.rcWork.top;
In my opinion INT_MAX is wrong here, because in line 149 it says

Code: Select all

int left = -1; // Defaults to screen center
int top = -1; // Defaults to screen center
Best regards,
m00ggi
Post Reply