Running Ogre3D v.1.8RC and MyGUI v3.2.0 on 64 bits (BUG fix)

kekar

01-05-2012 14:50:09

Hi,

I'm currently working on a project that is being developed for the 64 bits architecture (Windows 7 currently).

I've managed to compile all the dependencies for Ogre and MyGUI, but I struggled with crashes in the MyGUI API. I traced it down, and found that the currently Windows Input manager is calling unsafe 32bits calls like these;

SetWindowLong(mHwnd, GWL_WNDPROC, (long)windowProc);

In the MSDN documentation, there are actually better system calls to use, that are much more architecture-safe.

E.g:

Note To write code that is compatible with both 32-bit and 64-bit Windows, use SetClassLongPtr. When compiling for 32-bit Windows, SetClassLongPtr is defined as a call to the SetClassLong function

I've made a small patch, replacing these and similar calls, and everything runs stable and fine.

diff -ru ../orig/MyGUI_3.2.0/Common/Input/Win32/InputManager.cpp ./Common/Input/Win32/InputManager.cpp
--- ../orig/MyGUI_3.2.0/Common/Input/Win32/InputManager.cpp 2012-02-29 00:46:16.000000000 +0100
+++ ./Common/Input/Win32/InputManager.cpp 2012-05-01 15:01:30.728479900 +0200
@@ -228,8 +228,8 @@
// подсовываем нашу функцию калбеков
if (!msOldWindowProc)
{
- msOldWindowProc = GetWindowLong(mHwnd, GWL_WNDPROC);
- SetWindowLong(mHwnd, GWL_WNDPROC, (long)windowProc);
+ msOldWindowProc = GetWindowLongPtr(mHwnd, GWLP_WNDPROC);
+ SetWindowLongPtr(mHwnd, GWLP_WNDPROC, (LONG_PTR)windowProc);
}

// устанавливаем поддержку дропа файлов
@@ -246,7 +246,7 @@
// если мы подменили процедуру, то вернем на место
if (msOldWindowProc)
{
- SetWindowLong((HWND)mHwnd, GWL_WNDPROC, (long)msOldWindowProc);
+ SetWindowLongPtr((HWND)mHwnd, GWLP_WNDPROC, (LONG_PTR)msOldWindowProc);
msOldWindowProc = 0;
}
}
diff -ru ../orig/MyGUI_3.2.0/Common/Input/Win32/PointerManager.cpp ./Common/Input/Win32/PointerManager.cpp
--- ../orig/MyGUI_3.2.0/Common/Input/Win32/PointerManager.cpp 2012-02-22 21:28:12.000000000 +0100
+++ ./Common/Input/Win32/PointerManager.cpp 2012-05-01 15:01:28.812370300 +0200
@@ -58,7 +58,8 @@

void PointerManager::setPointerHandle(size_t _id)
{
- SetClassLong((HWND)mHwnd, GCL_HCURSOR, (LONG)_id);
+ SetClassLongPtr((HWND)mHwnd, GCLP_HCURSOR, (LONG_PTR)_id);
+
if ((GetCapture() == (HWND)mHwnd)
|| isMouseInClient())
{


Please note, I haven't tested a 32 bit build yet, but I assume this will work on both systems. If anyone that already have a 32 bit configuration ready, please let me know if there are any issues. I will check it myself later on.

I wasn't able to attach the package file in this post (quota reached or something), but the RAR-file with the two patched files in Common\Input\Win32 (InputManager.cpp and PointerManager.cpp) can be downloaded from here;

http://www.rosodev.com/projects/mygui/M ... patch2.rar

I hope this will be adopted/fixed in the future releases of MyGUI :)

kekar

11-06-2012 13:47:34

Works fine with the Ogre v1.8.0 release too :)