mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Made script deserialization more robust
This commit is contained in:
@@ -613,10 +613,6 @@ class SceneSerializer
|
|||||||
// Allocate a string on the stack, because the dictionary uses a string as key
|
// Allocate a string on the stack, because the dictionary uses a string as key
|
||||||
String fieldNameString = scope .(fieldName);
|
String fieldNameString = scope .(fieldName);
|
||||||
|
|
||||||
if (fields.ContainsKey(fieldNameString))
|
|
||||||
{
|
|
||||||
var field = ref fields[fieldNameString];
|
|
||||||
|
|
||||||
Result<StringView> fieldTypeName = reader.Type();
|
Result<StringView> fieldTypeName = reader.Type();
|
||||||
|
|
||||||
if (fieldTypeName case .Err)
|
if (fieldTypeName case .Err)
|
||||||
@@ -629,23 +625,36 @@ class SceneSerializer
|
|||||||
|
|
||||||
Result<ScriptFieldType> fieldType = Enum.Parse<ScriptFieldType>(fieldTypeName, true);
|
Result<ScriptFieldType> fieldType = Enum.Parse<ScriptFieldType>(fieldTypeName, true);
|
||||||
|
|
||||||
if ((fieldType case .Err) || (fieldType != field.Type))
|
if ((fieldType case .Err))
|
||||||
{
|
{
|
||||||
Log.EngineLogger.Error($"Unexpected field type (\"{fieldTypeName}\" instead of \"{field.Type}\" for field: \"{fieldName}\" in script \"{component.ScriptClassName}\" of entity {entity.UUID} (\"{entity.Name}\")");
|
Log.EngineLogger.Error($"Error deserializing field type (Raw string: \"{fieldTypeName}\" of field: \"{fieldName}\" in script \"{component.ScriptClassName}\" of entity {entity.UUID} (\"{entity.Name}\")");
|
||||||
reader.FileEntrySkip(1);
|
reader.FileEntrySkip(1);
|
||||||
dontRemoveComma = true;
|
dontRemoveComma = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* data = &field.[Friend]_data;
|
uint8[sizeof(Matrix)] data = .();
|
||||||
|
|
||||||
if (Deserialize.Value(reader, ValueView(field.Type.GetBeefType(), data), gBonEnv) case .Err)
|
if (Deserialize.Value(reader, ValueView(fieldType.Value.GetBeefType(), &data), gBonEnv) case .Err)
|
||||||
{
|
{
|
||||||
Log.EngineLogger.Error($"Failed to deserialize data for field: \"{fieldName}\" in script \"{component.ScriptClassName}\" of entity {entity.UUID} (\"{entity.Name}\")");
|
Log.EngineLogger.Error($"Failed to deserialize data for field: \"{fieldName}\" in script \"{component.ScriptClassName}\" of entity {entity.UUID} (\"{entity.Name}\")");
|
||||||
reader.FileEntrySkip(1);
|
reader.FileEntrySkip(1);
|
||||||
dontRemoveComma = true;
|
dontRemoveComma = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fields.ContainsKey(fieldNameString))
|
||||||
|
{
|
||||||
|
var field = ref fields[fieldNameString];
|
||||||
|
|
||||||
|
// Make sure the type we deserialized actually is correct.
|
||||||
|
if (fieldType != field.Type)
|
||||||
|
{
|
||||||
|
Log.EngineLogger.Error($"Unexpected field type (\"{fieldTypeName}\" instead of \"{field.Type}\" for field: \"{fieldName}\" in script \"{component.ScriptClassName}\" of entity {entity.UUID} (\"{entity.Name}\")");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
field.SetData(data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user