daid / EmptyEpsilon

Open source bridge simulator. Build with the SeriousProton engine.
https://daid.github.io/EmptyEpsilon/
GNU General Public License v2.0
520 stars 173 forks source link

fix: prevent segfault when template does not exist #2113

Closed Piglit closed 1 month ago

Piglit commented 1 month ago

setTemplate now produces an error, if the chosen template does not exist. But the game no longer crashes with a segfault.

daid commented 1 month ago

I'm quite sure this moves segfaults to other spots, there are quite some places in the code that assume that the template property is set.

Piglit commented 1 month ago

Actually it produces quite nice errors and defined behaviour, since objects without templates get deleted in ShipTemplateBasedObject::update:

ERROR: Failed to find ship template: AtlantisXX
ERROR: Failed to find ship template: Adder MK5XX
ERROR: Failed to find ship template: 
ERROR: ShipTemplateBasedObject with ID 241 lacked a template, so it was destroyed.
ERROR: Failed to find ship template: 
ERROR: ShipTemplateBasedObject with ID 246 lacked a template, so it was destroyed.
daid commented 1 month ago

In that case, it's mostly fine. There is still a chance that it runs into a crash because other code doing something with the object before the update runs, but those are then extreme edge cases