o3de / o3de-extras

Other
58 stars 60 forks source link

Editor with ROS2 gem enabled crash on simulate #705

Closed yosagi closed 2 weeks ago

yosagi commented 3 weeks ago

Describe the bug Editor with ROS2 gem enabled crash on simulate.

Assets required Any project with ROS2 gem added.

Steps to reproduce

  1. Create a project with default template.
  2. Add ROS2 gem in "configure gems".
  3. Build the project.
  4. Open the project in a Editor.
  5. Create or open any level.
  6. Press simulate button on top right corner on the Editor.
  7. The editor crashes with SIGSEGV.

Expected behavior No crash.

Actual behavior Crash.

Screenshots/Video The following is a first few lines of backtrace on gdb session.

Module: Success!
[New Thread 0x7ffdb07f8640 (LWP 295626)]
[New Thread 0x7ffdb05f7640 (LWP 295627)]
[Detaching after fork from child process 295628]
[New Thread 0x7ffd7ae4b640 (LWP 295630)]

Thread 1 "Editor" received signal SIGSEGV, Segmentation fault.
ROS2::ROS2SystemComponent::Deactivate (this=0x555558d40250) at /mnt/data/yos/work/upstream/o3de-extras/Gems/ROS2/Code/Source/ROS2SystemComponent.cpp:172
warning: Source file is more recent than executable.
172             m_simulationClock->Deactivate();
(gdb) bt
#0  ROS2::ROS2SystemComponent::Deactivate (this=0x555558d40250) at /mnt/data/yos/work/upstream/o3de-extras/Gems/ROS2/Code/Source/ROS2SystemComponent.cpp:172
#1  0x00007fff010184ba in non-virtual thunk to ROS2::ROS2EditorSystemComponent::OnStopPlayInEditor() ()
    at /mnt/data/yos/work/upstream/o3de-extras/Gems/ROS2/Code/Source/ROS2EditorSystemComponent.cpp:66
#2  0x00007ffff3291ea2 in void AZ::Internal::EBusContainer<AzToolsFramework::EditorEntityContextNotification, AzToolsFramework::EditorEntityContextNotification, (AZ::EBusAddressPolicy)0, (AZ::EBusHandlerPolicy)1>::Dispatcher<AZ::EBus<AzToolsFramework::EditorEntityContextNotification, AzToolsFramework::EditorEntityContextNotification> >::Broadcast<void (AzToolsFramework::EditorEntityContextNotification::*)()>(void (AzToolsFramework::EditorEntityContextNotification::*&&)()) ()
   from /mnt/data/yos/work/upstream/o3de/install-phy5/bin/Linux/profile/Default/libEditorLib.so
#3  0x00007ffff3281db9 in AzToolsFramework::EditorEntityContextComponent::StopPlayInEditor() ()
   from /mnt/data/yos/work/upstream/o3de/install-phy5/bin/Linux/profile/Default/libEditorLib.so
#4  0x00007ffff3281e4a in non-virtual thunk to AzToolsFramework::EditorEntityContextComponent::StopPlayInEditor() ()
   from /mnt/data/yos/work/upstream/o3de/install-phy5/bin/Linux/profile/Default/libEditorLib.so
#5  0x00007ffff1b54a6d in void AZ::Internal::EBusContainer<AzToolsFramework::EditorEntityContextRequests, AzToolsFramework::EditorEntityContextRequests, (AZ::EBusAddressPolicy)0, (AZ::EBusHandlerPolicy)0>::Dispatcher<AZ::EBus<AzToolsFramework::EditorEntityContextRequests, AzToolsFramework::EditorEntityContextRequests> >::Broadcast<void (AzToolsFramework::EditorEntityContextRequests::*)()>(void (AzToolsFramework::EditorEntityContextRequests::*&&)()) () from /mnt/data/yos/work/upstream/o3de/install-phy5/bin/Linux/profile/Default/libEditorLib.so
#6  0x00007ffff1b4e645 in CGameEngine::SetSimulationMode(bool, bool) () from /mnt/data/yos/work/upstream/o3de/install-phy5/bin/Linux/profile/Default/libEditorLib.so
#7  0x00007ffff1cfea32 in CCryEditApp::OnSwitchPhysics() () from /mnt/data/yos/work/upstream/o3de/install-phy5/bin/Linux/profile/Default/libEditorLib.so

