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

unity crash with addUnityViewToGroup

Open soronto3603 opened this issue 3 years ago • 5 comments

Hello.

Thank you for your great work. I've build your example successfully. but It's crashed. unity load is successfully load at first. but almost next load was crashed.

https://user-images.githubusercontent.com/22703602/167987171-13875d0e-8b25-4625-bc25-299569d4e7b9.mp4

2022-05-12 12:38:19.515 5764-5764/com.example E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example, PID: 5764
    java.lang.Error: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    Version '2021.3.2f1 (d6360bedb9a0)', Build type 'Release', Scripting Backend 'il2cpp', CPU 'armeabi-v7a'
    Build fingerprint: 'samsung/z3qksx/z3q:12/SP1A.210812.016/G988NKSU1GVC7:user/release-keys'
    Revision: '15'
    ABI: 'arm'
    Timestamp: 2022-05-12 12:38:15+0900
    pid: 5764, tid: 7694, name: UnityGfxDeviceW  >>> com.example <<<
    uid: 10041
    signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x8
    Cause: null pointer dereference
        r0  ad24a330  r1  00000008  r2  00000087  r3  00000000
        r4  ace17b70  r5  00000040  r6  ace112c0  r7  ae28e150
        r8  ad24a330  r9  ffffffff  r10 ace2e200  r11 00000001
        ip  00000000  sp  a5e6be80  lr  af9c6278  pc  af9c729c
    
    backtrace:
          #00 pc 0041829c  /data/app/~~VQI66LEWJupqVrg2ybOXWw==/com.example-ruYKx-EqLVTGo54fpqT4YQ==/lib/arm/libunity.so (BuildId: 9faa1e7e16a9e71bb4a70ee16bbc3bad4e940f05)
          #01 pc 00429608  /data/app/~~VQI66LEWJupqVrg2ybOXWw==/com.example-ruYKx-EqLVTGo54fpqT4YQ==/lib/arm/libunity.so (BuildId: 9faa1e7e16a9e71bb4a70ee16bbc3bad4e940f05)
          #02 pc 0040969c  /data/app/~~VQI66LEWJupqVrg2ybOXWw==/com.example-ruYKx-EqLVTGo54fpqT4YQ==/lib/arm/libunity.so (BuildId: 9faa1e7e16a9e71bb4a70ee16bbc3bad4e940f05)
          #03 pc 00403f20  /data/app/~~VQI66LEWJupqVrg2ybOXWw==/com.example-ruYKx-EqLVTGo54fpqT4YQ==/lib/arm/libunity.so (BuildId: 9faa1e7e16a9e71bb4a70ee16bbc3bad4e940f05)
          #04 pc 00403da0  /data/app/~~VQI66LEWJupqVrg2ybOXWw==/com.example-ruYKx-EqLVTGo54fpqT4YQ==/lib/arm/libunity.so (BuildId: 9faa1e7e16a9e71bb4a70ee16bbc3bad4e940f05)
          #05 pc 0049a593  /data/app/~~VQI66LEWJupqVrg2ybOXWw==/com.example-ruYKx-EqLVTGo54fpqT4YQ==/lib/arm/libunity.so (BuildId: 9faa1e7e16a9e71bb4a70ee16bbc3bad4e940f05)
          #06 pc 004a096f  /data/app/~~VQI66LEWJupqVrg2ybOXWw==/com.example-ruYKx-EqLVTGo54fpqT4YQ==/lib/arm/libunity.so (BuildId: 9faa1e7e16a9e71bb4a70ee16bbc3bad4e940f05)
          #07 pc 0049a097  /data/app/~~VQI66LEWJupqVrg2ybOXWw==/com.example-ruYKx-EqLVTGo54fpqT4YQ==/lib/arm/libunity.so (BuildId: 9faa1e7e16a9e71bb4a70ee16bbc3bad4e940f05)
          #08 pc 00161c8b  /data/app/~~VQI66LEWJupqVrg2ybOXWw==/com.example-ruYKx-EqLVTGo54fpqT4YQ==/lib/arm/libunity.so (BuildId: 9faa1e7e16a9e71bb4a70ee16bbc3bad4e940f05)
          #09 pc 000802e7  /apex/com.android.runtime/lib/bionic/libc.so (pthread_attr_destroy+6) (BuildId: 5fd652727ca3edbb2b9609b35cb5811f)
    
        at libunity.0x41829c(Native Method)
        at libunity.0x429608(Native Method)
        at libunity.0x40969c(Native Method)
        at libunity.0x403f20(Native Method)
        at libunity.0x403da0(Native Method)
        at libunity.0x49a593(Native Method)
        at libunity.0x4a096f(Native Method)
        at libunity.0x49a097(Native Method)
        at libunity.0x161c8b(Native Method)
        at libc.pthread_attr_destroy(pthread_attr_destroy:6)

I found error line.

// ReactNativeUnity.java
...
public static void addUnityViwToGroup(ViewGroup group) {
        if (unityPlayer == null) {
            return;
        }
        if (unityPlayer.getParent() != null) {
            ((ViewGroup) unityPlayer.getParent()).removeView(unityPlayer);
        }
        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT);
        group.addView(unityPlayer, 0, layoutParams);
        unityPlayer.windowFocusChanged(true);
        unityPlayer.requestFocus();
        unityPlayer.resume(); // < -- here
}
...

It was load successfully when I remove the line.

+------- I was known it load successfully. but it was unloaded state.

soronto3603 avatar May 12 '22 03:05 soronto3603

@soronto3603 Did you find a fix for the crash on second load?

ROBYER1 avatar Jul 22 '22 19:07 ROBYER1

**Edit: Ignore this, the fix didn't work for me either, I'm still stuck.

Have you submitted a PR for this or closing this issue because the fix is to comment out the line you pointed out at the bottom. I wasted hours of my day trying to look into this issue to realise you already said what fixed it.

ROBYER1 avatar Jul 22 '22 23:07 ROBYER1

I am facing the same issue. I am using a Mac M1. Is there a solution except commenting out unityPlayer.resume(); ?

When I commented out resume() it doesn't crash but the game is frozen.

It seems that it doesn't happen using the example project. Maybe it's a matter of our different navigation lib. I am using react-native-navigation. In addition, I 'd like to note that after the first unity load I can see the android status bar switches to white: Before unity load Screenshot 2023-05-24 at 2 53 22 PM

After unity load (while on unity screen) Screenshot 2023-05-24 at 2 53 54 PM

After unity has been loaded once and then I return to Main screen Screenshot 2023-05-24 at 2 54 06 PM

entelostre avatar May 25 '23 16:05 entelostre

Hello @entelostre. I couldn't find any solution.

soronto3603 avatar May 26 '23 01:05 soronto3603

Hey @soronto3603 thanks for your interest. So you mean you get the same result as me (frozen player on second load) after commenting out that resume() call?

entelostre avatar May 26 '23 08:05 entelostre