Skip to content

Commit

Permalink
Do not dispose the client on drop to avoid the CoreMIDI server to shu…
Browse files Browse the repository at this point in the history
…tdown in iOS (#53)
  • Loading branch information
chris-zen authored Jun 30, 2024
1 parent e15673a commit 926e2cc
Showing 1 changed file with 13 additions and 6 deletions.
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) };
// }
// }

0 comments on commit 926e2cc

Please sign in to comment.