Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Catch C++ exceptions before returning to JNI #2825

Closed

Description

@1ec5

Per #2804, the Android SDK suffers from a native crash any time there’s an uncaught C++ exception at the mbgl level. An uncaught exception there usually indicates developer error, so the Android SDK needs to present that error in a way that’s actionable without spelunking into mbgl code. The Android bindings cannot rely on an assumption that the C++ code won’t throw exceptions.

platform/android/jni.cpp needs to have C-style exception handling. For example, nativeSetStyleURL() should be wrapped in a try-catch statement. When an exception is caught, this function should return some kind of error code. For functions that already need to return a value, this would imply some kind of out parameter or a tuple-typed return value.

Though this could be a fair amount of work, it pays off in the form of Android bindings that can actually be debugged.

/cc @ljbade @bleege @jfirebaugh

Activity

  1. added
    Android
    on Oct 27, 2015
  2. ljbade commented on Oct 27, 2015

    @ljbade
    Contributor

    As discussed in slack a wrinkle with nativeSetStyleURL is that the invalid style URL error will be thrown from the map thread, not the UI thread, so adding a catch to nativeSetStyleURL will not work.

    Instead we can take advantage of how Java checking JNI thrown Java exceptions. If we convert exception to Java exception in the map thread instead of killing the thread. Then when we next call into Java land (View::invalidate) the exception will be picked up and crash the app Java side with a useful message.

    We also need to log the C++ exception stack trace to logcat first so that in the log we have both the original stack trace, and the new Java one which will point to invalidate()

  3. ljbade commented on Oct 27, 2015

    @ljbade
    Contributor

    @1ec5 Historic context on my previous attempt at C++ exception handling:
    #562

  4. ljbade commented on Oct 28, 2015

    @ljbade
    Contributor

    @1ec5 Should we also open a iOS ticket for iOS exception handling? Will help in #2775 (comment)

    I don't believe iOS has any direct way of knowing if a style has failed to load.

  5. 1ec5 commented on Oct 28, 2015

    @1ec5
    ContributorAuthor

    @ljbade, once #2762 is fixed, iOS will get such notifications for free.

  6. bleege commented on Oct 28, 2015

    @bleege
    Contributor

    once #2762 is fixed, iOS will get such notifications for free.

    The joys of living in an all C++ world. 😃

  7. self-assigned this
    on Mar 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Androidbugcrash

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions