-
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
GetSize and GetPixelSize methods on ID2D1RenderTarget need special ABI handling #731
Comments
Thank you for the excellent report. The metadata for this interface appears to present several methods inconsistently. I'm going to transfer this issue to the metadata repo for resolution, since CsWin32 is just generating the methods as described there. |
These methods all work correctly in Rust, so I can confirm the metadata is correct. Note that various Direct2D methods don't return |
I don't think that necessarily follows. Our projections interpret the metadata differently, so it's possible one works while a bug remains in the metadata. But I'm just exploring here and trying to understand. Thanks for the link to the other issue. I'd personally say the metadata is incorrect, since we can't take the declaration as given, and there is no annotation in the metadata to tell us that projections need to do something special here. It's just that Rust has already figured out this 'bug' in the metadata and worked around it, and CsWin32 hasn't.
|
Sure, you could argue the metadata could be improved. I'm just pointing out that it works today so we shouldn't blindly "fix" these methods. Another case of this: microsoft/win32metadata#1295 (comment) |
FYI we'll track |
I suggested maybe these need to be marked as These would fall into those specifications. |
I'll move this back to CsWin32 and track fixing our generator. |
Note to self: our fix in CsWin32 will require that we apply similar transformations that the rust projection applies, as described here: To avoid user confusion though, we may want to adjust our friendly overloads to look like the documented signature (in effect, reversing the transformation). |
@Shkyrockett Can you confirm that once fixed, you're expecting pixel sizes of 0 to come out of these to get size methods? When I manually apply the prescribed fix, I'm getting 0,0 from both methods. |
@AArnott Yes. The GDI object is not getting initiated with dimensions, so the sizes should be 0,0 here. If more complete solutions would help, I have been playing around with this in Direct2DCanvasPlayground and AutoGenDirectWritePlayground. The Overrides folders contain the files overriding the CSWin32 generation. |
Duplicate of #167 |
Actual behavior
ID2D1RenderTarget.EndDraw
does not return a neededHRESULT
, andID2D1RenderTarget.GetSize
, andID2D1RenderTarget.GetPixelSize
throw System.AccessViolationException exceptions when accessed because they are also not returningHRESULT
s.Expected behavior
The
EndDraw
,GetSize
, andGetPixelSize
methods should returnHRESULT
inID2D1RenderTarget
and inherited interfaces, when using"allowMarshaling": true
. Maybe these need to be marked as[PreserveSig]
?ID2D1RenderTarget.EndDraw
should return anHRESULT
so the result can be used to tell if the draw attempt failed and Direct2D needs to be reinitialized because of a display reset. See https://docs.microsoft.com/en-us/windows/win32/api/d2d1/nn-d2d1-id2d1rendertarget#remarksBoth
ID2D1RenderTarget.GetSize
, andID2D1RenderTarget.GetPixelSize
throwSystem.AccessViolationException
exceptions when called using the current method signatures which returnD2D_SIZE_F
orD2D_SIZE_U
respectively. Changing the methods to returnHRESULT
fixes the exception. Friendly overload extensions that do returnD2D_SIZE_F
orD2D_SIZE_U
would be helpful for these methods.Repro steps
NativeMethods.txt
content:NativeMethods.json
content (if present):Minimal repro:
The code above should be rewritten to the following if the methods returned HRESULTS:
Context
The text was updated successfully, but these errors were encountered: