#FixedString implicit conversion issue

1 messages · Page 1 of 1 (latest)

fiery fable
#

having some weird implicit conversion issue with FixedString.

So I have this funtion cs public static void Warning(FixedString4096Bytes message, LogChannel channel = default, FixedString512Bytes helpPageUrl = default) => LogTo(message, LogLevel.Warning, channel, helpPageUrl); in the Log class. Calling it manually for example by using Log.Debug($"CMS Remapping path {path}", LogChannel.Content); works perfectly fine. However I made a little wrapper/helper that looks like this: public static void Debug(FixedString4096Bytes text) => Log.Debug(text, LogChannel.Content, null);
and when calling it I instead get an exception in FixedString512.op_Implicit

NullReferenceException: Object reference not set to an instance of an object
Unity.Collections.FixedStringMethods.CopyFromTruncated[T] (T& fs, System.String s) (at Library/PackageCache/com.unity.collections@d49facba0036/Unity.Collections/FixedStringAppendMethods.cs:417)
Unity.Collections.FixedString512Bytes.Initialize (System.String source) (at Library/PackageCache/com.unity.collections@d49facba0036/Unity.Collections/FixedString.gen.cs:5284)
Unity.Collections.FixedString512Bytes..ctor (System.String source) (at Library/PackageCache/com.unity.collections@d49facba0036/Unity.Collections/FixedString.gen.cs:5272)
Unity.Collections.FixedString512Bytes.op_Implicit (System.String b) (at Library/PackageCache/com.unity.collections@d49facba0036/Unity.Collections/FixedString.gen.cs:5769)```
Anyone have any idea what could be causing it?
harsh loom
#

Looks like an internal bug with the operator, see if it has an explicit operator that acts differently by doing (string)text

fiery fable
#

Solved! The issue was that I was providing null to helpPageUrl which caused it to implicitly convert to string since (string)null is a valid case for FixedString512

harsh loom
#

Oh good catch

fiery fable
#

Had to use IL disassembler to figure out what was actually going on and then it was fairly obvious. Very sneaky little error though 😄