Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Strange null ref in COM call #6042

Closed
mellinoe opened this issue Jul 3, 2018 · 6 comments · Fixed by #6051
Closed

Strange null ref in COM call #6042

mellinoe opened this issue Jul 3, 2018 · 6 comments · Fixed by #6051

Comments

@mellinoe
Copy link
Contributor

mellinoe commented Jul 3, 2018

After #5587 was fixed, I'm able to get much further with my project. Most everything works, but there's still some issues calling into SharpDX (or so it seems). I get a crash with this stack:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at Veldrid.D3D11.D3D11Swapchain..ctor(Device, SwapchainDescription&) + 0x342
   at Veldrid.D3D11.D3D11GraphicsDevice..ctor(GraphicsDeviceOptions, Nullable`1) + 0x1e3
   at Veldrid.GraphicsDevice.CreateD3D11(GraphicsDeviceOptions, IntPtr, UInt32, UInt32) + 0xfb
   at Veldrid.StartupUtilities.VeldridStartup.CreateDefaultD3D11GraphicsDevice(GraphicsDeviceOptions, Sdl2Window) + 0x6e
   at Veldrid.StartupUtilities.VeldridStartup.CreateGraphicsDevice(Sdl2Window, GraphicsDeviceOptions, GraphicsBackend) + 0x86
   at SampleBase.VeldridStartupWindow.Run() + 0x9c
   at Instancing.Program.Main(String[]) + 0x6d
   at Instancing.Desktop!<BaseAddress>+0x4ad77a
   at Instancing.Desktop!<BaseAddress>+0x4ad807

I believe that it's hitting a null ref on this line. dxgiDevice is null when it shouldn't be, and isn't when using CoreCLR. That query function shouldn't return null (it should throw instead), as far as I know.

The problem can be reprod by checking out the corert-crash branch of https://github.com/mellinoe/veldrid-samples/tree/corert-crash.

dotnet publish -r win-x64 src\Instancing\Desktop\Instancing.Desktop.csproj

@MichalStrehovsky
Copy link
Member

I tried to repro this, but I'm getting:

C:\Temp\veldrid-samples-corert-crash\src\AssetProcessor\AssetProcessor.csproj : error : The project was restored using Microsoft.NETCore.App version 2.1.1, but with current settings, version 2.1.0 would be used instead.  To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish.  Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore.

All I did was downloading your branch as a ZIP from GitHub and running the command you provided.

@mellinoe
Copy link
Contributor Author

mellinoe commented Jul 3, 2018

Looks like you're missing the 2.1.0 runtime, or your SDK is targeting a different version or something? I haven't kept up with the SDK well enough to understand what that error means.

@MichalStrehovsky
Copy link
Member

No, the case of missing runtime is:

C:\Program Files\dotnet\sdk\2.1.201\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(135,5): error : The current .NET SDK does not support targeting .NET Core 2.1.  Either target .NET Core 2.0 or lower, or use a version of the .NET SDK that supports .NET Core 2.1. [C:\Temp\veldrid-samples-corert-crash\src\AssetProcessor\AssetProcessor.csproj]

I got that first, so I uninstalled all the .NET Core SDKs I had and installed the latest one from the web.

@jkotas
Copy link
Member

jkotas commented Jul 4, 2018

This is https://github.com/dotnet/cli/issues/9544. It can be worked around it by adding <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> to src\AssetProcessor\AssetProcessor.csproj or by downgrading to 2.1.300 SDK.

I can get further with this workaround, but the repro steps are still failing for me:

 Processing C:\veldrid-samples\assets\models\rock01.dae

  Unhandled Exception: System.IO.FileNotFoundException: Could not find or load the native library: Assimp64.dll
     at NativeLibraryLoader.LibraryLoader.LoadNativeLibrary(String name, PathResolver pathResolver)

...

C:\veldrid-samples\Directory.Build.targets(13,5): error MSB3073: The command "dotnet C:\veldrid-samples\bin/Debug/AssetProcessor/netcoreapp2.1/AssetProcessor.dll C:\veldrid-samples\bin\obj\Instancing\/ProcessedAssets C:\veldrid-samples\assets\textures\texturearray_rocks_bc3_unorm.ktx C:\veldrid-samples\assets\textures\lavaplanet_bc3_unorm.ktx C:\veldrid-samples\assets\textures\texturearray_rocks_etc2_unorm.ktx C:\veldrid-samples\assets\textures\lavaplanet_etc2_unorm.ktx C:\veldrid-samples\assets\models\rock01.dae C:\veldrid-samples\assets\models\sphere.obj" exited with code -532462766. [C:\veldrid-samples\src\Instancing\Application\Instancing.csproj]

@mellinoe
Copy link
Contributor Author

mellinoe commented Jul 4, 2018

@jkotas Hm, sorry about that -- I haven't seen that issue before. Instead of working around that, I've pushed a commit that changes another one of the projects to use CoreRT. It's simpler but still exhibits the same crash.

dotnet publish -r win-x64 src\GettingStarted\GettingStarted.csproj

@MichalStrehovsky
Copy link
Member

I opened a pull request with a fix.

Once that's merged, you'll hit a MissingMethodException because SharpDX reflection-activates things and we didn't bother compiling the constructors because things looked unused.

I used following RD.XML to fix it:

<Directives>
    <Application>
        <Assembly Name="SharpDX.D3DCompiler" Dynamic="Required All" />
        <Assembly Name="SharpDX.Direct3D11" Dynamic="Required All" />
        <Assembly Name="SharpDX" Dynamic="Required All" />
        <Assembly Name="SharpDX.DXGI" Dynamic="Required All" />
        <Assembly Name="Veldrid" Dynamic="Required All" />
        <Assembly Name="Veldrid.MetalBindings" Dynamic="Required All" />
        <Assembly Name="Veldrid.OpenGLBindings" Dynamic="Required All" />
        <Assembly Name="Veldrid.SDL2" Dynamic="Required All" />
        <Assembly Name="Veldrid.StartupUtilities" Dynamic="Required All" />
        <Assembly Name="vk" Dynamic="Required All" />
    </Application>
</Directives>

It's possible not all of this is needed (having this all means compilation throughput and size of the output binary is worse), but I prefer not fixing these one-by-one. You should be able to tweak it as needed.

veldrid

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants