Why do you need an event loop in order for the window to show up?

The Cocoa (and CoreFoundation) frameworks are designed with the concept of “runloops”. These runloops are how all notifications, UI events, timers, etc are serviced. If the runloop doesnt get ran then none of these “runloop sources” will fire. One of these sources is the mach port connecting to the windowserver, so if it doesnt get serviced, no window gets created.

SDL runs the runloop when you poll events by calling Cocoa_PumpEventsUntilDate which calls NSApp nextEventMatchingMask:NSEventMaskAny untilDate:expiration inMode:NSDefaultRunLoopMode dequeue:YES.

if you want you can always run the runloop yourself. If you are using Coca you can use run method of NSApplication on the main thread. You can also get more fine grain control by directly using NSRunloop. You can use CoreFoundation if you want to avoid Objective-C, it has a corresponding CFRunLoop

consider that if you have no event loop then the application GUI will be completely unresponsive (eg menus, dock icon, etc). The entire Cocoa UI is driven by the runloop, to make an application do what you want without a runloop you would have to avoid Cocoa and SDL uses Cocoa.

1 Like