react-native-skia icon indicating copy to clipboard operation
react-native-skia copied to clipboard

Failed to create window surface native crash on android

Open TomAtterton opened this issue 2 years ago • 16 comments

Ever since updating to version 1.5.5, the app now crashes on my Android device (Pixel 6).

2024-11-20 12:28:32.798 15830-15913 unknown:Vi...rtyUpdater com.tomatterton.advent               W  Could not find generated setter for class com.shopify.reactnative.skia.SkiaPictureViewManager
2024-11-20 12:28:32.799 15830-15913 unknown:Vi...rtyUpdater com.tomatterton.advent               W  Could not find generated setter for class com.shopify.reactnative.skia.SkiaDomViewManager
2024-11-20 12:28:34.435 15830-15912 nativeloader            com.tomatterton.advent               D  Load /data/app/~~ADlBVr7mg6_yR7xnb4EKGA==/com.tomatterton.advent-W3v2hwIrfKrYYZHLB_-bNQ==/base.apk!/lib/arm64-v8a/librnskia.so using ns clns-6 from class loader (caller=/data/app/~~ADlBVr7mg6_yR7xnb4EKGA==/com.tomatterton.advent-W3v2hwIrfKrYYZHLB_-bNQ==/base.apk!classes7.dex): ok
2024-11-20 12:28:38.867 15830-15830 SkiaView                com.tomatterton.advent               I  Create SurfaceTexture
2024-11-20 12:28:38.867 15830-15830 SkiaView                com.tomatterton.advent               I  onSurfaceTextureAvailable 0/0
2024-11-20 12:28:38.902 15830-15830 SkiaView                com.tomatterton.advent               I  onLayout 1080/2400
2024-11-20 12:28:38.902 15830-15830 SkiaView                com.tomatterton.advent               I  onSurfaceTextureSizeChanged 1080/2400
2024-11-20 12:28:38.902 15830-15830 RNSkia                  com.tomatterton.advent               I  EGL Error: Bad Alloc (12291) in /Users/tomatterton/Projects/advent-app/node_modules/@shopify/react-native-skia/android/cpp/rnskia-android/gl/Display.h:89
2024-11-20 12:28:38.903 15830-15830 unknown:ReactNative     com.tomatterton.advent               E  Exception in native call java.lang.RuntimeException: Failed to create window surface
    at com.shopify.reactnative.skia.SkiaDomView.surfaceSizeChanged(Native Method)
    at com.shopify.reactnative.skia.SkiaBaseView.onSurfaceTextureSizeChanged(SkiaBaseView.java:67)
    at android.view.TextureView.onSizeChanged(TextureView.java:453)
    at android.view.View.sizeChange(View.java:25350)
    at android.view.View.setFrame(View.java:25302)
    at android.view.View.layout(View.java:25153)
    at com.shopify.reactnative.skia.SkiaBaseView.onLayout(SkiaBaseView.java:52)
    at android.view.View.layout(View.java:25159)
    at android.view.ViewGroup.layout(ViewGroup.java:6460)
    at com.facebook.react.uimanager.NativeViewHierarchyManager.updateLayout(NativeViewHierarchyManager.java:265)
    at com.facebook.react.uimanager.NativeViewHierarchyManager.updateLayout(NativeViewHierarchyManager.java:233)
    at com.swmansion.reanimated.layoutReanimation.ReanimatedNativeHierarchyManagerBase.updateLayout(ReanimatedNativeHierarchyManagerBase.java:15)
    at com.facebook.react.uimanager.UIViewOperationQueue$UpdateLayoutOperation.execute(UIViewOperationQueue.java:145)
    at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:879)
    at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:992)
    at com.facebook.react.uimanager.UIViewOperationQueue.-$$Nest$mflushPendingBatches(Unknown Source:0)
    at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:1052)
    at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.kt:22)
    at com.facebook.react.modules.core.ReactChoreographer.frameCallback$lambda$1(ReactChoreographer.kt:60)
    at com.facebook.react.modules.core.ReactChoreographer.$r8$lambda$nSkFhrr5T7rop_XKwzlLov4NLLw(Unknown Source:0)
    at com.facebook.react.modules.core.ReactChoreographer$$ExternalSyntheticLambda0.doFrame(D8$$SyntheticClass:0)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1404)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1415)
    at android.view.Choreographer.doCallbacks(Choreographer.java:1015)
    at android.view.Choreographer.doFrame(Choreographer.java:941)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1389)
    at android.os.Handler.handleCallback(Handler.java:959)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loopOnce(Looper.java:232)
    at android.os.Looper.loop(Looper.java:317)
    at android.app.ActivityThread.main(ActivityThread.java:8592)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
