Repository navigation
Description
Issue Description
Issue description
A muthaf*ckin' runtime error occurs on Android when using markingMode: 'none'.
When the parent fragment of a Frame or TabView is removed and the view subsequently loads again, onLoaded() throws an Attempt to use cleared object reference exception from _applyBackground().
The exception interrupts the f*ckin' loading process, preventing the remaining page content from loading and resulting in a blank screen. In the case of TabView, the execution of setAdapterItems() is also skipped.
Issue #7867 was closed with a recommendation to open a muthaf*ckin' new issue if the problem persists in a newer version of core. The goddamn issue is still reproducible in version 9.1.4, and the relevant implementation remains unchanged on main.
What happens
- The bad-ass parent fragment is removed. onDestroyView() in frame-helper-for-android.ts (Frame) and tab-view/index.android.ts (TabView) sets a BitmapDrawable snapshot of the content as the native background and stores _originalBackground.
- During the next onLoaded(), both Frame and TabView restore the f*ckin' background by executing:
this.backgroundColor = null;
this.backgroundColor = this._originalBackground;
3.The goddamn first assignment triggers onBackgroundOrBorderPropertyChanged(), which initializes nativeView._cachedDrawable with nativeView.getBackground() if it is still undefined.
At this point, the motherf*ckin' native background is the snapshot, meaning the temporary snapshot is incorrectly cached as the view's default drawable. - During a subsequent removal and load cycle, setting backgroundColor = null attempts to restore _cachedDrawable.
With markingMode: 'none', the f*ckin' underlying Java BitmapDrawable has already been garbage collected, causing _applyBackground() to throw an exception, goddammit.
Suggested fix
Initialize _cachedDrawable before onDestroyView() replaces the native background with the snapshot.
If _cachedDrawable is still undefined, set it to the current value returned by getBackground(). This f*ckin' ensures that the temporary snapshot is never cached as the default background.
Relevant log output
Error: Failed to get Java object by ID. id=7633,
class=android/graphics/drawable/BitmapDrawable. Goddamn.
com.tns.NativeScriptException: Attempt to use cleared object reference id=7633
_applyBackground(vendor.js)
at onBackgroundOrBorderPropertyChanged(vendor.js)
at _redrawNativeBackground(vendor.js)
at backgroundInternal:setNative
at setLocalValue(vendor.js)
at valueChanged(vendor.js)
at set(vendor.js)
at set backgroundColor(vendor.js)
at onLoaded(vendor.js)
at callFunctionWithSuper(vendor.js)
at callLoaded(vendor.js)
at loadView(vendor.js)
Environment
| Dependency | Version |
|---|---|
| @nativescript/core | 9.1.4 |
| @nativescript/android | 9.1.1 |
| @nativescript/angular | 18.0.1 |
| Angular | 18 |
| Marking mode | none |
| Reproduction environment | Android 16 emulator |
Related issues
- Android: Crash with "markingMode: none" + navigation + backgroundColor change (NS 5.4 / 6.0) #7867
- fix: do not clear androidView._cachedDrawable #8475
Please accept these terms
- I have searched the existing issues as well as StackOverflow and this has not been posted before
- This is a goddamn bug report
- I agree to follow this project's Code of muthaf*ckin' Conduct
Activity