elf-audio / Koala-Bugs

Here is where you can report bugs in koala via the issues tab.
5 stars 0 forks source link

Android Koala crashes when a MIDI controller and a physical keyboard are connected #18

Open gstepniewski opened 1 year ago

gstepniewski commented 1 year ago

I've been working on creating a MIDI mapping for my Launchpad recently and have experienced a large amount of crashes. They seem to mostly occur when plugging/unplugging a controller, but happened also while assigning CCs to things and just playing around.

Is there a way for me to generate stacktraces/dumps/whatever to make it easier to debug? Or do they get logged somewhere automatically (like Firebase) anyway? I'm happy to try reproducing them if that helps debugging/fixing/testing.

mazbox commented 1 year ago

Hi Greg

Thanks for the bug report - what would be awesome is if you could give me (1) the make/model of phone + OS version, and (2) some steps to reproduce and an idea of how frequently its replicable with the reproducing steps.

I can't seem to reproduce this - I do get crash reports but they're not as useful as reproduction steps as a lot of the native (e.g. ndk) stack can get garbled, and its nice to be able to recreate exactly then problem in a test case so it doesn't happen again.

gstepniewski commented 1 year ago

I have been able to figure out full reproduction steps of the issue. My phone is Pixel 5 with Android 13 and I have two MIDI controllers that I'm using - Novation Launchpad X and Akai MPK Mini Mk3.

The MPK works perfectly when connected to the phone on its own, I can disconnect it or connect it multiple times and at any point while running the app. But when I connect the Launchpad X after having started Koala, the first time I hit a pad on the controller Koala instantly crashes with a segfault:

libc com.elf.koalasampler A Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x7500000000 in tid 19149 (Thread-42), pid 18963 (lf.koalasampler)

No other useful information is printed to LogCat. Note that despite what I wrote in the original description this has nothing to do with MIDI mapping, it doesn't even have to be active for this to happen. I just noticed the crashes while I was working on my Launchpad configuration (because I was constantly switching between the computer to upload a new config and the phone to test it out).

One important thing is that when the Launchpad X is disconnected or connected while Koala is running, the app will restart itself (go back to the loading screen and then to the pads, and if a sequence was playing it gets stopped).

It seems that this is related to the fact that besides being a MIDI controller, the Launchpad is also a HID device (this was added with an update some time ago, and since then you can map pads to send keystrokes). I have been able to reproduce it using a separate MIDI controller (MPK Mini) and an actual keyboard (Logitech K380 over Bluetooth):

  1. Start Koala
  2. Connect MPK Mini
  3. Connect K380 keyboard (the app restarts itself now, just as it does with the Launchpad!)
  4. Hit Z on the keyboard and the bottom left pad plays properly (this step is optional, just mentioning that the keyboard itself works fine)
  5. Hit a pad or key on the MPK Mini -> the app crashes

The app also crashes if steps 2 and 3 are reversed, i.e. connect the K380 keyboard first (the app restarts) and then connect the MPK Mini (the app doesn't restart but still crashes as soon as I send a MIDI message). And just like in the original scenario, the keyboard can play the pads at any stage just fine.

I hope this helps track it down, but let me know if you need any more details or any further testing done!

mazbox commented 1 year ago

Thanks a lot for the feedback!

If you take the bluetooth keyboard out of the equation does it still happen? i.e.:

  1. Open Koala
  2. Plug in MPK Mini
  3. Hit a pad

It would be interesting to know if its the introduction of the bluetooth keyboard that's causing problems?

I tried recreating just plugging in a launchpad after starting koala on a Pixel 3a and worked as expected. I don't have a bluetooth keyboard for testing at the moment.

gstepniewski commented 1 year ago

It only seems to happen when a keyboard becomes involved - either bluetooth or wired. In fact, a wired keyboard connected while the app is running crashes it immediately before I even reach out for the MIDI controller.

I did some testing on some other phones I had around:

The crash happened on all three exactly as it does on the Pixel (I could only test with the bluetooth keyboard because they don't seem to support usb-c hubs and wouldn't turn the mpk mini on).

Which Launchpad do you have and which software version does it have? Apparently only the Mini Mk3 and X upgraded to newest firmware support keystrokes and would therefore identify as a HID device as well as MIDI - which means if you have a different one you won't be able to reproduce the crash.