Skip to content

Commit

Permalink
fix: [wasm] Don't fail on uninitialized GC handle
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Jan 16, 2024
1 parent 72e326f commit 6546ec3
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/Uno.UI/UI/Xaml/UIElement.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,23 +326,21 @@ partial void ApplyNativeClip(Rect rect)

internal static UIElement GetElementFromHandle(IntPtr handle)
{
var gcHandle = GCHandle.FromIntPtr(handle);

if (gcHandle.IsAllocated && gcHandle.Target is UIElement element)
if (handle != IntPtr.Zero)
{
return element;
}

return null;
}

internal static UIElement GetElementFromHandle(int handle)
{
var gcHandle = GCHandle.FromIntPtr((IntPtr)handle);
var gcHandle = GCHandle.FromIntPtr(handle);

if (gcHandle.IsAllocated && gcHandle.Target is UIElement element)
if (gcHandle.IsAllocated && gcHandle.Target is UIElement element)
{
return element;
}
}
else
{
return element;
if (typeof(UIElement).Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Debug))
{
typeof(UIElement).Log().Debug($"Unable to get element handle for uninitialized handle");
}
}

return null;
Expand Down

0 comments on commit 6546ec3

Please sign in to comment.