diff options
author | Sam Lantinga <slouken@libsdl.org> | 2021-02-01 08:55:48 -0800 |
---|---|---|
committer | Sam Lantinga <slouken@libsdl.org> | 2021-02-01 08:55:48 -0800 |
commit | 2703e0a1d27e174bfb8a8313a2b747809a30dd8e (patch) | |
tree | c8dca076bc2c5d53b6353455642346dd57b5052d | |
parent | dd7e0cae7fdb86f52dfcc6275181798369757433 (diff) | |
download | sdl-2703e0a1d27e174bfb8a8313a2b747809a30dd8e.tar.gz |
Fixed bug 5524 - Pass NSString to NSLog()
Hiroyuki Iwatsuki
If you pass the C string directly to NSLog(), it will be garbled with Japanese and probably other language strings, or no log will be output at all.
NSLog("Hello, World!"); // => "Hello, World!"
NSLog("こんにちは、世界!"); // => No output...
Therefore, you need to convert the string to an NSString before passing it to NSLog().
NSString *str = [NSString stringWithUTF8String:"こんにちは、世界!"];
NSLog(@"%@", str); // => "こんにちは、世界!"
Thank you.
-rw-r--r-- | src/video/cocoa/SDL_cocoavideo.m | 5 | ||||
-rw-r--r-- | src/video/uikit/SDL_uikitvideo.m | 5 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m index 41ed703b1..55c6026cf 100644 --- a/src/video/cocoa/SDL_cocoavideo.m +++ b/src/video/cocoa/SDL_cocoavideo.m @@ -260,7 +260,10 @@ Cocoa_CreateImage(SDL_Surface * surface) void SDL_NSLog(const char *text) { - NSLog(@"%s", text); + @autoreleasepool { + NSString *str = [NSString stringWithUTF8String:text]; + NSLog(@"%@", str); + } } #endif /* SDL_VIDEO_DRIVER_COCOA */ diff --git a/src/video/uikit/SDL_uikitvideo.m b/src/video/uikit/SDL_uikitvideo.m index e32443cb5..f302e6494 100644 --- a/src/video/uikit/SDL_uikitvideo.m +++ b/src/video/uikit/SDL_uikitvideo.m @@ -279,7 +279,10 @@ UIKit_ForceUpdateHomeIndicator() #if !defined(SDL_VIDEO_DRIVER_COCOA) void SDL_NSLog(const char *text) { - NSLog(@"%s", text); + @autoreleasepool { + NSString *str = [NSString stringWithUTF8String:text]; + NSLog(@"%@", str); + } } #endif /* SDL_VIDEO_DRIVER_COCOA */ |