question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DirectX fatal error on almost every method on x86

See original GitHub issue

Summary

Running the code with x86 PlatformTarget will fatal error:

using D3D11 = Silk.NET.Direct3D11;
using D3D9 = Silk.NET.Direct3D9;
using DXGI = Silk.NET.DXGI;

            var width = 1000;
            var height = 1000;

            var texture2DDesc = new D3D11.Texture2DDesc()
            {
                BindFlags = (uint) (D3D11.BindFlag.BindRenderTarget | D3D11.BindFlag.BindShaderResource),
                Format = DXGI.Format.FormatB8G8R8A8Unorm,
                Width = (uint) width,
                Height = (uint) height,
                MipLevels = 1,
                SampleDesc = new DXGI.SampleDesc(1, 0),
                Usage = D3D11.Usage.UsageDefault,
                MiscFlags = (uint) D3D11.ResourceMiscFlag.ResourceMiscShared,
                // The D3D11_RESOURCE_MISC_FLAG cannot be used when creating resources with D3D11_CPU_ACCESS flags.
                CPUAccessFlags = 0, //(uint) D3D11.CpuAccessFlag.None,
                ArraySize = 1
            };

            D3D11.ID3D11Device* pD3D11Device;
            D3D11.ID3D11DeviceContext* pD3D11DeviceContext;
            D3DFeatureLevel pD3DFeatureLevel = default;
            D3D11.D3D11 d3D11 = D3D11.D3D11.GetApi();

            var hr = d3D11.CreateDevice((DXGI.IDXGIAdapter*) IntPtr.Zero, D3DDriverType.D3DDriverTypeHardware,
                Software: 0,
                Flags: (uint) D3D11.CreateDeviceFlag.CreateDeviceBgraSupport,
                (D3DFeatureLevel*) IntPtr.Zero,
                FeatureLevels: 0, // D3DFeatureLevel 的长度
                SDKVersion: 7,
                (D3D11.ID3D11Device**) &pD3D11Device,
                ref pD3DFeatureLevel,
                (D3D11.ID3D11DeviceContext**) &pD3D11DeviceContext
            );

Steps to reproduce

  • Platform: Desktop
  • Framework Version: ALL
  • API: DirectX
  • API Version: All

Demo: https://github.com/lindexi/lindexi_gd/tree/cf6880ecd807f19d54da45566ac56bd23016ce18/RawluharkewalQeaninanel/RawluharkewalQeaninanel

Comments

The main reason is the Cdecl and Stdcall issues, such as the code:

((delegate* unmanaged[Cdecl]<ID3D11Device*, BufferDesc*, SubresourceData*, ID3D11Buffer**, int>)LpVtbl[3])(@this, pDesc, pInitialData, ppBufferPtr);

We should not use Cdecl key word, because the DirectX define is __stdcall.

#define STDMETHOD(method)        virtual COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE method
#define STDMETHOD_(type,method)  virtual COM_DECLSPEC_NOTHROW type STDMETHODCALLTYPE method
#define STDMETHODV(method)       virtual COM_DECLSPEC_NOTHROW HRESULT STDMETHODVCALLTYPE method
#define STDMETHODV_(type,method) virtual COM_DECLSPEC_NOTHROW type STDMETHODVCALLTYPE method

#define STDMETHODCALLTYPE       __stdcall

We must update all the DirectX method call with Stdcall

See https://github.com/dotnet/Silk.NET/pull/583 https://github.com/dotnet/Silk.NET/issues/663

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Perkseycommented, Dec 23, 2021

I’ll attempt to fix this, but note that D3D9 is one of two of our bindings that are explicitly unsupported on x86.

If the fix proves to difficult this’ll probably have to be community-championed or sponsored work using the GitHub Sponsors mechanism, as I fear it’s just going to be easier to drop x86 support.

Again, I’ll give it a shot, but don’t expect much. Not going to the moon and back for x86.

0reactions
lindexicommented, Jan 8, 2022

Thank you @Perksey

Read more comments on GitHub >

github_iconTop Results From Across the Web

Possible causes of (and solutions to) the infamous DirectX ...
Possible causes of (and solutions to) the infamous DirectX crash [Unexpected error & fatal DirectX error] · Press the Windows Key, type "Windows ......
Read more >
Fatal DirectX Error (11000002)
i see you have MSI Afterburner 4.6.4 Beta 3 installed. is ytour GPU overclocked at all? if so than that is your issue....
Read more >
DirectX fatal error issue
I recently had issues of when trying to play games or anything like that my computer would launch the game but close and...
Read more >
Saints Row - Game Crashes After Directx screen.
Game Crashes After Directx screen. i've been at this for almost 2 hours now. just bought the game and couldn't run it.
Read more >
FF14 DirectX 11 fatal error 11000002
All my screens died but sound still worked. Had to hard reset. Now trying standard settings, but doubt it will change much as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found