dotnet / Silk.NET

The high-speed OpenGL, OpenCL, OpenAL, OpenXR, GLFW, SDL, Vulkan, Assimp, WebGPU, and DirectX bindings library your mother warned you about.
https://dotnet.github.io/Silk.NET
MIT License
4.15k stars 398 forks source link

Clash in Vulkan "CreateInstance()" Times #1843

Closed kgs233 closed 10 months ago

kgs233 commented 10 months ago

What happened?

When I was trying to create a Vulkan instance, I ran into a strange issue where it would crash without error from time to time. Specifically:

Vk vk = Vk.GetApi();
...
vk.CreateInstance(createInfo, null, out Instance pInstance); //There
...

After that, the program just exits without leaving any error message (but this is only in the terminal and in vscode, in vs it will report an error "heap memory corruption") In Debug mode the program returns 0xC0000374, which is shown in the windows log tracker as "STATUS_HEAP_CORRUPTION".

What might have happened?

I' dont knowI think the problem is with P/Invoke though, maybe the GC is reclaiming resources that shouldn't be reclaimed? But I don't know how to fix it.

Where's the weird part?

This problem doesn't always happen, sometimes it works fine in debug mode but not in release mode, sometimes it works fine in the debugger but not outside of it, and even sometimes it still occurs from time to time when you run the same version of the program in the same environment.

Beyley commented 10 months ago

this error suggests you are writing out of bounds somewhere in your code, or you are passing bad pointers into the driver, and it is writing out of bounds, we'd need more code reference to know whether or not this is our problem or yours.