FLAMEGPU / FLAMEGPU2-visualiser

Cross platform real-time OpenGL visualiser for FLAMEGPU2 models.
1 stars 2 forks source link

Wrong agent temp disappear when agents are removed #126

Closed Robadob closed 1 year ago

Robadob commented 1 year ago

Running T2, I've noticed at around step 120 the static (red) vehicle starts blinking. My best guess is that this is occurring when vehicles that start behind the static vehicle are killed, the order of vis data is out of sync with the agent count, causing the wrong agent to disappear for a frame. Vis bug!

Did some testing.

Firstly, the below two lines have no reason to use requiredSize, dataSize matches the size of data in the allocated buffer. Rendering required size agents can catch out of date data and cause wrong agent to go missing.

https://github.com/FLAMEGPU/FLAMEGPU2-visualiser/blob/02097b5ca1bf38a52693e926d0d750d972a2ae80/src/flamegpu/visualiser/Visualiser.cpp#L595

After, resolving this the static vehicle only blinked once, however it was consistently when the last other agent was removed.

On reading CUDA graphics interops docs, I clarified that the only possible reason for this is that the code abuses undefined behaviour. Specifically that we're writing data to the CUDA mapped pointer to the GL buffer after it's been unmapped.

I quickly hacked in triple buffering and the problem went away,