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

Do not dispose the client on drop to avoid the CoreMIDI server to shutdown in iOS #53

Merged
merged 1 commit into from
Jun 30, 2024
Merged
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
19 changes: 13 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::cell::RefCell;
use std::{mem::MaybeUninit, ops::Deref, os::raw::c_void, ptr};

use coremidi_sys::{
MIDIClientCreate, MIDIClientCreateWithBlock, MIDIClientDispose, MIDIDestinationCreateWithBlock,
MIDIClientCreate, MIDIClientCreateWithBlock, MIDIDestinationCreateWithBlock,
MIDIDestinationCreateWithProtocol, MIDIEventList, MIDIInputPortCreateWithBlock,
MIDIInputPortCreateWithProtocol, MIDINotification, MIDINotifyBlock, MIDIOutputPortCreate,
MIDIPacketList, MIDIReadBlock, MIDIReceiveBlock, MIDISourceCreate,
Expand Down Expand Up @@ -330,8 +330,15 @@ impl Deref for Client {
}
}

impl Drop for Client {
fn drop(&mut self) {
unsafe { MIDIClientDispose(self.object.0) };
}
}
// According to Apple docs:
//
// > Don’t explicitly dispose of your client; the system automatically disposes all clients when an app terminates.
// > However, if you call this method to dispose the last or only client owned by an app, the MIDI server may exit
// > if there are no other clients remaining in the system. If this occurs, all subsequent calls by your app to
// > MIDIClientCreate and MIDIClientCreateWithBlock fail.
//
// impl Drop for Client {
// fn drop(&mut self) {
// unsafe { MIDIClientDispose(self.object.0) };
// }
// }
Loading