mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Fixed serialization of null-strings
This commit is contained in:
@@ -105,8 +105,12 @@ class SerializedObject
|
||||
|
||||
if (primitiveType == .String)
|
||||
{
|
||||
MonoString* string = (.)value;
|
||||
// If the string is null, we store a nullptr and 0-length
|
||||
StringView valueView = StringView(null, 0);
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
MonoString* string = (.)value;
|
||||
char8* rawStringValue = Mono.mono_string_to_utf8(string);
|
||||
|
||||
String stringValue = new String(rawStringValue);
|
||||
@@ -115,7 +119,8 @@ class SerializedObject
|
||||
|
||||
Mono.mono_free(rawStringValue);
|
||||
|
||||
StringView valueView = stringValue;
|
||||
valueView = stringValue;
|
||||
}
|
||||
|
||||
Internal.MemCpy(&data, &valueView, sizeof(StringView));
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ public static class EntitySerializer
|
||||
}
|
||||
else if (fieldType == typeof(string))
|
||||
{
|
||||
AddField(fieldName, SerializationType.String, fieldValue.ToString());
|
||||
AddField(fieldName, SerializationType.String, fieldValue);
|
||||
}
|
||||
else if (fieldType.IsEnum)
|
||||
{
|
||||
@@ -317,8 +317,15 @@ public static class EntitySerializer
|
||||
{
|
||||
// rawData contains a Pointer and a string length!
|
||||
byte* utf8Ptr = *(byte**)rawData;
|
||||
|
||||
if (utf8Ptr == null)
|
||||
return null;
|
||||
|
||||
ulong length = *(ulong*)(rawData + 8);
|
||||
|
||||
if (length == 0)
|
||||
return string.Empty;
|
||||
|
||||
return Encoding.UTF8.GetString(utf8Ptr, (int)length);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user