Raptor007 / X-Wing-Revival

X-Wing combat space flight simulator (uses RaptorEngine).
https://www.raptor007.com/x-wing-revival/
12 stars 4 forks source link

Fix collision detection on Linux/Mac #15

Closed Raptor007 closed 2 months ago

Raptor007 commented 3 months ago

Sometimes flying near a capital ship without actually touching it causes a fighter to explode, including player ships.

For some reason, this does not seem to effect games hosted by the Windows version.

The dedicated server is Linux, so this currently effects "Fly Online" games. Keep your distance (but don't look like you're keeping your distance).

Raptor007 commented 3 months ago

This seems to be a problem with sv threads on those platforms, so I've disabled that feature on the dedicated server for now.

Strangely even with sv threads 6 the problem does not appear on Windows.

Raptor007 commented 3 months ago

Okay, it gets stranger: The problem occurs on Mac OS X with or without sv threads, on Linux only with sv threads, and never on Windows.

Raptor007 commented 3 months ago

Current best guess is that my ModelArrays copy constructor and/or destructor are not behaving as expected if std::vector< std::pair< ModelArrays, std::string > > has to internally resize its storage when adding new pairs. This would explain why it behaves so inconsistently across platforms.

Replacing with std::pair< ModelArrays*, std::string > using new/delete seems to have solved the problem without impairing performance. Just need to make this hasn't introduced any memory leaks.

Raptor007 commented 3 months ago

One minor leak found and fixed: ModelArrays::Resize was not setting Allocated upon first resizing from 0. (It was expecting BecomeCopy to do it, but that doesn't happen if there are no arrays allocated yet.) Zero leaks detected after fixing this.

This bug fix is now live on the dedicated server.

Raptor007 commented 2 months ago

Found and fixed some additional issues that effected all platforms, such as picking too small of a block size when detecting collisions between two fast-moving starfighters.