From 8992305d94b575cddeb85453e2931919ceecbc98 Mon Sep 17 00:00:00 2001 From: Derek S <44935661+Derek-R-S@users.noreply.github.com> Date: Thu, 8 Apr 2021 21:11:40 -0500 Subject: [PATCH] Fixed string serialization issues --- .../LRM/DataHandler.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/DataHandler.cs b/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/DataHandler.cs index 3efa752..53edbe5 100644 --- a/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/DataHandler.cs +++ b/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/DataHandler.cs @@ -41,9 +41,17 @@ namespace LightReflectiveMirror public static void WriteString(this byte[] data, ref int position, string value) { - data.WriteInt(ref position, value.Length); - for (int i = 0; i < value.Length; i++) - data.WriteChar(ref position, value[i]); + if (string.IsNullOrWhiteSpace(value)) + { + // Incase string is null or empty, just write nothing. + data.WriteInt(ref position, 0); + } + else + { + data.WriteInt(ref position, value.Length); + for (int i = 0; i < value.Length; i++) + data.WriteChar(ref position, value[i]); + } } public static string ReadString(this byte[] data, ref int position)