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 2982 - SDL_CreateWindowFrom() crash with Qt widget under Mac OS
Summary: SDL_CreateWindowFrom() crash with Qt widget under Mac OS
Status: RESOLVED WONTFIX
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.0
Hardware: x86_64 Mac OS X (All)
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-12 09:41 UTC by François Colas
Modified: 2016-10-08 00:41 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description François Colas 2015-05-12 09:41:09 UTC
I am using libSDL2 in a Qt app. The code is working well under Linux and Windows but is failing under Mac OS. Here is the crash output:

2015-05-12 10:24:35.598 testapp[4621:105425] -[QNSView title]: unrecognized selector sent to instance 0x7fdfbac7b8e0
2015-05-12 10:24:35.643 testapp[4621:105425] An uncaught exception was raised
2015-05-12 10:24:35.643 testapp[4621:105425] -[QNSView title]: unrecognized selector sent to instance 0x7fdfbac7b8e0
2015-05-12 10:24:35.643 testapp[4621:105425] (
    0   CoreFoundation                      0x00007fff9332764c __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x00007fff967686de objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff9332a6bd -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x00007fff93271a84 ___forwarding___ + 1028
    4   CoreFoundation                      0x00007fff932715f8 _CF_forwarding_prep_0 + 120
    5   testapp                             0x000000010446af59 Cocoa_CreateWindowFrom + 73
    6   testapp                             0x000000010445fe1d SDL_CreateWindowFrom_REAL + 205
    7   testapp                             0x000000010417c83c main + 380
    8   testapp                             0x000000010417c6b4 start + 52
    9   ???                                 0x0000000000000001 0x0 + 1
)

That sample code reproduce the crash. Again it is working under Linux and Windows but not under Mac OS.

int main(int argc, char* argv[])
{
    QApplication app(argc, argv);

    if (SDL_VideoInit(NULL) != 0) {
        qCritical("SDL_VideoInit() error: %s", SDL_GetError());
        return EXIT_FAILURE;
    }

    QWidget*    qwidget   = new QWidget();
    SDL_Window* sdlWindow = SDL_CreateWindowFrom((void*) qwidget->winId());
    if (sdlWindow == NULL) {
        qCritical("SDL_CreateWindowFrom error: %s", SDL_GetError());
        return EXIT_FAILURE;
    }

    return app.exec();
}

According to Qt's documentation, QWidget::winId() return a pointer to a NSView. Looking at SDL's source code it seems that Cocoa_CreateWindowFrom() function takes a NSWindow.

Does it means that we can't embed a SDL widget in a app window? Do you think Cocoa_CreateWindowFrom() could be updated to take a NSView?
Comment 1 Sam Lantinga 2016-10-08 00:41:34 UTC
That's correct, although there may be some way to get an NSWindow from an NSView, I don't know.