-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Access violation when calling ID3D12DescriptorHeap.GetCPUDescriptorHandleForHeapStart #449
Comments
I guess this is the same issue as in #167 . Is there any recommended workaround for now? |
I don't have a workaround to offer at this point. Thanks for the report and noticing the dupe. |
I did some more digging and it appears that support for this calling convention is already implemented in clr in .net 6. Since I'm already using it, I was able to work around this issue with following code (code is proof of concept for now, performance of this is very bad obviously): private unsafe D3D12_CPU_DESCRIPTOR_HANDLE GetDescriptorHandle(ID3D12DescriptorHeap* heap)
{
var vtableField = typeof(ID3D12DescriptorHeap).GetField("lpVtbl", BindingFlags.NonPublic | BindingFlags.Instance)!;
var vtableType = typeof(ID3D12DescriptorHeap).GetNestedType("Vtbl", BindingFlags.NonPublic)!;
var vtable = (nuint*)Pointer.Unbox(vtableField.GetValue(*heap));
var getDescriptor = (delegate* unmanaged[Stdcall, MemberFunction]<ID3D12DescriptorHeap*, D3D12_CPU_DESCRIPTOR_HANDLE>)(vtable[9]);
var getDescriptorResult = getDescriptor(heap);
return getDescriptorResult;
} This code requires marshalling to be disabled and manually calls the vtable pointer with newly introduced Is there a plan to use this new COM calling convention in generated vtables? |
Not at present. Presumably there should be a way to make this work on .NET Framework as well, and we'd most likely generate the code necessary to make it work there as well as .NET 6. |
Closing as duplicate of #167. |
Actual behavior
I'm getting access violation error when calling ID3D12DescriptorHeap.GetCPUDescriptorHandleForHeapStart method. I've destilled my code to short repro. It might be my error, but C++ version looks to be working without crashing.
Expected behavior
Code working correctly
Repro steps
NativeMethods.txt
content:NativeMethods.json
content (if present):NOTE: I've tried different settings and could not manage to get it to work without access violation. I've also tried version with and without marshalling.
Here is the version with marshalling enabled:
Compare to correclty working C++ version:
Context
The text was updated successfully, but these errors were encountered: