Search Unity

WinStore App crashes on RenderBufferManager::Textures::GetTempBuffer using Unity 2018.2 with IL2CPP

Discussion in 'Windows' started by Roywise, Sep 27, 2018.

  1. Roywise

    Roywise

    Joined:
    Jun 1, 2017
    Posts:
    68
    We have recently shifted our project from Unity 2017.4 to Unity 2018.2, with this change we have also switched to the IL2CPP scripting backend instead of the .NET scripting backend that we used before.

    Sadly, for some reason, something that worked fine before now crashes the App and it happens in the Unity Editor as well. It's hard to pinpoint at what exact moment a crash would occur because it varies but the crash log always points to the same class. According to the Stack Trace the ThumbnailCameraController is to blame.

    I've copy pasted the Stack Trace and the class methods it points towards below:


    Code (CSharp):
    1. ========== OUTPUTTING STACK TRACE ==================
    2.  
    3. 0x00000001407A3D23 (Unity) RenderBufferManager::Textures::GetTempBuffer
    4. 0x0000000141611EF3 (Unity) RenderTexture_CUSTOM_INTERNAL_CALL_GetTemporary_Internal
    5. 0x0000000015EFBAAE (Mono JIT Code) (wrapper managed-to-native) UnityEngine.RenderTexture:INTERNAL_CALL_GetTemporary_Internal (UnityEngine.RenderTextureDescriptor&)
    6. 0x0000000015EFB963 (Mono JIT Code) [C:\buildslave\unity\build\artifacts\generated\bindings_old\Metro\Core\TextureBindings.gen.cs:383] UnityEngine.RenderTexture:GetTemporary_Internal (UnityEngine.RenderTextureDescriptor)
    7. 0x0000000015EFABAB (Mono JIT Code) [C:\buildslave\unity\build\Runtime\Export\Texture.cs:193] UnityEngine.RenderTexture:GetTemporary (UnityEngine.RenderTextureDescriptor)
    8. 0x0000000015EF9843 (Mono JIT Code) [C:\buildslave\unity\build\Runtime\Export\Texture.cs:212] UnityEngine.RenderTexture:GetTemporaryImpl (int,int,int,UnityEngine.RenderTextureFormat,UnityEngine.RenderTextureReadWrite,int,UnityEngine.RenderTextureMemoryless,UnityEngine.VRTextureUsage,bool)
    9. 0x0000000015EF93CB (Mono JIT Code) [C:\buildslave\unity\build\Runtime\Export\Texture.cs:266] UnityEngine.RenderTexture:GetTemporary (int,int)
    10. 0x0000000015EF81E3 (Mono JIT Code) [D:\Repositories\unity-projectname\Assets\src\com\companyname\projectname\core\navigator\ThumbnailCameraController.cs:91] ThumbnailCameraController:onFrameRendered (System.Action`1<UnityEngine.Color[]>)
    11. 0x0000000015EF7F13 (Mono JIT Code) [D:\Repositories\unity-projectname\Assets\src\com\companyname\projectname\core\navigator\ThumbnailCameraController.cs:83] ThumbnailCameraController/<RenderFrame>c__AnonStorey0:<>m__0 ()
    12. 0x0000000015EF7D40 (Mono JIT Code) [D:\Repositories\unity-projectname\Assets\src\com\companyname\projectname\common\CameraFPSLimiter.cs:103] src.com.companyname.projectname.common.CameraFPSLimiter:OnPostRender ()
    13. 0x000000003F22EB78 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    14. 0x00007FFA776FA65B (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\mini\mini-runtime.c:2809] mono_jit_runtime_invoke
    15. 0x00007FFA77681B72 (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\object.c:2915] do_runtime_invoke
    16. 0x00007FFA7768AB5F (mono-2.0-bdwgc) [c:\buildslave\mono\build\mono\metadata\object.c:2962] mono_runtime_invoke
    17. 0x0000000140C0665A (Unity) scripting_method_invoke
    18. 0x0000000140BFE990 (Unity) ScriptingInvocation::Invoke
    19. 0x0000000140BB9D3D (Unity) MonoBehaviour::HandleNotifications
    20. 0x00000001405A0E94 (Unity) GameObject::SendMessageAny
    21. 0x00000001405CB347 (Unity) Camera::CustomRender
    22. 0x00000001405D2C09 (Unity) Camera::Render
    23. 0x000000014066B4F7 (Unity) RenderManager::RenderOffscreenCameras
    24. 0x000000014144DECB (Unity) PlayerLoopController::UpdateScene
    25. 0x000000014144BFF3 (Unity) Application::TickTimer
    26. 0x00000001415EB195 (Unity) MainMessageLoop
    27. 0x00000001415ED588 (Unity) WinMain
    28. 0x0000000142430FEA (Unity) __scrt_common_main_seh
    29. 0x00007FFACBD83034 (KERNEL32) BaseThreadInitThunk
    30. 0x00007FFACD581461 (ntdll) RtlUserThreadStart
    31.  
    32. ========== END OF STACKTRACE ===========

    Code (CSharp):
    1. public class ThumbnailCameraController : MonoBehaviour
    2. {
    3.     public void RenderFrame(Action<Color[]> callback)
    4.     {
    5.         _cameraFpsLimiter.RenderSingleFrame(() =>
    6.         {
    7.             onFrameRendered(callback);
    8.         });
    9.     }
    10.  
    11.     private void onFrameRendered(Action<Color[]> callback)
    12.     {
    13.         RenderTexture curRenderTexture = RenderTexture.active;
    14.  
    15.         RenderTexture.active = _camera.targetTexture;
    16.         RenderTexture renderTexture = RenderTexture.GetTemporary(_camera.targetTexture.width, _camera.targetTexture.height);
    17.  
    18.         Graphics.Blit(_camera.targetTexture, renderTexture);
    19.  
    20.         Texture2D texture = new Texture2D(renderTexture.width, renderTexture.height);
    21.         texture.ReadPixels(new Rect(0, 0, texture.width, texture.height), 0, 0);
    22.         texture.Apply();
    23.        
    24.         RenderTexture.ReleaseTemporary(renderTexture);
    25.         Destroy(renderTexture);
    26.         renderTexture = null;
    27.        
    28.         RenderTexture.active = curRenderTexture;
    29.        
    30.         callback(texture.GetPixels()); // <-- Pass texture to the callback.
    31.         Destroy(texture);
    32.         texture = null;
    33.     }
    34. }
    35.  
    36.  
    37.  
    38. public class CameraFPSLimiter : MonoBehaviour
    39. {
    40.     public void RenderSingleFrame(Action callback = null)
    41.     {
    42.         _renderCamera.enabled = true;
    43.  
    44.         if (callback != null)
    45.             _singleFrameActions.Add(callback);
    46.     }
    47.  
    48.     void OnPostRender()
    49.     {
    50.         // Causes the Camera to disable itself after it has rendered one frame.
    51.         _renderCamera.enabled = false;
    52.  
    53.         if (_singleFrameActions.Count > 0)
    54.         {
    55.             for (int i = _singleFrameActions.Count - 1; i >= 0; i--)
    56.                 _singleFrameActions[i].Invoke();
    57.            
    58.             _singleFrameActions.Clear();
    59.         }
    60.     }
    61. }
    What has changed with the handling of Textures/RenderTextures? Can someone point us towards a possible cause?
     
  2. Kaspar-Daugaard

    Kaspar-Daugaard

    Unity Technologies

    Joined:
    Jan 3, 2011
    Posts:
    150
    Hi, do you have a project with the crash that you can share?
     
  3. Roywise

    Roywise

    Joined:
    Jun 1, 2017
    Posts:
    68
    Hi @Kaspar-Daugaard, I could create a separate project and try to reproduce the issue. Sharing the entire project would be way to big. Give me a couple of days to try to reproduce this and I'll post the result in this thread.

    Is there anything else I could provide you?

    We have currently fixed the issue by creating a regular RenderTexture instead of using the Temporary functionality (GetTemporary and ReleaseTemporary).