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

Crashes immediately on MIDI event (or, what am I missing) #214

Closed
apaleslimghost opened this issue Nov 27, 2017 · 4 comments
Closed

Crashes immediately on MIDI event (or, what am I missing) #214

apaleslimghost opened this issue Nov 27, 2017 · 4 comments

Comments

@apaleslimghost
Copy link

I created an empty Swift project, and in AppDelegate.application(_:didFinishLaunchingWithOptions:) added _ = MIKMIDIConnectionManager(name: "test"). That's it. As soon as the first MIDI event comes in the app crashes with EXC_BAD_ACCESS. I did wonder if it was #213, but I can reproduce in 1.6.2 and master.

Since I've no idea what I'm doing here, what's the absolute minimum I need to set up to start receiving MIDI events? Do I need MIKMIDIConnectionManager? Should registering the delegate be enough?

Is there an example project (in Swift!) anywhere?

@armadsen
Copy link
Member

armadsen commented Nov 27, 2017

Do you mind zipping up your project and sending it to me (andrew@openreelsoftware.com)? What you've described should work. I don't have a MIDI device handy to test with the moment, but will later tonight.

@armadsen
Copy link
Member

armadsen commented Nov 28, 2017

I was able to reproduce this. The problem here is that the MIKMIDIConnectionManager you're creating is being deallocated nearly immediately because you're not storing a strong reference to it (you're not even putting it in a variable). This is exposing a bug in MIKMIDI that causes a crash. (I've opened issue #215 for this, and will push a fix shortly.)

However, you need a little more than that to actually receive events. Try this:

class AppDelegate: UIResponder, UIApplicationDelegate {

	var window: UIWindow?

	let connectionManager = MIKMIDIConnectionManager(name: "test")
	
	func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
		
		connectionManager.eventHandler = { (source, messages) in
			print("Received MIDI messages: \(messages)")
		}
		
		return true
	}
}

@armadsen
Copy link
Member

The crash you saw should be fixed in master, but you'll still need to make sure you keep a strong reference to the connection manager (e.g. using a property as in my example code above) in order to actually receive events.

@apaleslimghost
Copy link
Author

Αh, thanks. Weak references always catch me out 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants