We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3048 - Crashes in Cocoa_SetWindowTitle
Summary: Crashes in Cocoa_SetWindowTitle
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.0
Hardware: x86 Mac OS X 10.8
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-04 20:52 UTC by David Ludwig
Modified: 2015-07-06 00:12 UTC (History)
1 user (show)

See Also:


Attachments
a sample program to reproduce SDL Bug 3048 (629 bytes, text/x-csrc)
2015-07-04 20:55 UTC, David Ludwig
Details
call-stack of crash (1.51 KB, text/plain)
2015-07-04 20:56 UTC, David Ludwig
Details
Here's a screenshot of Xcode showing where the crash occurs (731.45 KB, image/png)
2015-07-04 21:00 UTC, David Ludwig
Details
similar crash-inducing code (747 bytes, text/x-csrc)
2015-07-05 01:01 UTC, David Ludwig
Details
fix for forementioned crashes (947 bytes, patch)
2015-07-05 01:08 UTC, David Ludwig
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Ludwig 2015-07-04 20:52:42 UTC
When using SDL_CreateWindowAndRenderer on OS-X, in conjunction with either SDL_WINDOW_FULLSCREEN or SDL_WINDOW_FULLSCREEN_DESKTOP, SDL will crash.  This occurs in the latest hg.libsdl.org/SDL code as of this writing (Changeset 9795 / 63c4d6f1f85f).

Here is the call-stack of the crash:

2015-07-04 16:48:28.337 pongbat[5560:567443] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithUTF8String:]: NULL cString'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff9b21a03c __exceptionPreprocess + 172
	1   libobjc.A.dylib                     0x00007fff8b9c876e objc_exception_throw + 43
	2   CoreFoundation                      0x00007fff9b219eed +[NSException raise:format:] + 205
	3   Foundation                          0x00007fff930bccfb -[NSString initWithUTF8String:] + 78
	4   SDL2                                0x00000001000823dd Cocoa_SetWindowTitle + 125
	5   SDL2                                0x0000000100083301 Cocoa_SetWindowFullscreen + 1537
	6   SDL2                                0x00000001000ea0d1 SDL_UpdateFullscreenMode + 1025
	7   SDL2                                0x00000001000ec10b SDL_SetWindowFullscreen_REAL + 315
	8   SDL2                                0x00000001000e9c80 SDL_FinishWindowCreation + 160
	9   SDL2                                0x00000001000e955f SDL_CreateWindow_REAL + 1087
	10  SDL2                                0x00000001000ef300 SDL_CreateWindowAndRenderer_REAL + 64
	11  SDL2                                0x0000000100130751 SDL_CreateWindowAndRenderer + 65
	12  pongbat                             0x0000000100000b38 main + 120
	13  pongbat                             0x0000000100000ab4 start + 52
)
libc++abi.dylib: terminating with uncaught exception of type NSException


A sample program is forthcoming.
Comment 1 David Ludwig 2015-07-04 20:55:22 UTC
Created attachment 2212 [details]
a sample program to reproduce SDL Bug 3048
Comment 2 David Ludwig 2015-07-04 20:56:27 UTC
Created attachment 2213 [details]
call-stack of crash
Comment 3 David Ludwig 2015-07-04 21:00:43 UTC
Created attachment 2214 [details]
Here's a screenshot of Xcode showing where the crash occurs

The crash appears to occur because the window's title is unset, and Cocoa_SetWindowTitle makes an attempt to create an NSString from the NULL, 'window->title'.
Comment 4 David Ludwig 2015-07-05 01:01:13 UTC
Created attachment 2215 [details]
similar crash-inducing code

I noticed that a similar set of code can cause crashes on OS X, this time using a windowed-mode SDL_Window.  Attached is a sample program, that will crash on OS X (in SDL HG, same changeset as before).
Comment 5 David Ludwig 2015-07-05 01:08:58 UTC
Created attachment 2216 [details]
fix for forementioned crashes

Here is a Mercurial-generated patch to address the fore-mentioned crashes (in Cocoa_SetWindowTitle).

If this patch looks okay to you all, I'd be happy to push it out to hg.libsdl.org/SDL, if it'd help.
Comment 6 Sam Lantinga 2015-07-05 22:43:18 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/e0db4fedf80c
Comment 7 Sam Lantinga 2015-07-05 22:46:14 UTC
Actually I added a more general fix here:
https://hg.libsdl.org/SDL/rev/c142db5785ad
Comment 8 David Ludwig 2015-07-06 00:12:00 UTC
Cool.  :-)  I wasn't sure if a fix like that was kosher or not; a few other backends' SetWindowTitle implementations access window->title directly.  On a secondary inspection of them, I don't see any other sources for window->title crashes.  The OSX/Cocoa video backend appears to be the only one that accesses its SetWindowTitle implementation (Cocoa_SetWindowTitle) directly.  All others appear to only be called via SDL_SetWindowTitle and SDL_RecreateWindow, which do their own NULL checks.