microsoft / Chakra-Samples

Repository for Chakra JavaScript engine related samples.
MIT License
216 stars 84 forks source link

Access Violation #5

Closed SrinivasGourarum closed 8 years ago

SrinivasGourarum commented 8 years ago

Could you please brief on how the issue https://github.com/Microsoft/Chakra-Samples/issues/4 got resolved. We are facing a similar issue. There is access violation exception/ engine execution exception whenever there is a call on UI thread and succeding calls on the JS thread results in exception.

liminzhu commented 8 years ago

Thanks for the post :). I've briefed in the last thread. Hopefully that will help you with your issue but if not, feel free to discuss more with us.

Thanks, Limin Zhu Chakra, Microsoft

SrinivasGourarum commented 8 years ago

Thank you. The solution worked for us.

SrinivasGourarum commented 8 years ago

Hi,

There still seems to be an access violation when I enable finalizer callback when creating external object. when I pass "null" in place of finalizer callback, there is no access violation.

JavaScriptValue.CreateExternalObject(new IntPtr(objId), null);// no access viloation

JavaScriptValue.CreateExternalObject(new IntPtr(objId), ExternalCustomObjectFinalizeCallback);//access violation

public static void onExternalCustomObjectFinalizeCallback(IntPtr data) { //notifying the c# about the object to be collected }

Is it again a case of garbage collection? If so, how do we avoid it?

liminzhu commented 8 years ago

It's possible that ExternalCustomObjectFinalizeCallback is collected by GC. Can you try adding the line to hold on to the finalize callback,

public static readonly JavaScriptObjectFinalizeCallback finalizeDelegate = ExternalCustomObjectFinalizeCallback;

And pass finalizeDelegate to CreateExternalObject?

SrinivasGourarum commented 8 years ago

This seems to do the trick for the most part. I am still looking into a particular scenario which could result in access violation. I will get back if the issue persists.

SrinivasGourarum commented 8 years ago

That was all. I did not encounter any more AVs. Thanks a lot.