android": {
  "compileSdkVersion": 35,
  "targetSdkVersion": 35,
  "minSdkVersion": 24,
  "buildToolsVersion": "35.0.0",
  "newArchEnabled": false,
  "packagingOptions": {
    "pickFirst": ["**/libreactnative.so"]
  }
}

The only interaction with Skia in my project is with my package: react-native-snowfall. Running the example on the latest version seems to work fine, so I’m confused about what could have caused the issue in my project.

TomAtterton avatar Nov 20 '24 11:11 TomAtterton

Can you try v1.5.6 and also share with me the project on which you run the example? I tried the example with minSdk 24 on the example app and it worked (trying in release mode now)

wcandillon avatar Nov 20 '24 12:11 wcandillon

I would also be curious to know if this happens on the simulator as well.

wcandillon avatar Nov 20 '24 12:11 wcandillon

@wcandillon invited you to the project šŸ‘šŸ»

it does run on emulator without crashing interesting ! Pixel 4 api 32

TomAtterton avatar Nov 20 '24 12:11 TomAtterton

ok this is great to know because I use a Pixel 4, should I get a Pixel 6 or can I even get or newer pixel model?

wcandillon avatar Nov 20 '24 12:11 wcandillon

I am using a Pixel 6 with android 14 that's only device I have on hand

TomAtterton avatar Nov 20 '24 12:11 TomAtterton

The app looks so beautiful, unfortunately it looks like the crash is not reproducible on the Pixel 6 emulator. (I ordered a physical pixel 8 device).

wcandillon avatar Nov 20 '24 13:11 wcandillon

I also had same issue since v1.5.5. It worked until v1.5.4. My device is Pixel 7 & Android 15.

bluekyu avatar Nov 21 '24 02:11 bluekyu

Confirm it happens with 1.5.6 as well

antonandreyev avatar Nov 21 '24 09:11 antonandreyev

@TomAtterton you seem to be able to reproduce the issue locally, could I provide you a test package from #2759 and get some feedback? Anyone would be willing to test a potential fix for it?

wcandillon avatar Nov 21 '24 10:11 wcandillon

Hi William,

I am willing to test the potential fix. I got the same issue using 1.5.6: Crashed on my Samsung A51, Android 14 and got crashed report from Google Play for Pixel 7 Android 13 and Pixel 6 Android 12.

Best regards, Phuong

Reproducible code:

    var surface = Skia.Surface.MakeOffscreen(width,height);
    var canvas = surface.getCanvas();

Error message:

