Search Issue Tracker

By Design

Votes

2

Found in

2018.4

2019.3

2019.3.12f1

2020.1

2020.2

Issue ID

1244070

Regression

No

Crash on TexturesD3D11Base::RegisterNativeTexture when Texture2D.CreateExternalTexture() is called

Texture

-

Reproduction steps:
1. Open user's attached project and scene "DDOScene"
2. Delete the ML Agent package from the Package manager
3. Delete "BaseAgent.cs" from the Assets folder
4. Enter Play Mode
-- observe crash

Reproducible with: 2018.4.23f1, 2019.3.14f1, 2020.1.0b9, 2020.2.0a12

  1. Resolution Note:

    Texture2D.CreateExternalTexture is being used incorrectly. CreateExternalTexture() requires the user to pass in a native texture object. When using Direct3D11 for example, this could be a ID3D11Texture2D* texture. The code provided passes in a pointer to raw pixel data in memory. Unity cannot make the distinction between a valid and invalid pointer being passed in. To render a bitmap onto a RenderTexture, this example code would work:

    System.Drawing.Imaging.BitmapData bd =
    bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
    System.Drawing.Imaging.ImageLockMode.ReadOnly,
    System.Drawing.Imaging.PixelFormat.Format32bppArgb);

    int pixelSize = 4; // sizeof(ARGB32)
    byte[] data = new byte[bmp.Width * bmp.Height * pixelSize];

    Debug.Assert(bd.Stride == bd.Width * pixelSize);
    Marshal.Copy(bd.Scan0, data, 0, bmp.Width * bmp.Height * pixelSize);

    Texture2D tmptex = new Texture2D(bmp.Width, bmp.Height, TextureFormat.BGRA32, false);
    tmptex.LoadRawTextureData(data);
    tmptex.Apply();

    bmp.UnlockBits(bd);

    RenderTexture.active = texture;
    UnityEngine.Graphics.Blit(tmptex, texture);

    Object.DestroyImmediate(tmptex);

Comments (2)

  1. sniffle63

    Sep 11, 2020 16:15

    My company is getting this error on 2019.4 randomly and our game is crashing/

  2. kayke

    Jun 04, 2020 02:17

    We appear to be having a similar issue with intermittent crashes in our builds.
    Unity 2019.3.15f1

    0x00007FFE8010A924 (d3d11) D3D11CoreCreateDevice
    0x00007FFE801093D2 (d3d11) D3D11CoreCreateDevice
    0x00007FFE8010C1F3 (d3d11) D3D11CoreCreateDevice
    0x00007FFE8010CBCF (d3d11) D3D11CoreCreateDevice
    0x00007FFE8010D3C0 (d3d11) D3D11CoreCreateDevice
    0x00007FFE801026AA (d3d11) D3D11CoreCreateDevice
    0x00007FFE80125FD2 (d3d11) D3D11CoreGetLayeredDeviceSize
    0x00007FFE80125F92 (d3d11) D3D11CoreGetLayeredDeviceSize
    0x00007FFE1F395079 (UnityPlayer) CreateDefaultSRV
    0x00007FFE1F397F27 (UnityPlayer) TexturesD3D11Base::RegisterNativeTexture
    0x00007FFE1F38F183 (UnityPlayer) GfxDeviceD3D11Base::RegisterNativeTexture
    0x00007FFE1F43CD5C (UnityPlayer) GfxDeviceWorker::RunCommand
    0x00007FFE1F44471D (UnityPlayer) GfxDeviceWorker::RunExt
    0x00007FFE1F4447F8 (UnityPlayer) GfxDeviceWorker::RunGfxDeviceWorker
    0x00007FFE1F767188 (UnityPlayer) Thread::RunThreadWrapper
    0x00007FFE86DA7974 (KERNEL32) BaseThreadInitThunk
    0x00007FFE86EFA271 (ntdll) RtlUserThreadStart

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.