Workaround for P/Invoke AccessViolationException
Summary: The issue is on ARM builds for Windows UWP. For the C# P/Invoke API wrapper, any native method that returns the YogaValue struct throws the AccessViolationException. The issue is not with structs in general, as returning the YogaSize / YGSize struct works fine. The issue seems to be limited to structs that have an enum member. I tried a number of things to resolve the issue without changing the underlying native API for Windows. I read the ARM documentation and saw reference to variable enum sizes based on the number of enum members, so I tried to use a number of different UnmanagedType values in a [MarsalAs()] attribute on the enum member of the C# struct declaration. What ultimately worked was to return a pointer to the location of the struct, and use the System.Runtime.InteropServices.PtrToStructure API to read the struct data from that pointer. I added a few new macros that will return the struct address on Windows only, other builds are not affected. Note, I have not tested the impact of this ch Closes https://github.com/facebook/yoga/pull/459 Reviewed By: emilsjolander Differential Revision: D4652278 Pulled By: splhack fbshipit-source-id: bf7ada4da1781e3f813b3ba331974b7bded476d9
This commit is contained in:
committed by
Facebook Github Bot
parent
62f47190fb
commit
5bc0197c78
@@ -318,7 +318,7 @@ namespace Facebook.Yoga
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.YGNodeStyleGetFlexBasis(_ygNode);
|
||||
return YogaValue.MarshalValue(Native.YGNodeStyleGetFlexBasis(_ygNode));
|
||||
}
|
||||
|
||||
set
|
||||
@@ -342,7 +342,7 @@ namespace Facebook.Yoga
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.YGNodeStyleGetWidth(_ygNode);
|
||||
return YogaValue.MarshalValue(Native.YGNodeStyleGetWidth(_ygNode));
|
||||
}
|
||||
|
||||
set
|
||||
@@ -366,7 +366,7 @@ namespace Facebook.Yoga
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.YGNodeStyleGetHeight(_ygNode);
|
||||
return YogaValue.MarshalValue(Native.YGNodeStyleGetHeight(_ygNode));
|
||||
}
|
||||
|
||||
set
|
||||
@@ -390,7 +390,7 @@ namespace Facebook.Yoga
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.YGNodeStyleGetMaxWidth(_ygNode);
|
||||
return YogaValue.MarshalValue(Native.YGNodeStyleGetMaxWidth(_ygNode));
|
||||
}
|
||||
|
||||
set
|
||||
@@ -410,7 +410,7 @@ namespace Facebook.Yoga
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.YGNodeStyleGetMaxHeight(_ygNode);
|
||||
return YogaValue.MarshalValue(Native.YGNodeStyleGetMaxHeight(_ygNode));
|
||||
}
|
||||
|
||||
set
|
||||
@@ -430,7 +430,7 @@ namespace Facebook.Yoga
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.YGNodeStyleGetMinWidth(_ygNode);
|
||||
return YogaValue.MarshalValue(Native.YGNodeStyleGetMinWidth(_ygNode));
|
||||
}
|
||||
|
||||
set
|
||||
@@ -450,7 +450,7 @@ namespace Facebook.Yoga
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.YGNodeStyleGetMinHeight(_ygNode);
|
||||
return YogaValue.MarshalValue(Native.YGNodeStyleGetMinHeight(_ygNode));
|
||||
}
|
||||
|
||||
set
|
||||
|
Reference in New Issue
Block a user