kikotheexile / Endless-Sky-Civil-War

A stand alone, content driven Endless Sky fork.
22 stars 17 forks source link

Fix crash when displaying faction flags on macOS #149

Closed lukearndt closed 3 years ago

lukearndt commented 3 years ago

Context

My game crashed whenever I targeted a ship when playing on macOS.

We first thought that this had something to do with the High DPI code, as that's the line that eventually throw the error. However, hard coding the High DPI setting to false did not prevent the crash. This prompted us to investigate more deeply.

The actual error was an EXC_BAD_ACCESS exception. This happens when we try to access a memory location that has already been released. From what we can tell, macOS has stricter policies around memory access, which is probably why it didn't crash on other operating systems.

We eventually figured out that the crash was caused by the code that draws a faction flag for the currently targeted ship. This code read a single flag into a collection, then tried to iterate over that collection and display two of them.

Changes

This commit allows the game to display faction flags without crashing on macOS. It also makes that code run more quickly and use less memory.

kikotheexile commented 3 years ago

if it works for you, you're the best we got for testing.

Ty for the fix, merging.