Burst compiler error.

I got error after call:
static unsafe void StringTest(string source)
{
fixed (char* text = source){

}
}

Error:
Unable to find internal function System.Runtime.CompilerServices.RuntimeHelpers::get_OffsetToStringData
UnityEngine.StackTraceUtility:ExtractStackTrace ()
Burst.Compiler.IL.Jit.JitBurstInitializeUtility/<>c__DisplayClass5_0:b__0 (intptr)
Burst.Compiler.IL.Jit.JitBurstInitializeUtility:InvokeBurstInitializeFunction (intptr,string,intptr)
Burst.Compiler.IL.Client.CompilerClient/LoadedLibrary:EnsureInitialized (intptr)
Burst.Compiler.IL.Client.CompilerClient:CallCallback (Burst.Compiler.IL.Client.CompilerClient/RequestedFunctionPointer,Burst.Compiler.IL.Client.CompilerClient/LoadedFunctionPointer)
Burst.Compiler.IL.Client.CompilerClient:HandleCompilationRequest (string,Burst.Compiler.IL.Client.CompilerClientCompileStatusCallback,Burst.Compiler.IL.Jit.JitCompilerService/CompileCallbackDelegate,intptr,bool,System.Nullable`1<Burst.Compiler.IL.Jit.FunctionPointerStub>)
Burst.Compiler.IL.Jit.JitCompilerService:CompileILPPMethod (string)
Burst.Compiler.IL.Jit.JitCompilerService:ProcessCommand (string,string)
Burst.Compiler.IL.Jit.JitCompilerService:CompileInternal (string,string,intptr,Unity.Burst.NativeDumpFlags,intptr,intptr,string)
Unity.Burst.BurstCompiler:SendRawCommandToCompiler (string) (at ./Library/PackageCache/com.unity.burst@1.8.12/Runtime/BurstCompiler.cs:787)
Unity.Burst.BurstCompiler/CommandBuilder:SendToCompiler () (at ./Library/PackageCache/com.unity.burst@1.8.12/Runtime/BurstCompiler.cs:92)
Unity.Burst.BurstCompiler:GetILPPMethodFunctionPointer2 (intptr,System.RuntimeMethodHandle,System.RuntimeTypeHandle) (at ./Library/PackageCache/com.unity.burst@1.8.12/Runtime/BurstCompiler.cs:284)
InternalDebugLib/Test4_00000019$BurstDirectCall:GetFunctionPointerDiscard (intptr&)
InternalDebugLib/Test4_00000019$BurstDirectCall:GetFunctionPointer ()
InternalDebugLib/Test4_00000019$BurstDirectCall:Invoke ()

You’re not normally able to use strings in Burst-compiled code, with exceptions for assignment to fixed strings from the collections package and certain logging methods. That method can’t be used from within Burst as-is, you should be using fixed strings instead, or using [BurstDiscard] on it with the understanding that it will not be included in the Burst version of the code. What’s the full context of the code you’re using this in?

Info on string limitations in Burst:
https://docs.unity3d.com/Packages/com.unity.burst@1.8/manual/csharp-string-support.html

3 Likes

But I look for fixed string build. I see the above code.
[ExcludeFromBurstCompatTesting(“Takes managed string”)]
internal CopyError Initialize(string source)
{
return FixedStringMethods.CopyFromTruncated(ref this, source);
}

Inside CopyFromTruncated is a code i mentioned.
FixedString build on string as input.

As the attributes on Initialize and on CopyFromTruncated suggest, those methods are not supported from within Burst. You can’t pass string as an argument. Limit your own code to using supported string types from the collections package. The page I linked has an example of how to do so.