Closed tomimaki closed 8 years ago
I think I saw something related to this in a different mission, an address sanitiser build picked up memory corruption from a memset (IIRC), I'll have to see if I can repro & post the results.
I can reproduce this. Debugging shows that the submodel_instance_info
pointer in modelread.cpp:4435
is nullptr
. This could be a regression from the dumb rotate code where the submodel instance pointer isn't filled in correctly.
Collision detection happens in obj_move_all()
. The sii
attribute isn't filled in until model_update_instance()
gets called, which doesn't happen until ship_model_update_instance()
gets called, which doesn't happen until obj_move_all_post()
. This isn't a problem for ships arriving from subspace because ships warping in don't do collision detection in the first arrival phase; arriving from a docking bay means it tries to collide the same frame it was created, so ship_model_update_instance()
hasn't been called on it yet.
I see three basic solutions:
ship_model_update_instance()
earlier, e.g. by calling it immediately after the ship is created (I have no idea what the side effects of this could be).model_get_rotating_submodel_list()
check for sii
being nullptr
before calling get_submodel_delta_angle()
(alternatively, make get_submodel_delta_angle()
work on the angs
and prev_angs
attributes of the submodel_instance
directly instead of the submodel_instance_info
, since the former gets set from the latter anyway and will exist regardless of whether or not sii
has been set).Since the third option seems the least likely to have horrible side effects, I'm leaning towards that one... but since I'm not sure I understand this part of the code in the first place, I'd like to hear others' opinions before making a PR.
(FYI; I repro'd this with an ASAN build, and it didn't pick up any unusual memory activity prior to the segfault. Might have yet another bug lurking somewhere...)
@MageKing17: I tested your third option and it fixes the crash for me. Given that it can only happen in the first frame after a ship is created this shouldn't have any effects on other parts of the code. Should I submit the changes in a PR?
Sure; let's get this backported to the 3.7.4 branch ASAP so docking bays actually work in the next RC. :P
@tomimaki Could you check if the crash has been fixed by the recent commit to master?
Yes, it is fixed.
Great! I'll close this issue and create a PR for backporting this to 3.7.4.
This bug appears to be due to a combination of Volition's sequencing for rotating submodels and Swifty's conversion of the model rotation code to use instances instead of start/stop. I looked over the code in question and I agree that a simple nullptr check is the best solution.
Steps to reproduce crash:
On linux I got this backtrace:
And git bisect shows this: