question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[bug/crash] MaskedView makes application crash on Android

See original GitHub issue

Hi,

I’m experiencing an app crash on Android devices when using MaskedView. It occurs when leaving the screen (react navigation) with rendered MaskedView component and started happening after upgrading to RN 0.64.0.

Deps: “@react-native-masked-view/masked-view”: “0.2.3”, “react-native”: “0.64.0”,

P.s. iOS is working fine.

Logcat fragment:

021-04-13 12:31:49.611 15339-15339/[app] E/unknown:ReactNative: Exception thrown when executing ReactViewGroup.dispatchDraw method on ReactViewGroup[2999]
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setVisibility(int)' on a null object reference
        at org.reactnative.maskedview.RNCMaskedView.updateBitmapMask(RNCMaskedView.java:81)
        at org.reactnative.maskedview.RNCMaskedView.dispatchDraw(RNCMaskedView.java:35)
        at android.view.View.buildDrawingCacheImpl(View.java:20689)
        at android.view.View.buildDrawingCache(View.java:20555)
        at android.view.View.draw(View.java:21145)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4388)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4173)
        at com.facebook.react.views.view.ReactViewGroup.dispatchDraw(ReactViewGroup.java:710)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
k-ibrcommented, Apr 26, 2021

@DanielMarkiel I looked into this and it seems like MaskedView is trying to “modify” elements that no longer exist due to RN removing them from memory (by switching screens). So a quick fix for this is to check for null object on the view inside RNCMaskedView.java. You can try this by replacing the following functions by this code.

private void updateBitmapMask() {
    if (this.mBitmapMask != null) {
      this.mBitmapMask.recycle();
    }

    View maskView = getChildAt(0);
    if (maskView != null) {
      maskView.setVisibility(View.VISIBLE);
      this.mBitmapMask = getBitmapFromView(maskView);
      maskView.setVisibility(View.INVISIBLE);
    } else{
      this.mBitmapMask = null;
    }
  }
public void onDescendantInvalidated(View child, View target) {
    super.onDescendantInvalidated(child, target);

    if (!mBitmapMaskInvalidated) {
      View maskView = getChildAt(0);
      if (maskView != null) {
        if (maskView.equals(child)) {
          mBitmapMaskInvalidated = true;
        }
      }
    }
  }

this solves the crashing, but perhaps someone from the MaskedView team could look further into it because I am not 100% sure this is a clean solution. Could someone more experienced also look into this? @Naturalclar @FonDorn

4reactions
khorarkcommented, Jun 29, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Detect and diagnose crashes - Android Developers
An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java...
Read more >
How to Stop Apps From Crashing on Android - AVG
Try boosting your home wifi signal strength to fix crashing apps and make sure they have all the internet they need. Force stop...
Read more >
React native app crash without error log ,How to detect a bug?
Now run adb logcat : This command will output all logs (debug and error levels) coming from your Android Device. Install your application...
Read more >
Crash on supported devices when OpenGL is set to android ...
Create an application based on the Google Maps sample app. 2. Install the application and verify that maps load correctly. 3. Edit the...
Read more >
Instagram app rendered unusable for some by instant crash bug
An error had been causing Instagram's Android app to crash seconds after launching, rendering it almost unusable..
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found