[csharp,iOS] Fix callbacks on AOT #386
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix-logger-xamarinios"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When using AOT mode on Mono one can't use instance methods for callbacks, the compiler needs the MonoPInvokeCallback attribute on a static method to know how to get back to the managed world.
This worked fine without the change in JIT mode.
I not sure if we should use a MONO flag for this stuff as this could be needed for other usage that not only on iOS.
The adicional change is that one should as good practice call Dispose on the YogaNode when using callbacks to make sure we remove the handler from our dictionary, i was trying to write a test for this.. but i saw TestMeasureFuncWithDestructor was already there, but it doesn't seem correct to me, can you check @splhack.I'll look into this.
Ok after internal feedback from Alex Corrado i got a new implementation for the fix using the native ref context of Yoga.
The test for the Parent destructor is failing for me on AOT .. still looking at that one.
can you take a look at #387 ?
@splhack It looks like a more complicated way of doing the same thing? I do see one improvement: using a weak GCHandle and only allocating one of them.
Also note that neither PR appears to ever free the GCHandle
Ah, I haven't seen the updated diff.
revised in #388
@splhack has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Could you rebase this onto the current master too? I'll merge this and #388
It's rebased on top of master..
@splhack has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
@@ -44,0 +39,4 @@
Logger(level, message);
}
if (level == YogaLogLevel.Error)
You need to store the delegate in a static field, otherwise the GC will collect it and the app will crash when the callback is called:
@@ -568,1 +577,3 @@
private YogaSize MeasureInternal(
#if __IOS__
[ObjCRuntime.MonoPInvokeCallback(typeof(YogaMeasureFunc))]
#endif
Your patch never calls
GCHandle.Free
.Also you allocate a GCHandle both SetMeasureFunction and SetBaselineFunction, if both are called one of the values stored with YGNodeSetContext will be overwritten. The same will happen if either function is called more than once.
@@ -44,0 +39,4 @@
Logger(level, message);
}
if (level == YogaLogLevel.Error)
@splhack can you take a note on this in your PR ?
@@ -568,1 +577,3 @@
private YogaSize MeasureInternal(
#if __IOS__
[ObjCRuntime.MonoPInvokeCallback(typeof(YogaMeasureFunc))]
#endif
@splhack pr #388 fixes this.
@@ -44,0 +39,4 @@
Logger(level, message);
}
if (level == YogaLogLevel.Error)
sure
Pull request closed