Skip to content

Commit

Permalink
fixed segfault on close, request timer on macOS standalone (#295)
Browse files Browse the repository at this point in the history
* fixed segfault on close, request timer on macOS standalone

* removed cleanup (NSWindow auto frees)

---------

Co-authored-by: MeijisIrlnd <[email protected]>
  • Loading branch information
MeijisIrlnd and MeijisIrlnd authored Aug 18, 2024
1 parent d066aab commit 4b1972d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/detail/standalone/macos/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
{
// AudioSettingsWindowDelegate *audioSettingsWindowDelegate;
}
@property(assign) IBOutlet NSWindow *window;

@property(assign) NSTimer* requestCallbackTimer;
@property(assign) IBOutlet NSWindow* window;

- (IBAction)openAudioSettingsWindow:(id)sender;

Expand Down
23 changes: 20 additions & 3 deletions src/detail/standalone/macos/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ - (void)resetSampleRateSelection;

@implementation AppDelegate

- (void)timerCallback:(NSTimer *)instance
{
auto *standaloneHost = freeaudio::clap_wrapper::standalone::getStandaloneHost();
if (standaloneHost->callbackRequested.exchange(false))
{
auto *plugin = freeaudio::clap_wrapper::standalone::getMainPlugin()->_plugin;
plugin->on_main_thread(plugin);
}
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
Expand Down Expand Up @@ -61,7 +71,13 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
return;
}

self.requestCallbackTimer = [NSTimer timerWithTimeInterval:0.08
target:self
selector:@selector(timerCallback:)
userInfo:nil
repeats:YES];
auto *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:self.requestCallbackTimer forMode:NSDefaultRunLoopMode];
std::string pid{PLUGIN_ID};
int pindex{PLUGIN_INDEX};

Expand Down Expand Up @@ -142,6 +158,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
[alert runModal];
}
};

freeaudio::clap_wrapper::standalone::mainStartAudio();
}

Expand All @@ -164,8 +181,8 @@ - (void)applicationWillTerminate:(NSNotification *)aNotification
plugin->_ext._gui->destroy(plugin->_plugin);
}

[[self window] setDelegate:nil];
[[self window] release];
[self.requestCallbackTimer invalidate];
self.requestCallbackTimer = nil;

freeaudio::clap_wrapper::standalone::mainFinish();
}
Expand Down

0 comments on commit 4b1972d

Please sign in to comment.