UDBScript: fixed a crash when trying to access the UDMF fields of a thing that has its scale set. Fixes #1079

This commit is contained in:
biwa 2024-07-05 20:16:48 +02:00
parent 11f864bb6e
commit e1ce00aa84

View file

@ -530,10 +530,10 @@ namespace CodeImp.DoomBuilder.UDBScript.Wrapper
/// <param name="fields">UniFields of the map element</param> /// <param name="fields">UniFields of the map element</param>
internal override void AddManagedFields(IDictionary<string, object> fields) internal override void AddManagedFields(IDictionary<string, object> fields)
{ {
if (thing.ScaleX != 1.0) if (!fields.ContainsKey("scalex") && thing.ScaleX != 1.0)
fields.Add("scalex", thing.ScaleX); fields.Add("scalex", thing.ScaleX);
if (thing.ScaleY != 1.0) if (!fields.ContainsKey("scaley") && thing.ScaleY != 1.0)
fields.Add("scaley", thing.ScaleY); fields.Add("scaley", thing.ScaleY);
} }
@ -549,12 +549,28 @@ namespace CodeImp.DoomBuilder.UDBScript.Wrapper
switch(pname) switch(pname)
{ {
case "scalex": case "scalex":
if (newvalue == null) thing.SetScale(1.0, thing.ScaleY); if (newvalue == null)
else thing.SetScale((double)newvalue, thing.ScaleY); {
thing.SetScale(1.0, thing.ScaleY);
UniFields.RemoveField(fields, "scalex");
}
else
{
thing.SetScale((double)newvalue, thing.ScaleY);
UniFields.SetFloat(fields, "scalex", (double)newvalue);
}
return true; return true;
case "scaley": case "scaley":
if(newvalue == null) thing.SetScale(thing.ScaleX, 1.0); if (newvalue == null)
else thing.SetScale(thing.ScaleX, (double)newvalue); {
thing.SetScale(thing.ScaleX, 1.0);
UniFields.RemoveField(fields, "scaley");
}
else
{
thing.SetScale(thing.ScaleX, (double)newvalue);
UniFields.SetFloat(fields, "scaley", (double)newvalue);
}
return true; return true;
} }