gogins / csound-android

Almost all of Csound as an Android app, with a built-in code editor and support for HTML5 and JavaScript.
GNU Lesser General Public License v2.1
6 stars 0 forks source link

Csound for Android - implement better diagnostics for crashes #11

Closed arthunkins closed 1 year ago

arthunkins commented 1 year ago

In a new version, is it possible during realtime run (following successful compile), when Csound crashes, for it to leave the Message screen intact? This would be very helpful in debugging. Currently, Csound abruptly quits, returning to the "desktop." (The Message window is open for less than two seconds - not enough to read.) To run again, you must reboot Android and completely start over - with only guesswork for guidance.

gogins commented 1 year ago

Can you provide a minimal working example of a .csd file that crashes the app?

gogins commented 1 year ago

Don't bother, I just found dividing by zero in Xanadu does the job.

gogins commented 1 year ago

Solution may be indicated here: https://stackoverflow.com/questions/4138168/what-happens-when-i-throw-a-c-exception-from-a-native-java-method/12014833#12014833. I don't think that's quite going to do it though, because Csound is written in C. But a signal handler might work.

gogins commented 1 year ago

It looks like I would need to create a signal handler in C that would throw a Java exception via JNI. Does SWIG have anything to offer here? Yes, https://swig.org/Doc1.3/Java.html#exception_typemap. I still need to implement the signal handler.

In the app, csoundInitialize is called with CSOUNDINIT_NO_ATEXIT but not with CSOUNDINIT_NO_SIGNAL_HANDLER, therefore this default signal handler is called:

static void signal_handler(int sig)
{
#if defined(SIGPIPE)
    if (sig == (int) SIGPIPE) {
      psignal(sig, "Csound ignoring SIGPIPE");
      return;
    }
#endif
    psignal(sig, "\ncsound command");
    if ((sig == (int) SIGINT || sig == (int) SIGTERM)) {
      if (_csound) {
        csoundStop(_csound);
        csoundDestroy(_csound);
      }
      //_result = -1;
      if (logFile != NULL)
        fclose(logFile);
      exit(1);
      //return;
    }
    exit(1);
}

I will therefore try with no signal handler. No help.

gogins commented 1 year ago

This is interesting: https://github.com/android/ndk/issues/1398. This information has been made hard to access. More here: https://stackoverflow.com/questions/34547199/art-prevents-any-java-calls-from-jni-during-native-signal-handling. The only good way to do this would be to open a socket and send a message to a listener.

This in fact is exactly what happens by default in Android apps installed from the Play Store, the app sends a stack trace to the Developer Console, but of course only the developer can see it.

Two motivations here:

  1. JVM is in an undefined state when a signal handler is called, so behavior is undefined.
  2. Security!

Bottom line: Not doing this.

gogins commented 1 year ago

I will however document how to debug crashes in the User Guide.

arthunkins commented 1 year ago

Hi, Mike -

Sorry to here you can't do anything about the crashes, but I understand and thanks for investigating.

What I've been doing is to troubleshoot on Windows (for which I do versions of my .csd's) and work back and forth between the platforms.

I've been following your revision work and look forward to the new version.

One question: Regardless of whether or not I've got an internet connection (in my case Wi-Fi), the current Csound for Android takes 10 seconds or more to boot, i.e., show anything on screen. Is this much delay normal? Or may it have anything to do with my particular device?

Thanks much - Art H.

@.*** http://www.arthunkins.com


From: Michael Gogins @.> Sent: Thursday, August 24, 2023 3:30 PM To: gogins/csound-android @.> Cc: Arthur Hunkins @.>; Author @.> Subject: Re: [gogins/csound-android] Csound for Android - implement better diagnostics for crashes (Issue #11)

I will however document how to debug crashes in the User Guide.

— Reply to this email directly, view it on GitHubhttps://github.com/gogins/csound-android/issues/11#issuecomment-1692289702, or unsubscribehttps://github.com/notifications/unsubscribe-auth/APSKXHCH65PCIGSIF3Y5U2DXW6TTZANCNFSM6AAAAAAWXYFHOY. You are receiving this because you authored the thread.Message ID: @.***>

gogins commented 1 year ago

It takes a 2 or 3 seconds to boot on my tablet, which is reasonably up to date and powerful. I think it's just the nature of the beast, as Android apps go this is pretty heavy duty. One thing that takes time is copying plugins, examples, and such out of the .apk file and onto the device filesystem.

arthunkins commented 1 year ago

Michael -

I just checked on my wife's year-old Android smartphone, and load time for Csound is virtually immediate!

So, my apologies. My "older" (??) phone is a Nexus6, running Android 7.1.1, with updates expiring in Oct. 2017. I guess that a lot​ of performance improvements have been made since that time!

Art H.

@.*** http://www.arthunkins.com


From: Michael Gogins @.> Sent: Thursday, August 24, 2023 4:09 PM To: gogins/csound-android @.> Cc: Arthur Hunkins @.>; Author @.> Subject: Re: [gogins/csound-android] Csound for Android - implement better diagnostics for crashes (Issue #11)

It takes a 2 or 3 seconds to boot on my tablet, which is reasonably up to date and powerful. I think it's just the nature of the beast, as Android apps go this is pretty heavy duty. One thing that takes time is copying plugins, examples, and such out of the .apk file and onto the device filesystem.

— Reply to this email directly, view it on GitHubhttps://github.com/gogins/csound-android/issues/11#issuecomment-1692339995, or unsubscribehttps://github.com/notifications/unsubscribe-auth/APSKXHD4NOIP55RO5RM2ZSDXW6YIHANCNFSM6AAAAAAWXYFHOY. You are receiving this because you authored the thread.Message ID: @.***>