Skip to content

Instantly share code, notes, and snippets.

@cbaggers
Created April 19, 2018 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbaggers/f288572411e77d102d1527f96b7f298e to your computer and use it in GitHub Desktop.
Save cbaggers/f288572411e77d102d1527f96b7f298e to your computer and use it in GitHub Desktop.
#include <ApplicationServices/ApplicationServices.h>
#include <Cocoa/Cocoa.h>
@interface BlortAppDelegate : NSObject <NSApplicationDelegate>
@end
@implementation BlortAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSLog(@"applicationDidFinishLaunching");
[NSApp activateIgnoringOtherApps:YES];
}
@end
static BlortAppDelegate* appDelegate = nil;
static NSWindow* ourWindow = nil;
extern void Cocoa_Init(void)
{ @autoreleasepool
{
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
NSLog(@"\nFOIRST TROII!");
[NSApp setDelegate:[[BlortAppDelegate alloc] init]];
id menubar = [[NSMenu new] autorelease];
id appMenuItem = [[NSMenuItem alloc]initWithTitle:@"hoo" action:nil keyEquivalent:@""];
[menubar addItem:appMenuItem];
NSSize size = NSSizeFromString(@"64x64");
NSImage *image = [[[NSImage alloc] initWithSize:size] autorelease];
[image lockFocus];
[NSColor.blueColor drawSwatchInRect:NSMakeRect(0, 0, size.width, size.height)];
[image unlockFocus];
[NSApp setApplicationIconImage:image];
[NSApp setMainMenu:menubar];
NSRect frame = NSMakeRect(0, 0, 200, 200);
NSWindow* window = [[[NSWindow alloc] initWithContentRect:frame
styleMask:NSWindowStyleMaskBorderless
backing:NSBackingStoreBuffered
defer:NO] autorelease];
[window setBackgroundColor:[NSColor blueColor]];
[window makeKeyAndOrderFront:NSApp];
ourWindow = window;
[NSApp finishLaunching];
}
}
extern void Cocoa_PumpEvents(void)
{ @autoreleasepool
{
NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
}
}
@gavocanov
Copy link

Did u try stepping with the debugger to the same point in which we are getting the crash when used from SBCL?
Maybe we could figure-out what should be the resource (image) that is a null pointer in SBCL, some resource that a cocoa app initialised with setActivationPolicy:NSApplicationActivationPolicyRegular should have but SBCL does not?

I'v been using the same SDL lib on my system from different places, Kotlin Native (also FFI), C, C++ etc. these days, all works fine except SBCL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment