[Bugfix, UE4] SensorData's frame, timestamp and transform are wrong for camera sensors #8935
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After migrating an internal tool from CARLA 0.9.13 to 0.9.15, I noticed that there is an issue with the metadata, that comes with
SensorData
in 0.9.15.For camera-based sensors, the
frame
,timestamp
andtransform
do not correspond to the actual image, which is a quite severe issue for things like sensor fusion (since we cannot reliably synchronize different sensors) or for 3D reconstruction (where accurate transforms are necessary).I created a minimal script sensor_metadata_test.zip , that showcases this problem. It spawns a camera and moves it along the x-axis by one meter per tick for ten ticks. It then logs the frame, timestamp and x-position of the sensor according to the
WorldSnapshot
and according to the receivedSensorData
. The images are also stored on disk, so that they can be inspected.The script can be executed at least from 0.9.13 to the current
ue4-dev
branch and shows the differences in what theSensorData
states about the sensor:0.9.13
In 0.9.13, everything is as expected (on Linux and Windows). Frame, timestamp and x-position are identically reported by
WorldSnapshot
andSensorData
. The stored images also show, that the camera moves every frame by one step.Timing results (0.9.13)
0.9.15
In 0.9.15,
WorldSnapshot
is again as expected butSensorData
returns wrong values. On Linux, I get an offset of 1 frame quite consistently, which also affects the timestamp and transform. On Windows, the problem is even worse, where duplicate frames, timestamps and x-positions occur, or are skipped. The stored images still show, that the camera moves every frame by one step, i.e. the images are at least correct but are associated with wrong metadata.Is also tested on the current
ue4-dev
branch and the issue is still existing.Timing results (0.9.15)
Problem
I digged into the history of the sensor data streaming code and found, that the issue probably arose from the changes in this commit. As the comment in PixelReader.h is stating, the creation of the stream as part of the lambda's closure would still be executed in the game-thread, resulting in accurate values from frame, timestamp and sensor transform when instantiating the
FAsyncDataStreamTmpl
here. But the mentioned change is actually violating this assumption, since the creation of the stream is now part of the lambda, which will be asynchronously executed on the render thread. Thus, the metadata can be queried to late, resulting in associating wrong frame, timestamp and transform with the sensor data that will be send.Solution
I was not sure about the actual reason to move the creation of the stream from the closure into the lambda, but when reverting this, CARLA actually crashed when spawning and listening to a sensor. So I left the stream untouched and implemented a very easy solution:
FDataStreamTmpl
(as it already exists for the frame)If there might be a more clever fix, please let me know. But with this implementation, the timings are now correct again (this time only tested on Windows):
Timing results (after fix)
0.10.0
From what I see, this issue should also exist in 0.10.0: PixelReader.h @ ue5-dev
Since I am currently not working with 0.10.0, maybe someone from the CARLA team might think about porting this PR to
ue5-dev
(if it is accepted as is).Where has this been tested?
This change is