Page 1 of 1

Map Read Error

Posted: 16 Oct 2012, 00:42
by Deaod
Ive been fiddling with this piece of code for a long time now, but i simply cant stop it from randomly crashing and restarting the map.

This crashes sometimes when reading from __RewardLayers (and only reading, ive never seen it crash when writing). Youd think .existskey() would protect against invalid reads.

The actual code is sometimes executed after a player hit another with some weapon.

Code: Select all

declare CUILayer[Ident] __RewardLayers;

// ...
	if (__RewardLayers.existskey(player.Id)) {
		if (__RewardLayers[player.Id] != Null) {
			UIManager.UILayerDestroy(__RewardLayers[player.Id]);
		}
	}
// ...
I would be thankful for any pointer as to why this keeps happening because im currently at the end of my means.

Re: Map Read Error

Posted: 16 Oct 2012, 10:43
by Akbalder
Did you try to remove it from the array before destroying it?

Re: Map Read Error

Posted: 16 Oct 2012, 12:13
by Deaod
No, and why would i do that?

Like this?

Code: Select all

// ...
   if (__RewardLayers.existskey(player.Id)) {
      if (__RewardLayers[player.Id] != Null) {
         declare tmp <=> __RewardLayers[player.Id];
         __RewardLayers.remove(tmp); // maybe one is enough.
         __RewardLayers.removekey(player.Id);
         UIManager.UILayerDestroy(tmp);
      }
   }
// ...
My problem is with reading from the map. I dont see how this could possibly help.

Re: Map Read Error

Posted: 16 Oct 2012, 17:19
by Eole
I think you should avoid to save a CUILayer in __RewardLayers, but the Id of this layer instead. Something like:

Code: Select all

declare Ident[Ident] __RewardLayers; ///< IdOfLayer[IdOfPlayer]

// Then you can delete the layer with something like this
if (UIManager.UILayers.existskey(__RewardLayers[Player.Id])) {
    UIManager.UILayerDestroy(UIManager.UILayers[__RewardLayers[player.Id]]);
}
For more information about this you can read this thread:
http://forum.maniaplanet.com/viewtopic. ... 82&start=0
Basically, if you save a CUILayer in your array, it's not the actual layer you're saving but an alias to the position of this layer in the UIManager.UILayers array. So if a layer is destroyed afterward, the alias you saved in __RewardLayers won't direct to the right layer anymore or even somewhere outside the array. Thus causing an error.

Re: Map Read Error

Posted: 16 Oct 2012, 18:38
by Deaod
Am i reading this correctly in that the values of a Ident->CUILayer map can change by destroying some unrelated layer?

Re: Map Read Error

Posted: 17 Oct 2012, 08:39
by Eole
Yes, the CUILayer you save in your array is actually a "shortcut" to another array that save all the existing layers. When deleting a layer, this general array is modified and the layers inside it moves. So your shortcut won't points to the right layer anymore.