mauer / xmidictrl

XMidiCtrl is an X-Plane plugin to use midi controllers within the flight simulator
https://mauer.github.io/xmidictrl/#/
GNU Affero General Public License v3.0
31 stars 10 forks source link

XP12 hangs on exit due to XMidiCtrl #23

Closed beely closed 11 months ago

beely commented 1 year ago

Firstly, XMidiCtrl is awesome and has become essential to my simming - thank you!

I've been having an issue that when I quit XP12 (all versions I've been running with XMidiCtrl since release), I've been getting beachballs most of the time and therefore have to force-quit XP, and I have been troubleshooting the issue. It seems related to XMidiCtrl (I cannot reproduce the exit hangs when XMidiCtrl is not present).

The simplest reproducible case for me that might identify an issue:

This always exits as expected. Then:

This always beachballs on exit.

The XMidiCtrl debug log doesn't indicate anything unusual, and on finishing flights, indicates "Plugin XMidiCtrl 1.02 unloaded successfully" at the end of the flight. So it seems perhaps some kind of initialisation/memory allocation with the plugin itself, rather than in the normal operation of receiving and translating MIDI commands to XP.

When using XP properly, I also start with my MIDI controllers on, and do some flights, and then exit, and most of the time, XP will beachball - it never happens when XMidiCtrl is not loaded by XP.

This was happening with 1.02 - I just updated to 1.04, with the same results.

(With 1.02, often starting with the MIDI controllers powered up would generally let XP exit cleanly, but starting with the MIDI controllers switched off, I'd always get a beachball on exit. With 1.04, I get the exit hang regardless of whether the controllers are powered up when starting XP.)

I also checked running XP12 under Rosetta, and see the exact same issue/behaviour.

I hope that's enough information to help find the issue - if not, I'm happy to help diagnose or provide more info etc!

Thanks!

MBP M1 Pro 16MB, Monterey 12.6.5, XP12 running natively.

mauer commented 1 year ago

Hi @beely,

Many thanks for your kind words and the bug report.

Unfortunately, I don't own an Apple computer. My development environment is in Linux, while I usually use X-Plane on a Windows 11 PC. Both systems do not show the reported behavior. So speaking, it will be tricky to get this resolved.

XMidiCtrl uses a couple of worker threads in order to have as little impact on performance as possible. I assume that one of those threads doesn't terminate correctly. I will enhance the debug logging for those threads, which may help us to identify the issue. It may also be a problem with RtMidi - the component I use to connect the MIDI device. Just today the developer released a new version of it. I will check the release notes to see if there were any problems on macOS.

Could you try the following please?

  1. Install the latest version of the addon and open X-Plane
  2. Load an aircraft where you don't have a profile
  3. Exit X-Plane

I will prepare a new version for you with improved logging. I'm very eager to get this sorted out :-)

Many thanks and kind regards, Marco

beely commented 1 year ago

Sure, I'm happy to help try to diagnose this if I can!

I'd updated to 12.06b3, so I first ran the above tests again to see if the behaviour had changed at all - it hadn't, I still see the same exact behaviour.

Then I tried your steps, and I still get the hang on exit. I then removed XMidiCtrl, and ran the test again - same flight/location/aircraft, and XP exits normally.

I'm happy to run debug builds and do whatever testing you need - there's no rush or anything, I'll be here if you need me..!

mauer commented 1 year ago

Hi,

I have upgraded some core libraries (RtMidi etc.) and created a new test version. Could you try that with your installation, please?

If the problem still occurs I would like to ask you to send me the X-Plane log.txt and the XMidiCtrl log file. Hopefully this will help me to figure out what's going on.

Many thanks, Marco

XMidiCtrl.zip

beely commented 1 year ago

Thanks Marco.

Ok, here's five sets of both logfiles, using the debug version you posted above.

The first two are just running XP to the main screen, then quitting, with and without XMidiCtrl installed:

Then the next three are running XP, then a quick fly, and then quit. With no plugin, there is no hang. With XMidiCtrl installed/used, there are logs for both a clean exit, and a hang.

In all hang cases, I have to kill XP, and as XP continually writes the crash to the logs while hanging, the main log file grows to multiple GB if you let it continue. After a few repeated crash entries, I've deleted the rest of the redundant lines for size.

XMlogs.zip

Let me know if you need anything else!

mauer commented 1 year ago

Hi,

Many thanks for the detailed log. It's really strange. The log entry that XMidiCtrl was unloaded indicates that my plugin was closed correctly. It's more or less the last thing I do in the destructor of the main class.

Interesting is this repeating log entry: --=={FILE: /Users/bhall/X-Plane 12/Log_ATC.txt}==-- --=={This application has crashed because of the plugin: [XPLM_PLUGIN_XPLANE]}==--

I may get in the way of the new ATC system. Could you do me a favor and start X-Plane with XMidiCtrl enabled, wait until the main menu is shown and close it again. This should triggered a hang and send me the Log_ATC.txt afterwards.

Maybe there is something helpful in the ATC-Log which I could use to contact the ATC-Developer. Otherwise I will add debug logs into every destructor to check if everything gets destroyed correctly.

It's a really weird problem.

Thanks for your help!

beely commented 1 year ago

The log entry that XMidiCtrl was unloaded indicates that my plugin was closed correctly.

Yes, I'd seen that in all the logs previously, which looked like it was exiting cleanly. It's not impossible that it's a bug in plugin or memory handling in XP itself of course, but it's always difficult to get a busy dev to look at that bug report, because they'll just assume it's a third-party issue and close the report.

Interesting is this repeating log entry:

Don't worry about the ATC log entry - it's nothing to do with the crash, it's just one of the last thing XP does is write that log and log entry. I've seen this recently with other people's crashes on the XP forum, with people thinking the crash is related to ATC because that log line was the last thing added to the log before the crash, and one of the XP devs saying, no, that's not what it means. So I'm reasonably confident this has nothing to do with ATC.

The crash is caused after that ATC log entry by a plugin, which is the next line. The XPLM thing is the thing that manages plugins I believe, and from what i've seen, if a third-party plugin crashes, you don't often get the cause of the crash, you just get the plugin manager dying, hence the log entry. But I'm no more familiar with the XP dev kit of APIs to be of any more help there.

Could you do me a favor and start X-Plane with XMidiCtrl enabled, wait until the main menu is shown and close it again. This should triggered a hang and send me the Log_ATC.txt afterwards.

Sure, I'll do this for you shortly to check, but I'm pretty confident it has nothing to do with the issue.

Otherwise I will add debug logs into every destructor to check if everything gets destroyed correctly. It's a really weird problem.

Perhaps it has something to do with how the Mac version is compiled? Some weird memory allocation thing or something?

Ultimately, I guess if you can't get to the bottom of it (and it may not even be your plugin's fault), I'll likely just have to continue to force-quit XP much of the time, and hope that one day, something changes in XP that magically fixes it! It's not the end of the world - and I do appreciate you at least having a look into it!

