Repository navigation
System.Drawing - Simplify Pen.get_DashPattern P/Invoke code - #23958
Conversation
|
/cc @mellinoe |
| else if (DashStyle == DashStyle.Solid && !this.dashStyleWasChanged) | ||
| { | ||
| Marshal.FreeHGlobal(buf); | ||
| // Most likely we're replicating an existing System.Drawing bug here, it doesn't make much sense tó |
There was a problem hiding this comment.
There's an incorrect "ó" character on this line.
| private bool _immutable; | ||
|
|
||
| // Tracks whether the dash style has been changed to something else than Solid during the lifetime of this object. | ||
| private bool dashStyleWasChanged; |
There was a problem hiding this comment.
Prefix this with an underscore. Also, could you rename this to something like "_dashStyleIsNotSolid" to better reflect the name.
An aside: I'm okay with doing this as an attempt to match behavior better, but it's not perfectly robust. It is legal to change the native properties of the Pen outside of the Pen class (through a PInvoke or otherwise), and this cached state will become stale. This is a common problem in the library, and not specific to this at all. I just wanted to point it out.
|
|
||
| if (value != DashStyle.Solid) | ||
| { | ||
| this.dashStyleWasChanged = true; |
There was a problem hiding this comment.
Should this be set back to false if the value is Solid? Or rather:
_dashStyleIsNotSolid = value != DashStyle.Solid;
There was a problem hiding this comment.
The DashStyle_Custom unit test best explains the behavior:
https://github.com/dotnet/corefx/pull/23797/files#diff-7e1bf1ca3f411d193feac1a3697b2db1R304
- By default, the dash style is solid. If you execute
get_DashPattern, you'll get anOutOfMemoryException. - If you change the dash style to a custom dash style, you can get/set
DashPatternwithout issue - If you afterwards change the dash style back to
Solid, callingget_DashPatternwill not cause anOutOfMemoryException.
So the flag really tracks whether the dash patter is or has been different from Solid at any point or time. dashStyleIsNotSolid doesn't feel right because it's present tense; dashStyleIsOrWasNotSolid is the best I can come up with, let me know if you have a better idea for the name :).
There was a problem hiding this comment.
Okay, sounds like a reasonable description of what the field is tracking. Very weird behavior from GDI+ there...
|
Looks like an okay change to enable better compatibility, but I left a few comments to be fixed. |
|
Test UWP CoreCLR x64 Debug Build (I don't really understand what went wrong) |
…nvoke System.Drawing - Simplify Pen.get_DashPattern P/Invoke code Commit migrated from dotnet/corefx@839f044
Let the runtime marshal the
floatarrays instead of manually processing unmanaged memory.Fixes libgdiplus compatibility.