__main_argc_argv` called before runtime initialization

19 views
Skip to first unread message

キャロウ マーク

unread,
Apr 15, 2024, 2:06:17 AMApr 15
to emscripten-discuss Sam Clegg via
When I try to load the .html for my compiled app under the debugger in Firefox I get a runtime exception:

native function `__main_argc_argv` called before runtime initialization

If I run without the debugger, the app runs.

I am using Emscripten’s default generated .html. Here are my Emscripten link options:

--source-map-base ./
--exclude-file '${PROJECT_SOURCE_DIR}/tests/testimages/cubemap*'
-s ALLOW_MEMORY_GROWTH=1
-s DISABLE_EXCEPTION_CATCHING=0
-s USE_SDL=2
-s USE_WEBGL2=1

plus a few —preload-file options for some image files.

Any idea why this is happening and how to fix it?

Regards

-Mark
signature.asc

Alon Zakai

unread,
Apr 15, 2024, 4:00:30 PMApr 15
to emscripte...@googlegroups.com
That is very strange. Based on those link flags, you did not modify how the application starts up, so I have no idea how it could break like that. If it only happens in the Firefox debugger then perhaps it is a Firefox debugger bug somehow? That seems unlikely too. But maybe try debuggers in other browsers and other versions of Firefox (in particular I would try Firefox Nightly).

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/A5D9183C-ABB3-4D89-81DC-3DB38CFD6600%40callow.im.

Sam Clegg

unread,
Apr 15, 2024, 4:16:01 PMApr 15
to emscripte...@googlegroups.com
When you have the debugger attached and you hit that error/assertion, what does the stack trace look like?

キャロウ マーク

unread,
Apr 15, 2024, 11:32:42 PMApr 15
to emscripte...@googlegroups.com


> On Apr 16, 2024, at 5:15, 'Sam Clegg' via emscripten-discuss <emscripte...@googlegroups.com> wrote:
>
> When you have the debugger attached and you hit that error/assertion, what does the stack trace look like?
>

The debugger does not show a stack trace.

signature.asc
Screenshot 2024-04-16 at 12.30.02.png

Sam Clegg

unread,
Apr 15, 2024, 11:39:58 PMApr 15
to emscripte...@googlegroups.com
Can you click on the little red arrow next to the "Aborted" message in the console?  It should show the stack trace.

If not, can you set a break point in the `abort` function in the JavaScript file?  That should certainly give you a backtrace when you hit it.


--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.


Regards

    -Mark

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

キャロウ マーク

unread,
Apr 16, 2024, 5:02:22 AMApr 16
to emscripte...@googlegroups.com

On Apr 16, 2024, at 12:39, 'Sam Clegg' via emscripten-discuss <emscripte...@googlegroups.com> wrote:

 
Can you click on the little red arrow next to the "Aborted" message in the console?  It should show the stack trace.

Aborted(Assertion failed: native function `__main_argc_argv` called before runtime initialization) es3loadtests.js:789:6
    createExportWrapper http://127.0.0.1:8080/es3loadtests.js:836
    <anonymous> debugger eval code:1

Here is the createExportWrapper function with the assert that is firing

function createExportWrapper(name, nargs) {
  return (...args) => {
    assert(runtimeInitialized, `native function \`${name}\` called before runtime initialization`);
    var f = wasmExports[name];
    assert(f, `exported native function \`${name}\` not found`);
    // Only assert for too many arguments. Too few can be valid since the missing arguments will be zero filled.
    assert(args.length <= nargs, `native function \`${name}\` called with ${args.length} args but expects ${nargs}`);
    return f(...args);
  };
}

This is only happening when the code is compiled -O0, -g. When compiled -O3 the app runs with the debugger open.

Regards

    -Mark

signature.asc

Sam Clegg

unread,
Apr 16, 2024, 1:51:13 PMApr 16
to emscripte...@googlegroups.com
It makes sense that this would only happen in debug build since these checks (the ones performed by 
createExportWrapper) are only included in debug builds.

I still can't seem to see how `__main_argc_argv` is being called.  The `debugger eval code` might be a clue.. are you typing something into the DevTools to trigger this?

I assume your main function is just being called in the normal way that emscripten does.  e.g. via run -> doRun -> callMain -> wasmExports[`__main_argc_argv`]?  or are you calling main some other way?

Can you try setting a break point in `callMain` perhaps?    Do you hit that before the error you see?

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages