Code Monkey home page Code Monkey logo

Comments (4)

liminzhu avatar liminzhu commented on May 22, 2024

Thanks for sharing :). I work on the JSRT team at Microsoft. Do you think you can share a repro/dump with us so that my team could take a closer look? If you don't want to share it publicly here, feel free to reach me at [email protected].

Limin [MSFT]

from chakra-samples.

liminzhu avatar liminzhu commented on May 22, 2024

Issue resolved offline.

from chakra-samples.

SrinivasGourarum avatar SrinivasGourarum commented on May 22, 2024

Could you please brief on how the issue 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.

from chakra-samples.

liminzhu avatar liminzhu commented on May 22, 2024

Thanks for asking, and yes of course.

On a high level, most of the AV issues here come from that in the C# app, installed callbacks are not retained and got garbage collected before being invoked. For example, you create a function like this,

//JsNativeFunction callback
private static JavaScriptValue nativeFunction(JavaScriptValue callee, bool isConstructCall, JavaScriptValue[] arguments, ushort argumentCount, IntPtr callbackData) 
{
    //do something here
}

...

JsCreateFunction(nativeFunction, callbackData, func);

The nativeFunction can be garbage collected. So instead you want to hold on to the delegate like in our sample and write,

//JsNativeFunction callback
private static JavaScriptValue nativeFunction(JavaScriptValue callee, bool isConstructCall, JavaScriptValue[] arguments, ushort argumentCount, IntPtr callbackData) 
{
    //do something here
}

private static readonly JavaScriptNativeFunction nativeFunctionDelegate = nativeFunction;

...

JsCreateFunction(nativeFunctionDelegate , callbackData, func);

Another trick is that you want to call JsAddRef on JavaScript objects that are not going to be stored somewhere on the stack; otherwise you may hit AV as well.

Given this appears to be a common problem, we will look into improving our documentation.

Thanks,
Limin Zhu
Chakra, Microsoft

from chakra-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.