StarMade 0.09264: Heureka! Super bug is fixed (hopefully)!

    schema

    Cat God
    Joined
    Feb 17, 2012
    Messages
    1,552
    Reaction score
    2,604
    • Schine
    Hi there,

    This vicious bug has crippled the game for some time now.
    Its symptoms were very wide ranged. Most of the time, it caused power, weapons, thrusters, etc, not to be registered. Sometimes it could even cripple servers, so for example no ship would be usable anymore (stuck in-place which happened on mad realms). But it could also cause some other unforeseen glitches.
    This bug was very hard to fix, since it pretty much happened on random. Thanks to your reports i finally managed to track it down. Thanks to all players, who sent them in! One particular report from Raimeer finally gave me the right to rule out most of the sources where the bug could come from.

    Technical:
    The optimization which calculates the block cluster stats almost instantly is using a thread where CollectionManagers (which each ship have for each type of usable element) could register a needed update (when the structure of blocks of that collection changes) on the Update Thread.
    The Update Thread will take the next registered update request (if available) and tells the CollectionManager to fill its block buffer with the raw set of all blocks of that type attached to that collection manager. It will wait while the CollectionManager is doing that. When the buffer is filled, the CollectionManager will notify the thread, that it can now do the update without having to worry about things being changed simultaneously (which would cause very very ugly bugs). The thread performs the update where it calculates all clusters (sets of blocks touching), and will then return the finished sets to the ElementCollection which takes them to replace the old sets.
    The bug was happening when an update has been requested, and the thread was waiting for the buffer to be filled. IF now the ship, station, planet, etc, got unloaded because nobody is around, the buffer never gets filled and the thread will wait forever without performing further updates, while holding the unloaded entity in memory since it has a soft reference to the thread (it holds the buffer).
    This happened a lot more on clients than on servers, since client entities are much more fluctuant. A ship in multiplayer passing though another client's sector, even AI in neighboring sectors could cause the bug. This is the reason the bug seemingly happen randomly.
    The fix was to have the "wait to fill" routine timeout and then check if the buffer has been processed. If not, it's likely the object has been unloaded, so the update for that entity is interrupted and rescheduled should the entity become active again without being re-loaded. This will guarantee, the execution of the thread is never stopped.

    Please let me know if you still encounter the bug.

    Thanks for playing StarMade,
    - schema