Found very old error related to dynamic arrays of DynamicSprite or Overlay

Started by Crimson Wizard, Tue 04/09/2018 14:48:03

Previous topic - Next topic

Crimson Wizard

In the past years I've seen a number of reports about crashes related to dynamic sprites that acted as if they suddenly dissapeared.
Not 100% sure if this is the same one, but recently I've found an error in AGS that can with certain chance lead to DynamicSprite or Overlay getting destroyed after loading a savegame.

The technical details are explained here:
https://github.com/adventuregamestudio/ags/issues/502#issuecomment-418365544
but I warn that these won't be very useful to most people.

In more general terms, the error has a chance to occur if -
1. You have a dynamic array of DynamicSprites or Overlays, in other words something like this:
Code: ags

DynamicSprite *LotsOfSprites[];

function game_start()
{
    LotsOfSprites = new DynamicSprite[100];
    LotsOfSprites[0] = DynamicSprite.Create();
    <... and so on ...>
}


2. You save the game while it has this array and sprites created.
3. You restore that game during same game session.
4. If the slot numbers of dynamic sprites you had in your game just before loading the save match any slot numbers of dynamic sprites restored from the save, then there is a pretty high chance that these sprites will get deleted and your game crashes when trying to draw these sprites or do anything else with them.

I say "chance" because in practice there is a bit of random involved here. The larger is the array the higher the chance is.

This bug exists at least since AGS 3.2.1, did not see reason to test earlier versions.

I think we know actual reasons now, so hopefully next version will have a fix. But keep this in mind if you continue to work with older versions.

Monsieur OUXX

 

SMF spam blocked by CleanTalk