Crash after disabling compatibility mode in Unity 6 when using temporary target texture for a camera
After upgrading to Shapes 4.5.0 on Unity 6, disabling compatibility mode, and running the game in the editor, the game generates a lot of error messages in the console. These error messages are not generated when compatibility mode is enabled.
NullReferenceException: Object reference not set to an instance of an object UnityEngine.Rendering.RenderGraphModule.RenderGraphResourceRegistry.GetRenderTargetInfo (UnityEngine.Rendering.RenderGraphModule.ResourceHandle& res, UnityEngine.Rendering.RenderGraphModule.RenderTargetInfo& outInfo) (at ./Library/PackageCache/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs:708) UnityEngine.Rendering.RenderGraphModule.RenderGraphBuilders.CheckUseFragment (UnityEngine.Rendering.RenderGraphModule.TextureHandle tex, System.Boolean isDepth) (at ./Library/PackageCache/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphBuilders.cs:353) UnityEngine.Rendering.RenderGraphModule.RenderGraphBuilders.SetRenderAttachment (UnityEngine.Rendering.RenderGraphModule.TextureHandle tex, System.Int32 index, UnityEngine.Rendering.RenderGraphModule.AccessFlags flags, System.Int32 mipLevel, System.Int32 depthSlice) (at ./Library/PackageCache/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphBuilders.cs:388) UnityEngine.Rendering.RenderGraphModule.IRasterRenderGraphBuilder.SetRenderAttachment (UnityEngine.Rendering.RenderGraphModule.TextureHandle tex, System.Int32 index, UnityEngine.Rendering.RenderGraphModule.AccessFlags flags) (at ./Library/PackageCache/com.unity.render-pipelines.core/Runtime/RenderGraph/IRenderGraphBuilder.cs:196) Shapes.ShapesRenderPass.RecordRenderGraph (UnityEngine.Rendering.RenderGraphModule.RenderGraph renderGraph, UnityEngine.Rendering.ContextContainer frameData) (at Assets/Shapes/Scripts/Runtime/Immediate Mode/ShapesRenderPass.cs:40) UnityEngine.Rendering.Universal.ScriptableRenderer.RecordCustomRenderGraphPassesInEventRange (UnityEngine.Rendering.RenderGraphModule.RenderGraph renderGraph, UnityEngine.Rendering.Universal.RenderPassEvent eventStart, UnityEngine.Rendering.Universal.RenderPassEvent eventEnd) (at ./Library/PackageCache/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs:1222) UnityEngine.Rendering.Universal.ScriptableRenderer.RecordCustomRenderGraphPasses (UnityEngine.Rendering.RenderGraphModule.RenderGraph renderGraph, UnityEngine.Rendering.Universal.RenderPassEvent startInjectionPoint, UnityEngine.Rendering.Universal.RenderPassEvent endInjectionPoint) (at ./Library/PackageCache/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs:1241) UnityEngine.Rendering.Universal.ScriptableRenderer.RecordCustomRenderGraphPasses (UnityEngine.Rendering.RenderGraphModule.RenderGraph renderGraph, UnityEngine.Rendering.Universal.RenderPassEvent injectionPoint) (at ./Library/PackageCache/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs:1246) UnityEngine.Rendering.Universal.UniversalRenderer.OnAfterRendering (UnityEngine.Rendering.RenderGraphModule.RenderGraph renderGraph) (at ./Library/PackageCache/com.unity.render-pipelines.universal/Runtime/UniversalRendererRenderGraph.cs:1433) UnityEngine.Rendering.Universal.UniversalRenderer.OnRecordRenderGraph (UnityEngine.Rendering.RenderGraphModule.RenderGraph renderGraph, UnityEngine.Rendering.ScriptableRenderContext context) (at ./Library/PackageCache/com.unity.render-pipelines.universal/Runtime/UniversalRendererRenderGraph.cs:797) UnityEngine.Rendering.Universal.ScriptableRenderer.RecordRenderGraph (UnityEngine.Rendering.RenderGraphModule.RenderGraph renderGraph, UnityEngine.Rendering.ScriptableRenderContext context) (at ./Library/PackageCache/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs:1175) UnityEngine.Rendering.Universal.UniversalRenderPipeline.RecordRenderGraph (UnityEngine.Rendering.RenderGraphModule.RenderGraph renderGraph, UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Rendering.Universal.ScriptableRenderer renderer) (at ./Library/PackageCache/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineRenderGraph.cs:10) UnityEngine.Rendering.Universal.UniversalRenderPipeline.RecordAndExecuteRenderGraph (UnityEngine.Rendering.RenderGraphModule.RenderGraph renderGraph, UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Rendering.Universal.ScriptableRenderer renderer, UnityEngine.Rendering.CommandBuffer cmd, UnityEngine.Camera camera, System.String cameraName) (at ./Library/PackageCache/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineRenderGraph.cs:24) UnityEngine.Rendering.Universal.UniversalRenderPipeline.RenderSingleCamera (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Rendering.Universal.UniversalCameraData cameraData) (at ./Library/PackageCache/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs:857) UnityEngine.Rendering.Universal.UniversalRenderPipeline.RenderCameraStack (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Camera baseCamera) (at ./Library/PackageCache/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs:1082) UnityEngine.Rendering.Universal.UniversalRenderPipeline.Render (UnityEngine.Rendering.ScriptableRenderContext renderContext, System.Collections.Generic.List`1[T] cameras) (at ./Library/PackageCache/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs:469) UnityEngine.Rendering.RenderPipeline.InternalRender (UnityEngine.Rendering.ScriptableRenderContext context, System.Collections.Generic.List`1[T] cameras) (at <b5bf0c891ea345fe93688f835df32fdc>:0) UnityEngine.Rendering.RenderPipelineManager.DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset pipelineAsset, System.IntPtr loopPtr, UnityEngine.Object renderRequest, Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle safety) (at <b5bf0c891ea345fe93688f835df32fdc>:0) UnityEngine.Camera:Render() PortraitStudio:createPortrait(ActorView, Appearance) (at Assets/Scripts/View/PortraitStudio.cs:127) <createportraits>d__95:MoveNext() (at Assets/Scripts/View/ActorView.cs:360) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)</createportraits></b5bf0c891ea345fe93688f835df32fdc></b5bf0c891ea345fe93688f835df32fdc>
It might be relevant that the specific calls it seems to crash on are Camera.Render() calls (used to generate portraits at runtime), which render onto a targetTexture which is a temporary RenderTexture (using RenderTexture.GetTemporary):
portraitCamera.targetTexture = RenderTexture.GetTemporary(256, 256, 16, RenderTextureFormat.ARGB32); portraitCamera.Render() // <-- crash
When attaching a debugger, it seems that GetRenderTargetInfo is getting a null result when requesting the TextureResource related to that RenderTarget.
I have done a full clean install as documented in the Knowledge Base. The errors did not occur in previous Unity versions. The errors also don't occur if I remove Shapes from the project entirely.
For now I've simply re-enabled compatibility mode. I'm not very knowledgable when it comes to rendering, so I'm not sure if this is a Unity bug or a Shapes bug. If there's any other information I can provide, I'd be happy to do so! :)