beely commented 1 year ago

Could you do me a favor and start X-Plane with XMidiCtrl enabled, wait until the main menu is shown and close it again. This should triggered a hang and send me the Log_ATC.txt afterwards.

I just did this, XP hung on exit with the same repeated lines in the regular log, and there is nothing of any note in the ATC log:

--

Log_ATC.txt for X-Plane 12.06b6 (build 120610 Apple Silicon, Metal fd0041ed97441540d232b3daff25fb242982386a) Compiled on Aug 18 2023 08:21:38 X-Plane Started on Tue Aug 22 16:48:15 2023

This log file is generated automatically by Laminar Research applications and contains diagnostics about your graphics hardware, installation, and any error conditions. If you need to contact tech support or file a bug, please send us this file.

macOS: Version 12.6.8 (Build 21G725) CPU type: Apple M1 Pro CPU speed (mhz): 0 Bus speed (mhz): 0 RAM (MB): 16384

X-System folder:'/Users/REDACTED/X-Plane 12/', case sensitive=0

--

That's it.

beely commented 11 months ago

So - some good progress on this to report. I upgraded from Monterey to Sonoma today, and in checking various things out, I'm finding that XP12 is always exiting cleanly now - no hangs on exit so far, either from the main screen, or from in flight.

So the hanging problem was perhaps some issue with Monterey, or something specific on my system.

I'll do a little more testing over the next day or two, and if I really no longer have the problem, we can close this issue as likely not a problem directly with XMidiCtrl - which will no doubt be a relief!

beely commented 11 months ago

Doesn't seem to be an issue any more on Sonoma - closing issue.