Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed segfault on close, request timer on macOS standalone #295

Merged
merged 2 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading