diff --git a/AirLib/include/common/common_utils/Signal.hpp b/AirLib/include/common/common_utils/Signal.hpp index a3f550c971..1eea59077b 100644 --- a/AirLib/include/common/common_utils/Signal.hpp +++ b/AirLib/include/common/common_utils/Signal.hpp @@ -81,8 +81,9 @@ class Signal { // calls all connected functions void emit(Args... p) { - for (auto it : slots_) { - it.second(p...); + for(auto it=slots_.begin(); it!=slots_.end(); ) { + // Increment here so that the entry can be erased from inside the method as well + (it++)->second(p...); } } diff --git a/Unreal/Plugins/AirSim/Source/Vehicles/Multirotor/FlyingPawn.cpp b/Unreal/Plugins/AirSim/Source/Vehicles/Multirotor/FlyingPawn.cpp index a41677abf6..493eba77da 100644 --- a/Unreal/Plugins/AirSim/Source/Vehicles/Multirotor/FlyingPawn.cpp +++ b/Unreal/Plugins/AirSim/Source/Vehicles/Multirotor/FlyingPawn.cpp @@ -45,6 +45,9 @@ void AFlyingPawn::EndPlay(const EEndPlayReason::Type EndPlayReason) camera_back_center_ = nullptr; camera_bottom_center_ = nullptr; + pawn_events_.getActuatorSignal().disconnect_all(); + rotating_movements_.Empty(); + Super::EndPlay(EndPlayReason); }