SM 38 Windows Crash on Shutdown

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

SM 38 Windows Crash on Shutdown

markus.moenig
Hi,

using SM 38 on Windows I always get a crash on shutdown, here is what I do:

/* The class of the global object. */
static JSClass globalClass = {
    "global",
    JSCLASS_GLOBAL_FLAGS,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    nullptr, nullptr, nullptr, nullptr,
    JS_GlobalObjectTraceHook
};


    if (!JS_Init()) return 1;

    JSRuntime *rt = JS_NewRuntime( 8L * 1024 * 1024 * 20 );
    if (!rt) return 1;

    JS::RuntimeOptionsRef(rt).setBaseline(true).setIon(true).setAsmJS(true);

    JSContext *cx = JS_NewContext(rt, 8192);
    if (!cx) return 1;

    JS_SetErrorReporter(rt, reportError);

    JSAutoRequest ar(cx);

    RootedObject global(cx );
    global = JS_NewGlobalObject(cx, &globalClass, nullptr, JS::FireOnNewGlobalHook);    

    if (!global) return 1;

    JSAutoCompartment *ac=new JSAutoCompartment(cx, global);    
    JS_InitStandardClasses(cx, global);


    // --- Do stuff, but even if all of this is commented out still crashes

   // ---

    delete ac;

    JS_DestroyContext(cx);
    JS_DestroyRuntime(rt);    
    JS_ShutDown();

It crashes in JS_DestroyContext with

Hit MOZ_CRASH() at c:\Users\markusm\moz\mozjs-38.3.0\js\src\jscntxt.cpp:157


Any ideas ?

Thanks

Markus
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

Re: SM 38 Windows Crash on Shutdown

Steve Fink-4
On 09/22/2015 02:46 AM, Markus wrote:

> Hi,
>
> using SM 38 on Windows I always get a crash on shutdown, here is what I do:
>
> /* The class of the global object. */
> static JSClass globalClass = {
>      "global",
>      JSCLASS_GLOBAL_FLAGS,
>      0,
>      0,
>      0,
>      0,
>      0,
>      0,
>      0,
>      nullptr, nullptr, nullptr, nullptr,
>      JS_GlobalObjectTraceHook
> };
>
>
>      if (!JS_Init()) return 1;
>
>      JSRuntime *rt = JS_NewRuntime( 8L * 1024 * 1024 * 20 );
>      if (!rt) return 1;
>
>      JS::RuntimeOptionsRef(rt).setBaseline(true).setIon(true).setAsmJS(true);
>
>      JSContext *cx = JS_NewContext(rt, 8192);
>      if (!cx) return 1;
>
>      JS_SetErrorReporter(rt, reportError);
>
>      JSAutoRequest ar(cx);
>
>      RootedObject global(cx );
>      global = JS_NewGlobalObject(cx, &globalClass, nullptr, JS::FireOnNewGlobalHook);
>
>      if (!global) return 1;
>
>      JSAutoCompartment *ac=new JSAutoCompartment(cx, global);
>      JS_InitStandardClasses(cx, global);
>
>
>      // --- Do stuff, but even if all of this is commented out still crashes
>
>     // ---
>
>      delete ac;
>
>      JS_DestroyContext(cx);
>      JS_DestroyRuntime(rt);
>      JS_ShutDown();
>
> It crashes in JS_DestroyContext with
>
> Hit MOZ_CRASH() at c:\Users\markusm\moz\mozjs-38.3.0\js\src\jscntxt.cpp:157
>
>
> Any ideas ?

Yes, that MOZ_CRASH points directly to the problem. As your code is
written, your JS_DestroyContext is within the scope of a JSAutoRequest.
You could do the same trick as you're doing with JSAutoCompartment, but
really it would be better to use

   {
     JSAutoRequest ar(cx);
     JSAutoCompartment ac(cx, global);
     ...
   }
   JS_DestroyContext(cx);

_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

Re: SM 38 Windows Crash on Shutdown

markus.moenig
In reply to this post by markus.moenig
Thanks Steve, that did the trick. I removed the JSAutoRequest object altogether as it is not really needed ? After that everything worked fine.
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine