Map Read Error

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

Post Reply
Deaod
Posts: 19
Joined: 17 Jun 2012, 12:09

Map Read Error

Post 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.
Akbalder
Posts: 1059
Joined: 15 Jun 2010, 11:00
Contact:

Re: Map Read Error

Post by Akbalder »

Did you try to remove it from the array before destroying it?
Deaod
Posts: 19
Joined: 17 Jun 2012, 12:09

Re: Map Read Error

Post 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.
User avatar
Eole
Nadeo
Nadeo
Posts: 1265
Joined: 26 Apr 2011, 21:08

Re: Map Read Error

Post 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.
Contribute to the ManiaPlanet documentation on GitHub
A question about ManiaScript? Ask it here!
Deaod
Posts: 19
Joined: 17 Jun 2012, 12:09

Re: Map Read Error

Post by Deaod »

Am i reading this correctly in that the values of a Ident->CUILayer map can change by destroying some unrelated layer?
User avatar
Eole
Nadeo
Nadeo
Posts: 1265
Joined: 26 Apr 2011, 21:08

Re: Map Read Error

Post 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.
Contribute to the ManiaPlanet documentation on GitHub
A question about ManiaScript? Ask it here!
Post Reply

Return to “ManiaScript”

Who is online

Users browsing this forum: No registered users and 3 guests