From 08a2846a93e9254270f49a06869679b47724cddf Mon Sep 17 00:00:00 2001 From: cutealien Date: Sun, 21 Feb 2021 19:09:14 +0000 Subject: [PATCH] Merging r6194 from trunk to ogl-es branch. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@6195 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CIrrDeviceOSX.mm | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/source/Irrlicht/CIrrDeviceOSX.mm b/source/Irrlicht/CIrrDeviceOSX.mm index c709adb5..0be15bb3 100644 --- a/source/Irrlicht/CIrrDeviceOSX.mm +++ b/source/Irrlicht/CIrrDeviceOSX.mm @@ -1067,20 +1067,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); - title[1023] = 0; -#ifdef __MAC_10_6 - NSString* name = [NSString stringWithCString:title encoding:NSUTF8StringEncoding]; + if ( text ) + { + size_t numBytes = wcslen(text) * sizeof(wchar_t); + +#ifdef __BIG_ENDIAN__ + NSStringEncoding encode = sizeof(wchar_t) == 4 ? NSUTF32BigEndianStringEncoding : NSUTF16BigEndianStringEncoding; #else - NSString* name = [NSString stringWithCString:title length:size]; + NSStringEncoding encode = sizeof(wchar_t) == 4 ? NSUTF32LittleEndianStringEncoding : NSUTF16LittleEndianStringEncoding; #endif - [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:@""]; + } } }