Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug 1.0.0-pre15 scheduling an IBodyPairsJob leads to a crash on android

Discussion in 'Physics for ECS' started by Occuros, Feb 16, 2023.

  1. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    300
    In our project, we need to modify the physics simulation.

    We use a IBodyPairsJob inside of an ISystem to disable certain collision pairs based on some conditions.

    At startup the applications crashes with:

    Code (CSharp):
    1.  
    2. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime FATAL EXCEPTION: main
    3. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime Process: com.test_company.test_project, PID: 15796
    4. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime java.lang.Error: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    5. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime Version '2022.2.6f1 (10bfa6201ced)', Build type 'Development', Scripting Backend 'il2cpp', CPU 'arm64-v8a'
    6. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime Build fingerprint: 'oculus/hollywood/hollywood:10/QQ3A.200805.001/49882890235800150:user/release-keys'
    7. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime Revision: '0'
    8. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime ABI: 'arm64'
    9. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime Timestamp: 2023-02-16 13:56:19.097950451+0100
    10. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime pid: 15796, tid: 15847, name: Job.worker 1  >>> com.holonautic.test_project_cybrix <<<
    11. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime uid: 10097
    12. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr --------
    13. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime Cause: null pointer dereference
    14. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     x0  00000070c32ce8d0  x1  00000070705b3500  x2  00000000ffffffff  x3  00000070705b3500
    15. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     x4  0000000000000000  x5  0000000000000000  x6  0000000000000000  x7  0000000000000002
    16. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     x8  0000000000000002  x9  00000070f0259e70  x10 00000070705b3550  x11 0000000000000000
    17. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     x12 000000000000003c  x13 0000000000000000  x14 000000000000003b  x15 0000000000000001
    18. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     x16 00000071305e3e98  x17 0000007215117490  x18 0000007122efe000  x19 0000000000000000
    19. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     x20 00000000ffffffff  x21 00000070705b3480  x22 00000070705b3500  x23 00000070c32ce8d0
    20. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     x24 0000000000000000  x25 00000071306b2240  x26 00000070c096bd80  x27 0000000000008100
    21. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     x28 0000000000000a13  x29 0000000000000000
    22. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     lr  000000712eebf41c  sp  0000007123700770  pc  000000712eebe3c8  pst 0000000080001000
    23. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime
    24. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime backtrace:
    25. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime       #00 pc 0000000000d373c8  /data/app/com.holonautic.test_project_cybrix-lfl82ZsxfOJANHfy9ospbw==/lib/arm64/libunity.so (PatchListToArray(JobReflectionData const&, unsigned char*)+48) (BuildId: e552a8cc26a6fe3f)
    26. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime       #01 pc 0000000000d38418  /data/app/com.holonautic.test_project_cybrix-lfl82ZsxfOJANHfy9ospbw==/lib/arm64/libunity.so (ExecuteJob(ManagedJobData*, void (*)(void*, void*, void*, void*, int), int, unsigned char*)+164) (BuildId: e552a8cc26a6fe3f)
    27. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime       #02 pc 0000000000d37698  /data/app/com.holonautic.test_project_cybrix-lfl82ZsxfOJANHfy9ospbw==/lib/arm64/libunity.so (ForwardJobToManaged(ManagedJobData*)+84) (BuildId: e552a8cc26a6fe3f)
    28. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime       #03 pc 0000000000d35b14  /data/app/com.holonautic.test_project_cybrix-lfl82ZsxfOJANHfy9ospbw==/lib/arm64/libunity.so (ujob_execute_job(ujob_control_t*, ujob_lane_t*, ujob_job_t*, ujob_handle_t, int)+360) (BuildId: e552a8cc26a6fe3f)
    29. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime       #04 pc 0000000000d35ee0  /data/app/com.holonautic.test_project_cybrix-lfl82ZsxfOJANHfy9ospbw==/lib/arm64/libunity.so (lane_guts(ujob_control_t*, ujob_lane_t*, int, int)+672) (BuildId: e552a8cc26a6fe3f)
    30. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime       #05 pc 0000000000d36550  /data/app/com.holonautic.test_project_cybrix-lfl82ZsxfOJANHfy9ospbw==/lib/arm64/libunity.so (worker_thread_routine(void*)+136) (BuildId: e552a8cc26a6fe3f)
    31. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime       #06 pc 0000000001057328  /data/app/com.holonautic.test_project_cybrix-lfl82ZsxfOJANHfy9ospbw==/lib/arm64/libunity.so (Thread::RunThreadWrapper(void*)+1052) (BuildId: e552a8cc26a6fe3f)
    32. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime       #07 pc 00000000000d5c44  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+36) (BuildId: 76160b7be02961a2e357c92bde57eb19)
    33. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime       #08 pc 0000000000082fe4  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 76160b7be02961a2e357c92bde57eb19)
    34. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime
    35. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     at libunity.PatchListToArray(JobReflectionData const&, unsigned char*)(PatchListToArray:48)
    36. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     at libunity.ExecuteJob(ManagedJobData*, void (*)(void*, void*, void*, void*, int), int, unsigned char*)(ExecuteJob:164)
    37. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     at libunity.ForwardJobToManaged(ManagedJobData*)(ForwardJobToManaged:84)
    38. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     at libunity.ujob_execute_job(ujob_control_t*, ujob_lane_t*, ujob_job_t*, ujob_handle_t, int)(ujob_execute_job:360)
    39. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     at libunity.lane_guts(ujob_control_t*, ujob_lane_t*, int, int)(lane_guts:672)
    40. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     at libunity.worker_thread_routine(void*)(worker_thread_routine:136)
    41. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     at libunity.Thread::RunThreadWrapper(void*)(RunThreadWrapper:1052)
    42. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     at libc.__pthread_start(void*)(__pthread_start:36)
    43. 2023/02/16 13:56:56.083 15796 15796 Error AndroidRuntime     at libc.__start_thread(__start_thread:64)
    44.  


    We disabled all other systems, and this is the only one running, if we don't schedule the job, the application starts normally.

    The job itself has an empty execute method and the scheduling is done in the following way:


    Code (CSharp):
    1.            
    2. var disablingJob = new DisablingJob
    3. {
    4. };
    5.  
    6. var simulationSingleton = SystemAPI.GetSingleton<SimulationSingleton>();
    7. var worldSingleton = SystemAPI.GetSingleton<PhysicsWorldSingleton>();
    8.  
    9.  
    10. state.Dependency = disablingJob.Schedule(
    11.     simulationSingleton,
    12.     ref worldSingleton.PhysicsWorld,
    13.     state.Dependency);
    14.  
     
  2. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    300
    The issue can be reproduced in the official samples repository:

    https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/PhysicsSamples/Assets/Demos/5. Modify/5j. Modify Broadphase Pairs

    Steps to reproduce:

    - only build the example 5j
    - Modify the: ModifyBroadphasePairsBehaviour.cs, and comment out everything inside the `OnCreate`


    Code (CSharp):
    1. // state.RequireForUpdate(state.GetEntityQuery(ComponentType.ReadOnly<ModifyBroadphasePairs>()));
    Run it in editor: No issues
    Build it for android (Quest 2 preferably), and it has a NullPointerDereference exception.

    Bug report was submitted under: IN-32963
     
  3. JMPM-UNITY

    JMPM-UNITY

    Unity Technologies

    Joined:
    Jun 16, 2021
    Posts:
    93
    Hey @Occuros, thank you for reporting this bug crash. I will have a look at it asap!
     
    thurd666 and Occuros like this.
  4. JMPM-UNITY

    JMPM-UNITY

    Unity Technologies

    Joined:
    Jun 16, 2021
    Posts:
    93
    Regarding the physicsSamples, if you comment out everything inside the `OnCreate` I also get the errors with the subscene closed:
    Code (CSharp):
    1. NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object
    2. This Exception was thrown from a function compiled with Burst, which has limited exception support.
    3. #3 Unity.Physics.IBodyPairsJobExtensions.ScheduleUnityPhysicsBodyPairsJob<ModifyBroadphasePairsSystem.DisablePairsJob>(ModifyBroadphasePairsSystem.DisablePairsJob jobData, Unity.Physics.Simulation simulation, ref Unity.Physics.PhysicsWorld world, Unity.Jobs.JobHandle inputDeps) -> Unity.Jobs.JobHandle_4480d00f65928b44256cd769a6d940db from Havok.Physics, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
    4. #4 Unity.Physics.IHavokBodyPairsJobExtensions.Schedule<ModifyBroadphasePairsSystem.DisablePairsJob>(ModifyBroadphasePairsSystem.DisablePairsJob jobData, Unity.Physics.SimulationSingleton simulationSingleton, ref Unity.Physics.PhysicsWorld world, Unity.Jobs.JobHandle inputDeps) -> Unity.Jobs.JobHandle_4480d00f65928b44256cd769a6d940db from Unity.Physics.Samples, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
    5. #5 ModifyBroadphasePairsSystem.OnUpdate(ModifyBroadphasePairsSystem* this, ref Unity.Entities.SystemState state) -> void_4480d00f65928b44256cd769a6d940db from Unity.Physics.Samples, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
    6. #6 8039593d847515cc112d26660f471a2a
    7. #7 Unity.Entities.WorldUnmanagedImpl.Unity.Entities.UnmanagedUpdate_00001545$BurstDirectCall.Invoke(void* pSystemState) -> void_4480d00f65928b44256cd769a6d940db from Unity.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
    8. #8 7bf3b3dc1c88cb657fd69b548232391d
    9. #9  (Mono JIT Code) (wrapper managed-to-native) Unity.Entities.WorldUnmanagedImpl/Unity.Entities.UnmanagedUpdate_00001545$BurstDirectCall:wrapper_native_indirect_0x7febe343c1a0 (intptr&,void*)
    10. #10  (Mono JIT Code) [ComponentSystemGroup.cs:702] Unity.Entities.ComponentSystemGroup:UpdateAllSystems ()
    11. #11  (Mono JIT Code) [ComponentSystemGroup.cs:666] Unity.Entities.ComponentSystemGroup:OnUpdate ()
    12. #12  (Mono JIT Code) [ComponentSystemGroup.cs:710] Unity.Entities.ComponentSystemGroup:UpdateAllSystems ()
    13. #13  (Mono JIT Code) [ComponentSystemGroup.cs:666] Unity.Entities.ComponentSystemGroup:OnUpdate ()
    14. #14  (Mono JIT Code) [ComponentSystemGroup.cs:710] Unity.Entities.ComponentSystemGroup:UpdateAllSystems ()
    15. #15  (Mono JIT Code) [ComponentSystemGroup.cs:670] Unity.Entities.ComponentSystemGroup:OnUpdate ()
    16. #16  (Mono JIT Code) [ComponentSystemGroup.cs:710] Unity.Entities.ComponentSystemGroup:UpdateAllSystems ()
    17. #17  (Mono JIT Code) [ComponentSystemGroup.cs:666] Unity.Entities.ComponentSystemGroup:OnUpdate ()
    18. #18  (Mono JIT Code) [ScriptBehaviourUpdateOrder.cs:528] Unity.Entities.ScriptBehaviourUpdateOrder/DummyDelegateWrapper:TriggerUpdate ()
    19. #19 mono_jit_runtime_invoke
    20. #20 do_runtime_invoke
    21. #21 mono_runtime_invoke
    22. #22 scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool)
    23. #23 ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool)
    24. #24 ExecutePlayerLoop(NativePlayerLoopSystem*)
    25. #25 ExecutePlayerLoop(NativePlayerLoopSystem*)
    26. #26 PlayerLoop()
    27. #27 EditorPlayerLoop::Execute()
    28. #28 PlayerLoopController::InternalUpdateScene(bool, bool)
    29. #29 PlayerLoopController::UpdateSceneIfNeededFromMainLoop()
    30. #30 Application::TickTimer()
    31. #31 -[EditorApplication TickTimer]
    32. #32 __NSFireTimer
    33. #33 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
    34. #34 __CFRunLoopDoTimer
    35. #35 __CFRunLoopDoTimers
    36. #36 __CFRunLoopRun
    37. #37 CFRunLoopRunSpecific
    38. #38 RunCurrentEventLoopInMode
    39. #39 ReceiveNextEventCommon
    40. #40 _BlockUntilNextEventMatchingListInModeWithFilter
    41. #41 _DPSNextEvent
    42. #42 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
    43. #43 -[EditorApplication checkForFocusChange:]
    44. #44 __NSFireTimer
    45. #45 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
    46. #46 __CFRunLoopDoTimer
    47. #47 __CFRunLoopDoTimers
    48. #48 __CFRunLoopRun
    49. #49 CFRunLoopRunSpecific
    50. #50 RunCurrentEventLoopInMode
    51. #51 ReceiveNextEventCommon
    52. #52 _BlockUntilNextEventMatchingListInModeWithFilter
    53. #53 _DPSNextEvent
    54. #54 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
    55. #55 -[NSApplication run]
    56. #56 NSApplicationMain
    57. #57 EditorMain(int, char const**)
    58. #58 main
    59. #59 start
    60.  
    61. Unity.Entities.WorldUnmanagedImpl+UnmanagedUpdate_00001545$BurstDirectCall.Invoke (System.Void* pSystemState) (at <37db26e6bc024dee81d19ea05d9aab14>:0)
    62. Unity.Entities.WorldUnmanagedImpl.UnmanagedUpdate (System.Void* pSystemState) (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/WorldUnmanaged.cs:810)
    63. Unity.Entities.WorldUnmanagedImpl.UpdateSystem (Unity.Entities.SystemHandle sh) (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/WorldUnmanaged.cs:895)
    64. Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/ComponentSystemGroup.cs:702)
    65. UnityEngine.Debug:LogException(Exception)
    66. Unity.Debug:LogException(Exception) (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/Stubs/Unity/Debug.cs:19)
    67. Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/ComponentSystemGroup.cs:713)
    68. Unity.Entities.ComponentSystemGroup:OnUpdate() (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/ComponentSystemGroup.cs:666)
    69. Unity.Entities.SystemBase:Update() (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/SystemBase.cs:418)
    70. Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/ComponentSystemGroup.cs:708)
    71. Unity.Entities.ComponentSystemGroup:OnUpdate() (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/ComponentSystemGroup.cs:666)
    72. Unity.Entities.SystemBase:Update() (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/SystemBase.cs:418)
    73. Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/ComponentSystemGroup.cs:708)
    74. Unity.Entities.ComponentSystemGroup:OnUpdate() (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/ComponentSystemGroup.cs:672)
    75. Unity.Entities.SystemBase:Update() (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/SystemBase.cs:418)
    76. Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/ComponentSystemGroup.cs:708)
    77. Unity.Entities.ComponentSystemGroup:OnUpdate() (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/ComponentSystemGroup.cs:666)
    78. Unity.Entities.SystemBase:Update() (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/SystemBase.cs:418)
    79. Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at /Users/josep.pujol/Desktop/dots/Packages/com.unity.entities/Unity.Entities/ScriptBehaviourUpdateOrder.cs:526)
    80.  
     
    thurd666 and Occuros like this.
  5. thurd666

    thurd666

    Joined:
    May 12, 2022
    Posts:
    7
    I have a very similar error and managed to isolate it to just one line in my System:
    AsteroidSpawnerComponent asteroidSpawner = SystemAPI.GetSingleton<AsteroidSpawnerComponent>();

    If I leave this line out, I build properly, deploy on Quest 2 and run normally. If I leave it on then I build properly, deploy on Quest 2 and as soon as the app launches I see the first frame rendered but then it crashes.
    I even "emptied" my Component and Baker and it still gives me the error.
    Code (CSharp):
    1.  
    2. public struct AsteroidSpawnerComponent : IComponentData
    3. {
    4.     //public Entity asteroidPrefab;
    5. }
    6.  
    Code (CSharp):
    1. public class AsteroidSpawnerAuthoring : MonoBehaviour
    2. {
    3.     public GameObject asteroidPrefab;
    4. }
    5.  
    6. public class AsteroidSpawnerBaker : Baker<AsteroidSpawnerAuthoring>
    7. {
    8.     public override void Bake(AsteroidSpawnerAuthoring authoring)
    9.     {
    10.         var entity = GetEntity(TransformUsageFlags.Dynamic);
    11.         AddComponent(entity, new AsteroidSpawnerComponent
    12.         {
    13.             //asteroidPrefab = GetEntity(authoring.asteroidPrefab, TransformUsageFlags.Dynamic)
    14.         });
    15.     }
    16. }
    Code (CSharp):
    1.  
    2. public partial class AsteroidSpawnerSystem : SystemBase
    3. {
    4.  
    5.     public void OnCreate(ref SystemState state)
    6.     {
    7.         state.RequireForUpdate<AsteroidSpawnerComponent>();
    8.     }
    9.     protected override void OnUpdate()
    10.     {
    11.         EntityQuery asteroidEntityQuery = EntityManager.CreateEntityQuery(typeof(AsteroidTag));
    12.         // AsteroidSpawnerComponent asteroidSpawner = SystemAPI.GetSingleton<AsteroidSpawnerComponent>();
    13.     }
     
  6. thurd666

    thurd666

    Joined:
    May 12, 2022
    Posts:
    7
    I'm not sure if this is something obvious to people smarter than me or there actually is a problem in GetSingleton implementation but I managed to fix my problem and I'm posting because it might help OP or someone like me in the future.

    Instead of directly going for AsteroidSpawnerComponent through GetSingleton
    Code (CSharp):
    1. AsteroidSpawnerComponent asteroidSpawner = SystemAPI.GetSingleton<AsteroidSpawnerComponent>();
    Doing something like this fixes my issue and now both Play mode and deployment to Quest 2 work flawlessly:
    Code (CSharp):
    1. var asteroidSpawner = SystemAPI.GetSingletonEntity<AsteroidSpawnerComponent>();
    2. var asteroidPrefabData = SystemAPI.GetComponent<AsteroidSpawnerComponent>(asteroidSpawner);
     
    Occuros likes this.