mSparks43 / XPlane-11-AutoATC-plugin

C/C++ Source code for Xplane AutoATC plugin
GNU Lesser General Public License v3.0
16 stars 7 forks source link

X-Plane crashes on startup (mac) when AutoATC installed #56

Closed leecbaker closed 4 years ago

leecbaker commented 4 years ago

Not much to say other than X-Plane crashes on shutdown. I can replicate this every time.

Steps to reproduce:

I'm using the latest X-Plane release (11.41r2) on macOS 10.15.4.

Here's the backtrace from the crash reporter:

Thread 0 Crashed:: Main Thread  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fff6ade533a __pthread_kill + 10
1   libsystem_pthread.dylib         0x00007fff6aea1e60 pthread_kill + 430
2   libsystem_c.dylib               0x00007fff6ad6c808 abort + 120
3   libc++abi.dylib                 0x00007fff67fcc458 abort_message + 231
4   libc++abi.dylib                 0x00007fff67fbd7e9 demangling_terminate_handler() + 48
5   libc++abi.dylib                 0x00007fff67fcb887 std::__terminate(void (*)()) + 8
6   libc++abi.dylib                 0x00007fff67fcb838 std::terminate() + 56
7   libsystem_c.dylib               0x00007fff6ad4713c __cxa_finalize_ranges + 319
8   dyld                            0x0000000110f82ccd dyld::garbageCollectImages() + 851
9   dyld                            0x0000000110f8d042 dlclose + 191
10  libdyld.dylib                   0x00007fff6ac9acf8 dlclose + 170
11  XPLM                            0x000000007eeb3e98 UnloadOnePlugin(int) + 370
12  XPLM                            0x000000007eeb3cce XPLMUnloadPlugins() + 53
13  com.laminar-research.X-Plane    0x000000010a36af1f XPPShutdownPlugins() + 63
14  com.laminar-research.X-Plane    0x000000010a10c568 MACIBM_finishup(int) + 440
15  com.laminar-research.X-Plane    0x000000010a04ca13 main + 83
16  libdyld.dylib                   0x00007fff6ac9dcc9 start + 1

And from the log file, here are the last few lines:

0:00:25.610 I/WIN: Opened window menu bar
Apply /usr/local/jre/lib/server/libjvm.dylib
--=={This application has crashed because of the plugin: [XPLM_PLUGIN_XPLANE]}==--
mSparks43 commented 4 years ago

Thanks, I was just going to ask if you could put this on here. So, normally to build and test for mac I would sit on a friends macbook air in a cafe accros the street that also works from "home".. obviously that is not an option right now.

Carrying on from the comments on the install page, I understand you are using jdk 14. Please could you try 8. I believe these are the mac install instructions https://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html

The crash is happening at the point it tries to open the java vm

That is somewhere after line 230 of https://github.com/mSparks43/XPlane-11-AutoATC-plugin/blob/master/src/jvm.cpp

does it print the AutoATC:Successfully loaded the jvm .so line in the xplane log.txt? If that still isnt fixing it, the next option given the circumstances is probably to build it yourself. This is pretty easy on mac since all the tools you need are easily available and the reason so many developers prefer it.

Help is here.

mSparks43 commented 4 years ago

I see now these are two different reports on Mac 10.15.4 The above still applies

leecbaker commented 4 years ago

Yes, give me a day or so and I'll look into it. I do have easy access to mac, so it's easy for me to debug. I didn't realize this part of the plugin was open source, that makes it even easier.

-lee

leecbaker commented 4 years ago

OK here's what I have. I have compiled the plugin locally, and run with X-Plane. I'm still seeing a segfault, with a backtrace that isn't useful- looks like memory corruption.

I have no other plugins installed. Printed to the log:

AutoATC:Wav loaded.
AutoATC:Wav loaded.
AutoATC:Wav loaded.
AutoATC:Wav loaded.
AutoATC:Using OpenAL device.
plane thread began
a simple notepad in Resources/plugins/AutoATC
AutoATC:Successfully loaded the jvm .so

