Skip to content

Commit e242c3e

Browse files
authored
Merge pull request #178 from vmc-motion/fix/avoid-potential-shutdown-crash
Fix to avoid potential shutdown crash
2 parents 41f3971 + 5d0a83a commit e242c3e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Source/ROSIntegration/Private/ROSIntegrationGameInstance.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
#include "Kismet/GameplayStatics.h"
99

1010

11+
static void UnsubscribeAndUnadvertiseAllTopics()
12+
{
13+
for (TObjectIterator<UTopic> It; It; ++It)
14+
{
15+
UTopic* Topic = *It;
16+
Topic->Unadvertise(); // to make sure all topics are unadvertised on ROS side
17+
Topic->Unsubscribe(); // to prevent messages arriving during shutdown from triggering subscription callbacks
18+
Topic->MarkAsDisconnected();
19+
}
20+
}
21+
1122
static void MarkAllROSObjectsAsDisconnected()
1223
{
1324
for (TObjectIterator<UTopic> It; It; ++It)
@@ -187,6 +198,7 @@ void UROSIntegrationGameInstance::Shutdown()
187198
FWorldDelegates::OnWorldTickStart.RemoveAll(this);
188199
}
189200

201+
UnsubscribeAndUnadvertiseAllTopics(); // make sure no subscription callbacks are fired during shutdown
190202
MarkAllROSObjectsAsDisconnected(); // moved here from UROSIntegrationGameInstance::BeginDestroy()
191203

192204
UE_LOG(LogROS, Display, TEXT("ROS Game Instance - shutdown done"));

0 commit comments

Comments
 (0)