Skip to content

Commit 8822f28

Browse files
committed
fix segmentation API threading issue
1 parent ade76f3 commit 8822f28

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

PythonClient/PythonClient.pyproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<SchemaVersion>2.0</SchemaVersion>
66
<ProjectGuid>e2049e20-b6dd-474e-8bca-1c8dc54725aa</ProjectGuid>
77
<ProjectHome>.</ProjectHome>
8-
<StartupFile>car_collision.py</StartupFile>
8+
<StartupFile>segmentation.py</StartupFile>
99
<SearchPath>
1010
</SearchPath>
1111
<WorkingDirectory>.</WorkingDirectory>

PythonClient/segmentation.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
client = CarClient()
77
client.confirmConnection()
88

9+
AirSimClientBase.wait_key('Press any key to set all object IDs to 0')
10+
found = client.simSetSegmentationObjectID("[\w]*", 0, True);
11+
print("Done: %r" % (found))
12+
13+
AirSimClientBase.wait_key('Press any key to set all object IDs to 0 hard way')
14+
alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
15+
for letter in alphabet:
16+
found = client.simSetSegmentationObjectID(letter+"[\w]*", 0, True);
17+
print("Done: %r" % (found))
18+
919
AirSimClientBase.wait_key('Press any key to change one ground object ID')
1020
found = client.simSetSegmentationObjectID("Ground", 20);
1121
print("Done: %r" % (found))
@@ -14,5 +24,11 @@
1424
found = client.simSetSegmentationObjectID("ground[\w]*", 22, True);
1525
print("Done: %r" % (found))
1626

27+
found = client.simSetSegmentationObjectID("tree[\w]*", 2, True);
28+
found = client.simSetSegmentationObjectID("landscape[\w]*", 200, True);
29+
print("Done: %r" % (found))
30+
31+
32+
1733

1834

Unreal/Plugins/AirSim/Source/Car/CarPawn.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ class ACarPawn::CarApi : public msr::airlib::CarApiBase {
5858
virtual bool simSetSegmentationObjectID(const std::string& mesh_name, int object_id,
5959
bool is_name_regex = false) override
6060
{
61-
return UAirBlueprintLib::SetMeshStencilID(mesh_name, object_id, is_name_regex);
61+
bool success;
62+
UAirBlueprintLib::RunCommandOnGameThread([mesh_name, object_id, is_name_regex, &success]() {
63+
success = UAirBlueprintLib::SetMeshStencilID(mesh_name, object_id, is_name_regex);
64+
}, true);
65+
return success;
6266
}
6367

6468
virtual int simGetSegmentationObjectID(const std::string& mesh_name) override

Unreal/Plugins/AirSim/Source/Multirotor/MultiRotorConnector.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,11 @@ Pose MultiRotorConnector::getPose()
238238
bool MultiRotorConnector::setSegmentationObjectID(const std::string& mesh_name, int object_id,
239239
bool is_name_regex)
240240
{
241-
return UAirBlueprintLib::SetMeshStencilID(mesh_name, object_id, is_name_regex);
241+
bool success;
242+
UAirBlueprintLib::RunCommandOnGameThread([mesh_name, object_id, is_name_regex, &success]() {
243+
success = UAirBlueprintLib::SetMeshStencilID(mesh_name, object_id, is_name_regex);
244+
}, true);
245+
return success;
242246
}
243247

244248
int MultiRotorConnector::getSegmentationObjectID(const std::string& mesh_name)

0 commit comments

Comments
 (0)