Skip to content

newDrawable on NULL object crash in ui/styling/background.android.ts #7954

@Yermo

Description

@Yermo

I do not know if this is a tns-core-modules issues, an android-runtime issue, or an issue with the nativescript-mapbox plugin that I am working on.

I originally filed this with the android-runtime project here: NativeScript/android#1487

Environment

  • CLI: 6.1.2
  • Cross-platform modules: 6.1.1
  • Android Runtime: 6.1.2
  • iOS Runtime:
  • Plugin(s):
  "dependencies": {
    "@angular/animations": "~8.2.0",
    "@angular/common": "~8.2.0",
    "@angular/compiler": "~8.2.0",
    "@angular/core": "~8.2.0",
    "@angular/forms": "~8.2.0",
    "@angular/platform-browser": "~8.2.0",
    "@angular/platform-browser-dynamic": "~8.2.0",
    "@angular/router": "~8.2.0",
    "nativescript-advanced-permissions": "^1.2.0",
    "nativescript-mapbox": "file:../publish/dist/package",
    "nativescript-angular": "~8.2.0",
    "nativescript-theme-core": "~1.0.6",
    "nativescript-ui-sidedrawer": "~7.0.0",
    "reflect-metadata": "~0.1.12",
    "rxjs": "^6.4.0",
    "rxjs-compat": "^6.5.3",
    "tns-core-modules": "~6.1.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular/compiler-cli": "~8.2.0",
    "@ngtools/webpack": "~8.2.0",
    "@types/chai": "~4.1.7",
    "@types/mocha": "~5.2.5",
    "@types/node": "~10.12.18",
    "chai": "~4.1.2",
    "codelyzer": "~4.5.0",
    "mocha": "~5.2.0",
    "mocha-junit-reporter": "~1.18.0",
    "mocha-multi": "~1.0.1",
    "mochawesome": "~3.1.2",
    "nativescript-dev-appium": "^6.1.2",
    "nativescript-dev-webpack": "~1.2.0",
    "node-sass": "^4.7.1",
    "tslint": "~5.19.0",
    "typescript": "~3.5.3"
  }

Using Android Emulator with an API 28 image under Ubuntu 18.04 LTS with Android Studio:

Android Studio 3.5
Build #AI-191.8026.42.35.5791312, built on August 8, 2019
JRE: 1.8.0_202-release-1483-b49-5587405 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-38-generic

Describe the bug

I am working on the NativeScript Mapbox plugin. My fork is here: https://github.com/Yermo/nativescript-mapbox

The crash can be replicated using the included demo-angular app and e2e test.

Since upgrading Nativescript to NS 6+, I am experiencing a random crash when navigating away from a page containing a map and removing the map container when running with "markingMode":"none".

I do not know if the map plugin code is causing the instability as I have not been able to reproduce this problem navigating away from other pages, but the crash happens after the navigation has completed and the map view and object have been destroyed leading me to believe that maybe this is not my bug.

The map object is quite large so when doing lateral navigation ideally I want to destroy the mapbox view. I do this by wrapping the Mapbox tag in container with an *ngIf. Before navigating away the *ngIf condition is set to false and I wait for the mapbox onDestroy to return before proceeding with the navigation (thinking maybe there's a race condition somewhere.)

After a random number of navigations between the map page and the test-crash page in the demo-angular app, it will crash on

defaultDrawable = cachedDrawable.newDrawable(nativeView.getResources());

when navigating /to/ the test-crash page with the error:

JNI DETECTED ERROR IN APPLICATION: can't call android.graphics.drawable.Drawable android.graphics.drawable.ColorDrawable$ColorState.newDrawable(android.content.res.Resources) on null object

cachedDrawable in this case is not null on the javascript side so I suspect a markingMode: "none" issue. Adding a line of code to the javascript:

if ( cachedDrawable == null ) {
	console.log( "background.android.js - cachedDrawable is NULL ---------------" );
} else {
        console.log( "background.android.js - cachedDrawable is:", cachedDrawable );
}

Causes a crash on the second console.log with the error can't call toString() on null object.

To Reproduce
Clone my repository:
https://github.com/Yermo/nativescript-mapbox

cd nativescript-mapbox/src
npm run build.dist
cd ../demo-angular
tns build android
npm run e2e -- --runType android28

(or whatever emulator you have)
It will crash between 3 and 100 iterations of navigating between the map page and the crash-test page.

Expected behavior

Ideally, it should not crash.

Sample project
https://github.com/Yermo/nativescript-mapbox/demo-angular

Additional context
I am motivated to solve this problem as it is a blocking issue for me that has cost me a few weeks now.
It is entirely possible that something I am doing in my plugin is mucking up the works, but I have attempted to follow all the guides and recommendations for writing plugins. I am not the original Mapbox plugin author but am largely taking over development of that plugin.

If no one has the free cycles to look into this, could I maybe get some pointers on how I might try to track this down?
Is there a way to test a NativeScript/Javascript object to see if the corresponding Java object has been freed or is set to NULL?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions