Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBret Johnson <bret.johnson@microsoft.com>2022-02-25 02:16:32 +0300
committervs-mobiletools-engineering-service2 <valco@microsoft.com>2022-02-25 06:27:15 +0300
commit7de9cf172e998e18caed055eb63edf155bd7a063 (patch)
tree0ec463e50ca00791c48b33e572e62be085551275
parent73beaed3ef5e8b61e5d0e586a873675c0d88f311 (diff)
Add cast to fix bug with numeric conversionbackport-pr-794-to-main
With the macos P13 API type changes, an issue was introduced since casting an ObjCRuntime.nfloat to an nint (aka IntPtr) doesn't work properly - (nint)(ObjCRuntime.nfloat)23 for instance will evaluate to 0x4037000000000000, the floating point bits are just reinterpreted as an int rather than actually being converted. That in turn caused huge sizes for width and height causing new CGBitmapContext to throw an exception. Adding the double cast here fixes this, for now. Soon ObjCRuntime.nfloat will go away, replaced by System.Runtime.InteropServices.NFloat, but for now this workaround makes us work. Fixes: AB#1487089 AB#1487070 AB#1487089
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushLayer.cs7
-rw-r--r--Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs6
2 files changed, 10 insertions, 3 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushLayer.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushLayer.cs
index 9fce3f7..ac76c0d 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushLayer.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushLayer.cs
@@ -84,8 +84,11 @@ namespace Xamarin.PropertyEditing.Mac
public NSImage RenderPreview ()
{
var scale = this.ContentsScale;
- nint h = (nint)(this.Bounds.Height * scale);
- nint w = (nint)(this.Bounds.Width * scale);
+ // The double cast below is needed for now, while Width/Height/scale are of type ObjCRuntime.nfloat
+ // in order for the floating point to integral conversion to work properly. Later when ObjCRuntime.nfloat
+ // is replaced with System.Runtime.InteropServices.NFloat that won't be needed (but can't hurt).
+ nint h = (nint)(double)(this.Bounds.Height * scale);
+ nint w = (nint)(double)(this.Bounds.Width * scale);
nint bytesPerRow = w * 4;
if (h <= 0 || w <= 0)
diff --git a/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs b/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs
index a38bd55..fa71c50 100644
--- a/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs
+++ b/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs
@@ -212,7 +212,11 @@ namespace Xamarin.PropertyEditing.Mac
this.registrations[cellIdentifier] = registration;
}
- return (nfloat) registration.GetHeight (vm);
+ // The double cast below is needed for now, while the return value is type ObjCRuntime.nfloat
+ // in order for the integral to floating point conversion to work properly. Later when ObjCRuntime.nfloat
+ // is replaced with System.Runtime.InteropServices.NFloat that won't be needed (but can't hurt).
+ nfloat rowHeight = (nfloat)(double)registration.GetHeight (vm);
+ return rowHeight;
}
private class EditorRegistration