WebMIDIKit icon indicating copy to clipboard operation
WebMIDIKit copied to clipboard

Removing a Midi Device produces a crash

Open raduvarga opened this issue 3 years ago • 8 comments

The problem is here:

Assertion failed: file WebMIDIKit/MIDIPortMap.swift, line 72

The code:

assert(port.state == .connected)

Is this assertion necessary?

raduvarga avatar Dec 27 '20 13:12 raduvarga

what code causes this crash?

adamnemecek avatar Jan 04 '21 18:01 adamnemecek

Just physically removing a controller, no code of my own. I ended up just commenting that line. BTW, there were a few other lines that had to be fixed, the code did not compile at the beginning. Should I make a PR with those changes?

raduvarga avatar Jan 06 '21 20:01 raduvarga

Oh yeah that makes sense actually. Yeah start a PR. Yeah the repo hasn’t been updated in some time.

adamnemecek avatar Jan 06 '21 21:01 adamnemecek

Just found another crashing line, in Enum.swift line 32:

fatalError("You didn't initialize a virtual port")

This happens when closing a Virtual midi port. I've added a fix for the crash to the current PR. I'm however not sure how to recognize the Virtual ports as input and output. When they connect, they recognize fine, only when disconnecting the type is returned as other.

raduvarga avatar Jan 26 '21 18:01 raduvarga

I think that there isn’t support for virtual ports right now.

adamnemecek avatar Jan 27 '21 02:01 adamnemecek

Understood, but crashing the whole app when disconnecting a midi port is still not desired.

The Virtual ports actually do work (they show as Input and Output when connected), it's just hard to recognize when they disconnect, which is actually not that bad. I will try to see if I can figure this out.

raduvarga avatar Jan 27 '21 12:01 raduvarga

It’s an implementation of the webmidi standard. You might be right, I should be caching the values. Do you want to do a pr?

adamnemecek avatar Jun 01 '22 17:06 adamnemecek

Pull request.

adamnemecek avatar Jun 01 '22 17:06 adamnemecek