[fixed]Ver 1.5 64bit setWindowCaption() bug

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
playerdark
Posts: 64
Joined: Mon Aug 01, 2005 5:06 am

[fixed]Ver 1.5 64bit setWindowCaption() bug

Post by playerdark »

The above function should be looking something like this:

Code: Select all

void CIrrDeviceWin32::setWindowCaption(const wchar_t* text)
{
	DWORD *dwResult;
	if (IsNonNTWindows)
	{
		const core::stringc s = text;
		SendMessageTimeout(HWnd, WM_SETTEXT, 0,
				reinterpret_cast<LPARAM>(s.c_str()),
				SMTO_ABORTIFHUNG, 2000, (PDWORD_PTR) &dwResult);
	}
	else
		SendMessageTimeoutW(HWnd, WM_SETTEXT, 0,
				reinterpret_cast<LPARAM>(text),
				SMTO_ABORTIFHUNG, 2000, (PDWORD_PTR) &dwResult);
}
The last parameter in this function is a pointer to a pointer. Although the return value is never used, the original version of this function causes a crash in 64bit due to the different pointerlength, while the bug does not cause a crash on 32 bit because DWORD and pointer are of the same size
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

The last parameter in this function is a pointer to a pointer.
Actually, it is not. DWORD_PTR is an integral type that is the same size as a pointer (i.e. 32-bit on 32-bit hardware and 64-bit on 64-bit hardware). It is NOT a pointer type.

The function takes a PDWORD_PTR, so the parameter passed should be the address of a DWORD_PTR...

Code: Select all

void CIrrDeviceWin32::setWindowCaption(const wchar_t* text) 
{ 
   DWORD_PTR dwResult; 
   if (IsNonNTWindows) 
   { 
      const core::stringc s = text; 
      SendMessageTimeout(HWnd, WM_SETTEXT, 0, 
            reinterpret_cast<LPARAM>(s.c_str()), 
            SMTO_ABORTIFHUNG, 2000, &dwResult); 
   } 
   else 
      SendMessageTimeoutW(HWnd, WM_SETTEXT, 0, 
            reinterpret_cast<LPARAM>(text), 
            SMTO_ABORTIFHUNG, 2000, &dwResult); 
} 
Your suggested fix passes a pointer to a pointer to a DWORD which is different than the expected parameter type. That is why you had to apply the cast to eliminate the compiler warning.

Travis
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

It looks as though this issue has already been addressed, in a slightly different way, on trunk...
playerdark
Posts: 64
Joined: Mon Aug 01, 2005 5:06 am

Post by playerdark »

Well, the original version that came with V1.5 did not compile under 64 bit which is why I changed it in the first place.
Post Reply