GPUResident error.
DX11,enable GPUResidtentDrawer. open a new scene(only occurs in complex scene? Doesn’t always happen).
UnityEngine::UnityException: get_disableApplyMaterialPropertyDrawers can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
This Exception was thrown from a job compiled with Burst, which has limited exception support.
0x00007ffb46bc2afe (Unity) burst_abort
0x00007ffb46fb1dc3 (Unity) scripting_raise_exception
0x00007ffb4671c97a (Unity) EditorMaterialUtility_Get_Custom_PropDisableApplyMaterialPropertyDrawers
0x0000023dadb66487 (Mono JIT Code) (wrapper managed-to-native) UnityEditor.EditorMaterialUtility:get_disableApplyMaterialPropertyDrawers ()
0x0000023dadb660f3 (Mono JIT Code) UnityEditor.MaterialEditor:ApplyMaterialPropertyDrawers (UnityEngine.Object[])
0x0000023dadb65b7b (Mono JIT Code) UnityEditor.MaterialEditor:ApplyMaterialPropertyDrawersFromNative (UnityEngine.Material)
0x0000023d3c6c7988 (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void_object (object,intptr,intptr,intptr)
0x00007ffb300568de (mono-2.0-bdwgc) mono_jit_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:3445)
0x00007ffb2ff98404 (mono-2.0-bdwgc) do_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3068)
0x00007ffb2ff984f0 (mono-2.0-bdwgc) mono_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3115)
0x00007ffb46fbe324 (Unity) scripting_method_invoke
0x00007ffb46f960a3 (Unity) ScriptingInvocation::Invoke
0x00007ffb46f91365 (Unity) ScriptingInvocation::Invoke<void>
0x00007ffb470e84c3 (Unity) Scripting::UnityEditor::MaterialEditorProxy::ApplyMaterialPropertyDrawersFromNative
0x00007ffb46d14256 (Unity) Material::SetupKeywordsAndPasses
0x00007ffb46d006f5 (Unity) Material::BuildProperties
0x00007ffb46d07da7 (Unity) Material::GetActualRenderQueue
0x00007ffb4688355f (Unity) `anonymous namespace'::GetPackedMaterialData
0x00007ffb4687c054 (Unity) GPUDrivenProcessor::ClassifyMaterials
0x00007ffb461b0127 (Unity) GPUDrivenProcessor_CUSTOM_ClassifyMaterialsImpl
0x00007ffb545de155 (e08b5fac5506313367c8fe925e06818) Unity.Jobs.IJobExtensions.JobStruct`1<UnityEngine.Rendering.GPUResidentDrawer.ClassifyMaterialsJob>.Execute(ref UnityEngine.Rendering.GPUResidentDrawer.ClassifyMaterialsJob data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, ref Unity.Jobs.LowLevel.Unsafe.JobRanges ranges, int jobIndex) -> void_e6cd47a4990300e5c73209d1598fcacd from UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null (at E:/Project/Client/Library/PackageCache/com.unity.burst@7a907cf5a459/.Runtime/unknown/unknown:0)
0x00007ffb545dd99d (e08b5fac5506313367c8fe925e06818) 0c1b9cf4d0066c41e17e66573f57b9a4
0x00007ffb46bbf285 (Unity) ExecuteJob
0x00007ffb46bc031d (Unity) ForwardJobToManaged
0x00007ffb46bc1516 (Unity) ScheduleManagedJob
0x00007ffb46230ead (Unity) JobsUtility_CUSTOM_Schedule
0x0000023d39db57cd (Mono JIT Code) (wrapper managed-to-native) Unity.Jobs.LowLevel.Unsafe.JobsUtility:Schedule_Injected (Unity.Jobs.LowLevel.Unsafe.JobsUtility/JobScheduleParameters&,Unity.Jobs.JobHandle&)
0x0000023d39db56eb (Mono JIT Code) Unity.Jobs.LowLevel.Unsafe.JobsUtility:Schedule (Unity.Jobs.LowLevel.Unsafe.JobsUtility/JobScheduleParameters&)
0x0000023f15eb061b (Mono JIT Code) Unity.Jobs.IJobExtensions:Run<UnityEngine.Rendering.GPUResidentDrawer/ClassifyMaterialsJob> (UnityEngine.Rendering.GPUResidentDrawer/ClassifyMaterialsJob)
0x0000023f15eaefcb (Mono JIT Code) UnityEngine.Rendering.GPUResidentDrawer:ClassifyMaterials (Unity.Collections.NativeArray`1<int>,Unity.Collections.NativeList`1<int>&,Unity.Collections.NativeList`1<int>&,Unity.Collections.NativeList`1<UnityEngine.Rendering.GPUDrivenPackedMaterialData>&,Unity.Collections.Allocator) (at ./Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/GPUResidentDrawer.cs:826)
0x0000023f15ea5723 (Mono JIT Code) UnityEngine.Rendering.GPUResidentDrawer:PostPostLateUpdate () (at ./Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/GPUResidentDrawer.cs:578)
0x0000023f15ea528b (Mono JIT Code) UnityEngine.Rendering.GPUResidentDrawer:PostPostLateUpdateStatic () (at ./Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/GPUResidentDrawer.cs:470)
0x0000023d3f8b7d38 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007ffb300568de (mono-2.0-bdwgc) mono_jit_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:3445)
0x00007ffb2ff98404 (mono-2.0-bdwgc) do_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3068)
0x00007ffb2ff984f0 (mono-2.0-bdwgc) mono_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3115)
0x00007ffb46fbe324 (Unity) scripting_method_invoke
0x00007ffb46f960a3 (Unity) ScriptingInvocation::Invoke
0x00007ffb46c0bfc6 (Unity) ExecutePlayerLoop
0x00007ffb46c0bfe7 (Unity) ExecutePlayerLoop
0x00007ffb46c1111f (Unity) PlayerLoop
0x00007ffb47d1453a (Unity) EditorPlayerLoop::Execute
0x00007ffb47d2af37 (Unity) PlayerLoopController::InternalUpdateScene
0x00007ffb47d2ccfd (Unity) PlayerLoopController::UpdateSceneIfNeededFromMainLoop
0x00007ffb47d26aa1 (Unity) Application::TickTimer
0x00007ffb4831dd9a (Unity) MainMessageLoop
0x00007ffb48323a44 (Unity) UnityMain
0x00007ff607e52fba (Unity) __scrt_common_main_seh
0x00007ffba1e67614 (KERNEL32) BaseThreadInitThunk
0x00007ffba32226a1 (ntdll) RtlUserThreadStart
Be sure to send in a bug report: Help => Report a bug …
We’re seeing this too in Unity 6000.0.42f1 along with memory leak warnings that constantly spam the console.
Allocation of 80 bytes at 0x3210000b0
#0 GPUDrivenProcessor::ClassifyMaterials(core::array_ref<int>, ScriptingSpan<int>&, ScriptingSpan<int>&, ScriptingSpan<GPUDrivenPackedMaterialData>&)
#1 GPUDrivenProcessor_CUSTOM_ClassifyMaterialsImpl(BindingsManagedSpan*, BindingsManagedSpan*, BindingsManagedSpan*, BindingsManagedSpan*)
#2 Unity.Jobs.IJobExtensions.JobStruct`1<UnityEngine.Rendering.GPUResidentDrawer.ClassifyMaterialsJob>.Execute(ref UnityEngine.Rendering.GPUResidentDrawer.ClassifyMaterialsJob data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, ref Unity.Jobs.LowLevel.Unsafe.JobRanges ranges, int jobIndex) -> void_43d7ac6474c685e137710094c27f76d0 from UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
#3 0c1b9cf4d0066c41e17e66573f57b9a4
#4 ExecuteJob(ManagedJobData*, void (*)(void*, void*, void*, void*, int), int, unsigned char*)
#5 ScheduleManagedJob(JobScheduleParameters const&, void*, ScriptingExceptionPtr*)
#6 JobsUtility_CUSTOM_Schedule(JobScheduleParameters&, JobFence&)
A temporary solution. Convert ClassifyMaterialsJob to the main thread.
private void ClassifyMaterials(NativeArray<int> materials, out NativeList<int> unsupportedMaterials,
out NativeList<int> supportedMaterials, out NativeList<GPUDrivenPackedMaterialData> supportedPackedMaterialDatas, Allocator allocator)
{
supportedMaterials = new NativeList<int>(materials.Length, allocator);
unsupportedMaterials = new NativeList<int>(materials.Length, allocator);
supportedPackedMaterialDatas = new NativeList<GPUDrivenPackedMaterialData>(materials.Length, allocator);
if (materials.Length > 0)
{
//new ClassifyMaterialsJob
//{
// materialIDs = materials.AsReadOnly(),
// batchMaterialHash = m_Batcher.instanceCullingBatcher.batchMaterialHash.AsReadOnly(),
// unsupportedMaterialIDs = unsupportedMaterials,
// supportedMaterialIDs = supportedMaterials,
// supportedPackedMaterialDatas = supportedPackedMaterialDatas
//}.Run();
var usedMaterialIDs = new NativeList<int>(4, Allocator.TempJob);
foreach (var materialID in materials)
{
if (m_Batcher.instanceCullingBatcher.batchMaterialHash.ContainsKey(materialID))
usedMaterialIDs.Add(materialID);
}
if (usedMaterialIDs.IsEmpty)
{
usedMaterialIDs.Dispose();
return;
}
unsupportedMaterials.Resize(usedMaterialIDs.Length, NativeArrayOptions.UninitializedMemory);
supportedMaterials.Resize(usedMaterialIDs.Length, NativeArrayOptions.UninitializedMemory);
supportedPackedMaterialDatas.Resize(usedMaterialIDs.Length, NativeArrayOptions.UninitializedMemory);
int unsupportedMaterialCount = GPUDrivenProcessor.ClassifyMaterials(usedMaterialIDs.AsArray(), unsupportedMaterials.AsArray(), supportedMaterials.AsArray(), supportedPackedMaterialDatas.AsArray());
unsupportedMaterials.Resize(unsupportedMaterialCount, NativeArrayOptions.ClearMemory);
supportedMaterials.Resize(usedMaterialIDs.Length - unsupportedMaterialCount, NativeArrayOptions.ClearMemory);
supportedPackedMaterialDatas.Resize(supportedMaterials.Length, NativeArrayOptions.ClearMemory);
usedMaterialIDs.Dispose();
}
}
Thanks for bringing it up. Looking at the callstack and the code I think I know where this is coming from, but putting together a good repro might be tricky here so don’t worry about it. I just logged a ticket for it (UUM-101193).
Regarding the workaround, I think you should be able to just replace .Run() by .Execute().
Seeing this too, on both Mac and Windows.
Hi there! I don’t know how easy to reproduce or frequent this issue is, but I’d be curious to see if it persists if you disable Burst compilation (in the Jobs > Burst > Enable Burst Compilation menu). This might be an error in how we check for main thread with a complex chain of calls across C#, C++ and Burst.
I’m also experiencing this issue. At least for me, disabling burst and restarting Unity seems to fix the problem.
It is near constant and seems to happen only after a domain reload or reimport or something. Then happens more or less continuously. Will check the burst thing.
It does not happen with Burst compilation disabled, though this error does occur in that case. (I think, it’s not 100% deterministic when it reproduces.)
AssertionException: Assertion failure. Value was False
Expected: True
UnityEngine.Assertions.Assert.Fail (System.String message, System.String userMessage) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Assertions/Assert/AssertBase.cs:29)
UnityEngine.Assertions.Assert.IsTrue (System.Boolean condition, System.String message) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Assertions/Assert/AssertBool.cs:20)
UnityEngine.Assertions.Assert.IsTrue (System.Boolean condition) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Assertions/Assert/AssertBool.cs:13)
UnityEngine.Rendering.CreateDrawBatchesJob.ProcessRenderer (System.Int32 i) (at ./Library/PackageCache/com.unity.render-pipelines.core@405083404c88/Runtime/GPUDriven/InstanceCullingBatcher.cs:471)
UnityEngine.Rendering.CreateDrawBatchesJob.Execute () (at ./Library/PackageCache/com.unity.render-pipelines.core@405083404c88/Runtime/GPUDriven/InstanceCullingBatcher.cs:566)
Unity.Jobs.IJobExtensions+JobStruct`1[T].Execute (T& data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at /Users/bokken/build/output/unity/unity/Runtime/Jobs/Managed/IJob.cs:61)
Unity.Jobs.LowLevel.Unsafe.JobsUtility:Schedule_Injected(JobScheduleParameters&, JobHandle&)
Unity.Jobs.LowLevel.Unsafe.JobsUtility:Schedule(JobScheduleParameters&)
Unity.Jobs.IJobExtensions:Run(CreateDrawBatchesJob) (at /Users/bokken/build/output/unity/unity/Runtime/Jobs/Managed/IJob.cs:89)
UnityEngine.Rendering.GPUResidentDrawer:PostPostLateUpdateStatic() (at ./Library/PackageCache/com.unity.render-pipelines.core@405083404c88/Runtime/GPUDriven/GPUResidentDrawer.cs:469)
That last exception seems more problematic but at least the disappearance of the first exception without Burst proves that it was a “false positive” and an issue in how we detect if things are running in the main thread in that particular context. We will fix this but I’ll try to reproduce that last exception and try to understand what’s going on. Thanks for bringing this up.
Would it be possible for you to send us a zip of a project that can reproduce these exceptions?
Sorry, I can’t send you the project files.
Regarding how to reproduce the problem, in my case, for scene A that can reproduces the exception, if I set it as the default scene (the scene that opens when Unity is started), then reopen Unity and enter this scene, this error does not occur. If another scene is set as the default scene, and then open scene A, the error appear.
I unfortunately am unable to reproduce the issue, so this is rather frustrating. There’s probably a particular configuration in the scene in question that produces the issue. If you have the time to reduce the scene to a minimum that can reproduce the exception, that would be super helpful, although I imagine that you might not have the time for that. On my side, I’ll try to have a deeper dive in the exception to try to figure out what sequence of event could cause it.
An improved workflow for submitting bugs with minimal repro projects would probably go a long way towards getting the editor more stable more quickly. It’s quite painful right now. Unity has a Repro Project Wizard package but it isn’t that easy to use or integrated with the bug reporter, Unity Discussions, or any of the bug tracking tools or whatever. If there’s some PM in charge of this area somehow it seems like it could really benefit the engine.
Looks like this was fixed in the latest 6.2 alpha. A backport to 6.1 would be much appreciated!
It’s in the pipes
But there was a slight regression in 6.2 due to that that we would like to fix before landing this in 6.1.
It’s also happening in the Unity 6000.0.51 LTS version. Happens almost everytime I save the scene/project or perform a domain reload… hopefully it will be backported soon 
Hi, the backport fix to 6000.0 and 6000.1 should finally be available in the next minor releases.
Since it’s not in the Unity 6000.1.10 release notes from today I assume this fix will be in 6000.1.11?