mosra / magnum-examples

Examples for the Magnum C++11 graphics engine
https://magnum.graphics/
The Unlicense
282 stars 95 forks source link

[Octree] Properly remove invalid points from nodes. #99

Closed grishavanika closed 2 years ago

grishavanika commented 3 years ago

Hello.

Was looking at Octree example and I think I got it right. In removeInvalidPointsFromNodes(), line 294 - last element we swap with can also be invalid and, as result, skipped. Without this change, after call to incrementalUpdate() there are points duplicates.

I simply put remove_if. Hope that makes sense. On my PC, release build, without vsync, this improves CPU perf 2x with default options.

mosra commented 3 years ago

Hi!

Sorry for an extremely late reply -- was busy elsewhere. This indeed seems like a bug, thanks for catching and fixing it!

Looking at the code, the root cause seems to be the lack of arrayRemove() APIs in the library, which is why the buggy swap-remove code was added in the first place. I'll postpone the fix until arbitrary array insertion and removal implemented in Corrade, that should make the code cleaner overall.

Thanks again!