And stdout/stderr:

AutoATC:load sound 1AutoATC:load sound 2AutoATC:load sound 3AutoATC:load sound 4AutoATC:load sound 5AutoATC:load sound 6AutoATC:0x00000000: I found someone else's openAL context 0x00000019.
Process 43593 stopped
* thread #1, name = 'Main Thread', queue = 'com.apple.main-thread', stop reason = signal SIGSEGV

I'm going to dig in a bit more.

leecbaker commented 4 years ago

The crash is occurring here: https://github.com/mSparks43/XPlane-11-AutoATC-plugin/blob/27e9f5ebb6d0621a76fe2fb87d2f960db1c3da29/src/jvm.cpp#L293

I think the original bug might be caused by memory corruption, as the parameters to the function look OK to me.

mSparks43 commented 4 years ago

I didn't realize this part of the plugin was open source, that makes it even easier. The C/C++ is LGPL, with other options available if people want it. It had been 20 years since I had done much C, so made it open to help with any porting issues and because the XP11 SDK is so powerful it needs to be used more. The jar isn't, but the JVM gives enough feedback on issues that it doesn't need to be (there is a skeleton available .java that covers the functions called)

To clarify, there are two known bugs crashing on the JVM, the title of this is "on shutdown" There is a known - now fixed bug that affects everyone occasionally on shutdown, that should have been resolved on Wednesday with the jar in https://forums.x-plane.org/applications/core/interface/file/attachment.php?id=490544 from my comment in https://forums.x-plane.org/index.php?/files/file/45663-main-installation-files-for-autoatc-for-xplane-11/&page=8&tab=comments

There is also a crash, on mac, at startup, posted by Samir Singh in the comment thread above that looked like it could be the original issue posted here.

I suspect given what you have reported above that it is related to the performance options being used

options[0].optionString = "-XX:+UseG1GC"; options[1].optionString = "-XX:MaxGCPauseMillis=2"; //options[2].optionString = "-XX:+UseStringCache"; options[2].optionString = "-XX:ParallelGCThreads=4"; options[3].optionString = "-XX:ConcGCThreads=4";

Which were added/changed during performance issue debugging (using the standard GC results in multiple "stop the world" collections which hit performance badly on some machines) and have only been tested on win/lin.

These are also likely Java 8 specific.

First I would try

JavaVMOption* options = new JavaVMOption[4]; options[0].optionString = "-XX:+UseG1GC"; options[1].optionString = "-XX:MaxGCPauseMillis=2"; options[2].optionString = "-XX:ParallelGCThreads=4"; options[3].optionString = "-XX:ConcGCThreads=4"; vm_args.nOptions = 4;

Array of length 4 instead of 5 on the first line

then

vm_args.nOptions = 0; // vm_args.options = options;

to try and start it with default options.

leecbaker commented 4 years ago

To clarify, there are two known bugs crashing on the JVM, the title of this is "on shutdown" You're totally right. I have experienced both. I started to debug one bug, and then the other occurred. Was too busy chasing a bug to realize I was confusing the two.

Unfortunately starting with default options didn't seem to solve the problem at all. Even with incorrect options, I would hope this would not clobber the stack like it is.

It's getting late here- I'll have to pick this up another day.

mSparks43 commented 4 years ago

I started to debug one bug, and then the other occurred.

I renamed the title for this one. Shutdown is issue #17 and I just put 0.9.2 on the .org which should fix it.

Since startup is emergent on Catalina, I'd delete and try installing again, the .xpl has been tested on pre catalina mac, and JNI_CreateJavaVM is in /usr/local/jre/lib/server/libjvm.dylib from the JDK install

mSparks43 commented 4 years ago

Not sure if this is the cause here, but it is a candidate. segfaults on Linux if Resources/plugins/java/AutoATCPlugin.jar doesn't exist.

So if Xplane cant read this file (or one of its dependants) due to some permissions issue this might cause it

mSparks43 commented 4 years ago

As of 9.4.2, jvm is bundled, and options are configurable in the json file