diff --git a/source/Irrlicht/CIrrDeviceOSX.mm b/source/Irrlicht/CIrrDeviceOSX.mm index 7b20b906..a88ee1e9 100644 --- a/source/Irrlicht/CIrrDeviceOSX.mm +++ b/source/Irrlicht/CIrrDeviceOSX.mm @@ -1109,28 +1109,28 @@ void CIrrDeviceMacOSX::sleep(u32 timeMs, bool pauseTimer=false) void CIrrDeviceMacOSX::setWindowCaption(const wchar_t* text) { - size_t size; -// char title[1024]; - if (Window != NULL) { -// size = wcstombs(title,text,1024); - size = wcslen(text) * sizeof(wchar_t); -// title[1023] = 0; -//#ifdef __MAC_10_6 -// NSString* name = [NSString stringWithCString:title encoding:NSUTF8StringEncoding]; -//#else -// NSString* name = [NSString stringWithCString:title length:size]; -//#endif + if ( text ) + { + size_t numBytes = wcslen(text) * sizeof(wchar_t); #ifdef __BIG_ENDIAN__ - NSStringEncoding encode = NSUTF32BigEndianStringEncoding; + NSStringEncoding encode = sizeof(wchar_t) == 4 ? NSUTF32BigEndianStringEncoding : NSUTF16BigEndianStringEncoding; #else - NSStringEncoding encode = NSUTF32LittleEndianStringEncoding; + NSStringEncoding encode = sizeof(wchar_t) == 4 ? NSUTF32LittleEndianStringEncoding : NSUTF16LittleEndianStringEncoding; #endif - NSString* name = [[NSString alloc] initWithBytes:text length:size encoding:encode]; - [Window setTitle:name]; - [name release]; + NSString* name = [[NSString alloc] initWithBytes:text length:numBytes encoding:encode]; + if ( name ) + { + [Window setTitle:name]; + [name release]; + } + } + else + { + [Window setTitle:@""]; + } } }