You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Functions taking a pointer to an array of pointers get confusing signatures #2105
I've run into an issue with ID3D11DeviceContext::OMSetRenderTargets() where the original takes a pointer to an array of const pointers to ID3D11RenderTargetView, but the Rust version takes an Option<&[Option<ID3D11RenderTargetView>]>. As best as I can tell, it should really just be taking an &[ID3D11RenderTargetView], because it certainly makes no sense to be passing in NULLs in that API. In addition, the current version complicates things by requiring you to move ID3D11RenderTargetView to pass it in. If it took an &[ID3D11RenderTargetView] instead, you could avoid the move by using std::slice::from_ref().
The general problem is that the metadata doesn't indicate that the API expects non-null COM interface pointers so it assumes they can all be null, and thus uses Option. We might argue that array parameters should be non-null as any null COM interfaces pointers can simply be omitted. I'm not sure whether that logic is universally applicable, but it sounds reasonable at first glance.
In addition to it being quite ugly, the signature currently forces an unnecessary clone. It would be strictly easier for me to use without the Options getting in the way:
Activity
kennykerr commentedon Oct 19, 2022
The general problem is that the metadata doesn't indicate that the API expects non-null COM interface pointers so it assumes they can all be null, and thus uses
Option. We might argue that array parameters should be non-null as any null COM interfaces pointers can simply be omitted. I'm not sure whether that logic is universally applicable, but it sounds reasonable at first glance.Muon commentedon Oct 20, 2022
I suppose there are two parts here:
ID3D11DeviceContext::OMSetRenderTargets()expects an array of non-null pointers.&[T]instead ofOption<&[T]>. (The empty slice indicates an empty array.)kennykerr commentedon Oct 20, 2022
That would be great but an uphill battle that is unlikely to be comprehensive.
Yes, that may be possible. I can experiment to see how effective/practical that may be.
kennykerr commentedon Oct 25, 2022
This looks much like #1339.
kennykerr commentedon Oct 28, 2022
IDCompositionDevice.CreateTransform3DGroupis another good example as its typically passed an array of derived interfaces.Muon commentedon Mar 12, 2023
Unfortunate that #2233 had to be reverted. Currently I have to use
OMSetRenderTargetslike so:In addition to it being quite ugly, the signature currently forces an unnecessary clone. It would be strictly easier for me to use without the Options getting in the way:
or even
kennykerr commentedon Mar 13, 2023
There may be further options here now that I've dramatically simplified the parameter binding machinery (#2360).