Exception java.lang.RuntimeException: Failed to create window surface at com.shopify.reactnative.skia.SkiaDomView.surfaceSizeChanged at com.shopify.reactnative.skia.SkiaBaseView.onSurfaceTextureSizeChanged (SkiaBaseView.java:67) at android.view.TextureView.onSizeChanged (TextureView.java:381) at android.view.View.sizeChange (View.java:23332) at android.view.View.setFrame (View.java:23284) at android.view.View.layout (View.java:23141) at com.shopify.reactnative.skia.SkiaBaseView.onLayout (SkiaBaseView.java:52) at android.view.View.layout (View.java:23144) at android.view.ViewGroup.layout (ViewGroup.java:6412) at com.facebook.react.uimanager.NativeViewHierarchyManager.updateLayout (NativeViewHierarchyManager.java:254) at com.facebook.react.uimanager.NativeViewHierarchyManager.updateLayout (NativeViewHierarchyManager.java:222) at com.swmansion.reanimated.layoutReanimation.ReanimatedNativeHierarchyManager.updateLayout (ReanimatedNativeHierarchyManager.java:283) at com.facebook.react.uimanager.UIViewOperationQueue$UpdateLayoutOperation.execute (UIViewOperationQueue.java:135) at com.facebook.react.uimanager.UIViewOperationQueue$1.run (UIViewOperationQueue.java:910) at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches (UIViewOperationQueue.java:1023) at com.facebook.react.uimanager.UIViewOperationQueue.-$$Nest$mflushPendingBatches (Unknown Source) at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded (UIViewOperationQueue.java:1083) at com.facebook.react.uimanager.GuardedFrameCallback.doFrame (GuardedFrameCallback.java:29) at com.facebook.react.modules.core.ReactChoreographer$1.doFrame (ReactChoreographer.java:89) at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1035) at android.view.Choreographer.doCallbacks (Choreographer.java:845) at android.view.Choreographer.doFrame (Choreographer.java:775) at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1022) at android.os.Handler.handleCallback (Handler.java:938) at android.os.Handler.dispatchMessage (Handler.java:99) at androidx.test.espresso.base.Interrogator.loopAndInterrogate (Interrogator.java:10) at androidx.test.espresso.base.UiControllerImpl.loopUntil (UiControllerImpl.java:7) at androidx.test.espresso.base.UiControllerImpl.loopUntil (UiControllerImpl.java:1) at androidx.test.espresso.base.UiControllerImpl.loopMainThreadForAtLeast (UiControllerImpl.java:7) at androidx.test.espresso.action.Tap$1.sendTap (Tap.java:4) at androidx.test.espresso.action.GeneralClickAction.perform (GeneralClickAction.java:4) at androidx.test.espresso.ViewInteraction$SingleExecutionViewAction.perform (ViewInteraction.java:2) at androidx.test.espresso.ViewInteraction.doPerform (ViewInteraction.java:23) at androidx.test.espresso.ViewInteraction.-$$Nest$mdoPerform (Unknown Source) at androidx.test.espresso.ViewInteraction$1.call (ViewInteraction.java:6) at androidx.test.espresso.ViewInteraction$1.call (ViewInteraction.java:1) at java.util.concurrent.FutureTask.run (FutureTask.java:266) at android.os.Handler.handleCallback (Handler.java:938) at android.os.Handler.dispatchMessage (Handler.java:99) at android.os.Looper.loopOnce (Looper.java:201) at android.os.Looper.loop (Looper.java:288) at android.app.ActivityThread.main (ActivityThread.java:7839) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1003)

tsnguyenducphuong avatar Nov 21 '24 10:11 tsnguyenducphuong

Here is a package based on #2759: https://firebasestorage.googleapis.com/v0/b/start-react-native.appspot.com/o/tmp%2Freact-native-skia-test.tgz?alt=media&token=3e153a04-bea9-4404-acf6-d869ac5d05ba Could someone test it? I would appreciate it very much šŸ™

wcandillon avatar Nov 21 '24 14:11 wcandillon

v1.5.7 is published, I would love to get a read on whether it is improving Android stability?

wcandillon avatar Nov 21 '24 14:11 wcandillon

Thanks @wcandillon I use 1.5.7 and it works fine now on my Android 14 phone

tsnguyenducphuong avatar Nov 21 '24 16:11 tsnguyenducphuong

closing based on https://github.com/Shopify/react-native-skia/issues/1982#issuecomment-2491795834

wcandillon avatar Nov 21 '24 17:11 wcandillon

I confirm that it works on 1.5.7, thank you @wcandillon!

TomCorvus avatar Nov 22 '24 06:11 TomCorvus

@wcandillon just tested and it works for me too 🄳 Thanks for picking this up so quickly <3

TomAtterton avatar Nov 22 '24 12:11 TomAtterton