Fix segfault with daytime option in gamesetup.
Based on patch by: @Angen, @wraitii Fixes #6238 Differential Revision: https://code.wildfiregames.com/D4182 This was SVN commit r25829.
This commit is contained in:
parent
b06dd26dd7
commit
5eec8039b4
@ -2,8 +2,7 @@ GameSettings.prototype.Attributes.Daytime = class Daytime extends GameSetting
|
|||||||
{
|
{
|
||||||
init()
|
init()
|
||||||
{
|
{
|
||||||
this.data = undefined;
|
this.setDataValueHelper(undefined, undefined);
|
||||||
this.value = undefined;
|
|
||||||
this.settings.map.watch(() => this.onMapChange(), ["map"]);
|
this.settings.map.watch(() => this.onMapChange(), ["map"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,13 +25,11 @@ GameSettings.prototype.Attributes.Daytime = class Daytime extends GameSetting
|
|||||||
let mapData = this.settings.map.data;
|
let mapData = this.settings.map.data;
|
||||||
if (!mapData || !mapData.settings || !mapData.settings.Daytime)
|
if (!mapData || !mapData.settings || !mapData.settings.Daytime)
|
||||||
{
|
{
|
||||||
this.value = undefined;
|
this.setDataValueHelper(undefined, undefined);
|
||||||
this.data = undefined;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO: validation
|
// TODO: validation
|
||||||
this.data = mapData.settings.Daytime;
|
this.setDataValueHelper(mapData.settings.Daytime, "random");
|
||||||
this.value = "random";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setValue(val)
|
setValue(val)
|
||||||
@ -55,4 +52,17 @@ GameSettings.prototype.Attributes.Daytime = class Daytime extends GameSetting
|
|||||||
this.value = pickRandom(this.data).Id;
|
this.value = pickRandom(this.data).Id;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to ensure this.data and this.value
|
||||||
|
* are assigned in the correct order to prevent
|
||||||
|
* crashes in the renderer.
|
||||||
|
* @param {object} data - The day time option data.
|
||||||
|
* @param {string} value - The option's key.
|
||||||
|
*/
|
||||||
|
setDataValueHelper(data, value)
|
||||||
|
{
|
||||||
|
this.data = data;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user