Found in Branch 2310.3 on both o3de and o3de-extras

Commit ID from o3de/o3de and o3de/o3de-extras repositories

o3de-extras: a30c72f7668c39d138f83754ebe128b1fad5beed (2310.3) o3de: 1577b1e742358461d8b2e6cfafd937637315c9d5 (2310.3)

I can't test this issue on development branch because I cannot build any project with ROS2 gem enabled on them. (I could't find PhysX5 Gem stated on ROS2/gem.json on development branch)

Desktop/Device (please complete the following information):

Additional context According to the comment found here, the EndPlayInEditor event may be called without a prior call to StartPlayInEditor. However, ROS2SystemComponent::Deactivate function cannot be called if Activate was not called beforehand. This is because several members such as m_simulationClock are not available without Activate call.

Possible fix: https://github.com/yosagi/o3de-extras/commit/bd86a9bc1cf50b63ac70001d56851ad2d2f6bf0c

jhanca-robotecai commented 3 weeks ago

Thank you for raising the issue. I will try to replicate it on my setup.

In the meanwhile please find an answer for your comment below:

I can't test this issue on development branch because I cannot build any project with ROS2 gem enabled on them. (I could't find PhysX5 Gem stated on ROS2/gem.json on development branch)

As of today (2310.3), the PhysX engine is changed based on the compile flag - it is PhysX4 by default and PhysX5 when requested with compile flag -DAZ_USE_PHYSX5:=ON. In case of any newer code (stabilization/2409 or development), PhysX4 and PhysX5 are available as Gems, hence can be changed without rebuilding the whole codebase. You need to match versions of o3de-extras with o3de. Personally, I use the newest development branch from o3de-extras with stabilization/2409 branch from o3de.

yosagi commented 3 weeks ago

Thank you for your comment. I have managed to build using the develop branch and I was able to reproduce this issue.

o3de: 8fb30d990acc08bb2f83b78724d1ca22f739bf4b o3de-extrans: d6e6f5ccd520fd10018c3ea3991bf9c7f284ebe5

adamdbrw commented 3 weeks ago

@yosagi thank you for raising the issue. It should be straightforward to fix and points to an untested case as we only use "Play" to run simulations.

I am curious about your use-case if you would like to share, as obviously this was not tried before.

michalpelka commented 3 weeks ago

Hello, I can confirm that have a crash on simulate-in-editor usage scenario. I will investigate and test your proposed solution @yosagi ! I've tested stabilization/2409 branch

michalpelka commented 2 weeks ago

The fix is in development.

yosagi commented 1 week ago

Thanks for the fix. I'd like to follow the background a bit. I am a beginner with O3DE and have been exploring various features. I assumed that the Simulate function would be similar to the Simulate feature in Unreal Engine (UE), where the world continues to run without grabbing the mouse and keyboard, allowing navigation through the Editor's UI. However, this does not seem to be the case in O3DE. While I understand that the Editor might not function fully during simulation, is there a way to simulate the world without grabbing the mouse and keyboard?

jhanca-robotecai commented 1 week ago

While I understand that the Editor might not function fully during simulation, is there a way to simulate the world without grabbing the mouse and keyboard?

I fully understand your problem, as we have been facing it for a while. O3DE was primarily designed as a game engine assuming that the mouse and keyboard belong to the game when turned on (i.e. when the game mode is turned on). It was only later that the game engine became a simulation engine. I do not have much experience with Unreal, but I can say for sure that O3DE tries to separate Editor from the Gameplay as much as possible. This is the reason why Editor is not usable in the Gameplay.

We used to change some things in the O3DE code to be sure the mouse was always available and very recently we decided to add a proper solution: https://github.com/o3de/o3de/pull/18042 This is primarily meant for the situations, in which we use O3DE to simulate sensors and to visualize the scene. When this happens, we use the keyboard and mouse inputs to play with Foxglove/RViz or a terminal to interface with ROS2. In short: this code unlocks the mouse and keyboard, but mainly for other apps. The Editor stays unusable.

The code is already merged to development branch and we will cherry-pick it into stabilization to enable it in the next release (planned for the first week of October). You could cherry-pick it to your solution in case you build the code from source.