Repository: godot
Issue: Exported mono game only works on Windows; HTML5 crashes, macOS has graphic issues and/or locks up
Labels: bug,platform:web,platform:macos,topic:rendering,needs testing,topic:dotnet,crash

### Godot version

3.5 beta 1 and 3.4 (stable)

### System information

macOS Monterey 12.1 on MacBook Air M1 (8 cores, 16GB RAM)

### Issue description

I'm using Godot Mono to build a 2d pixel game.
It works fine in the editor and when exporting to Windows (Desktop).

Here's a screenshot of the game running correctly on Windows:

![screeny](https://user-images.githubusercontent.com/574373/151711059-91065351-6fca-49ac-bb76-afa9ad2ede9b.jpg)

## HTML

Exporting to HTML works until the player moves into a new room (click any door) and I can see the following error.
Same is true when running the game from the editor, using "Run in browser"

```
[Log] Say: kitchen (tmp_js_export.js, line 347)
[Error] ERROR: Condition "!tclass" is true. Returned: ManagedType()
	onPrintError (tmp_js_export.js:362)
	put_char (tmp_js_export.js:9:25034)
	write (tmp_js_export.js:9:24201)
	write (tmp_js_export.js:9:56848)
	doWritev (tmp_js_export.js:9:76649)
	_fd_write (tmp_js_export.js:9:214498)
	wasm-stub
	<?>.wasm-function[__stdio_write]
	<?>.wasm-function[__vfprintf_internal]
	<?>.wasm-function[vfprintf]
	<?>.wasm-function[StdLogger::logv(char const*, void*, bool)]
	<?>.wasm-function[Logger::logf_error(char const*, ...)]
	<?>.wasm-function[Logger::log_error(char const*, char const*, int, char const*, char const*, Logger::ErrorType)]
	<?>.wasm-function[CompositeLogger::log_error(char const*, char const*, int, char const*, char const*, Logger::ErrorType)]
	<?>.wasm-function[_err_print_error(char const*, char const*, int, char const*, char const*, ErrorHandlerType)]
	<?>.wasm-function[_err_print_error(char const*, char const*, int, char const*, ErrorHandlerType)]
	<?>.wasm-function[ManagedType::from_class(_MonoClass*)]
	<?>.wasm-function[GDMonoMarshal::mono_object_to_variant(_MonoObject*)]
	<?>.wasm-function[godot_icall_2_665(MethodBind*, Object*, _MonoString*, _MonoArray*)]
	<?>.wasm-function[do_icall]
	<?>.wasm-function[do_icall_wrapper]
	<?>.wasm-function[interp_exec_method_full]
	<?>.wasm-function[interp_runtime_invoke]
	<?>.wasm-function[mono_jit_runtime_invoke]
	<?>.wasm-function[do_runtime_invoke]
	<?>.wasm-function[mono_runtime_try_invoke]
	<?>.wasm-function[mono_runtime_invoke]
	<?>.wasm-function[GDMonoUtils::runtime_invoke(_MonoMethod*, void*, void**, _MonoException**)]
	<?>.wasm-function[GDMonoMethod::invoke(_MonoObject*, Variant const**, _MonoException**) const]
	<?>.wasm-function[CSharpInstance::_call_multilevel(_MonoObject*, StringName const&, Variant const**, int)]
	<?>.wasm-function[CSharpInstance::call_multilevel(StringName const&, Variant const**, int)]
	<?>.wasm-function[Object::call_multilevel(StringName const&, Variant const**, int)]
	<?>.wasm-function[SceneTree::_call_input_pause(StringName const&, StringName const&, Ref<InputEvent> const&)]
	<?>.wasm-function[Viewport::input(Ref<InputEvent> const&)]
	<?>.wasm-function[Viewport::_vp_input(Ref<InputEvent> const&)]
	<?>.wasm-function[MethodBind1<Ref<InputEvent> const&>::call(Object*, Variant const**, int, Variant::CallError&)]
	<?>.wasm-function[Object::call(StringName const&, Variant const**, int, Variant::CallError&)]
	<?>.wasm-function[Object::call(StringName const&, Variant const&, Variant const&, Variant const&, Variant const&, Variant const&)]
	<?>.wasm-function[SceneTree::call_group_flags(unsigned int, StringName const&, StringName const&, Variant const&, Variant const&, Variant const&, Variant const&, Variant const&)]
	<?>.wasm-function[SceneTree::input_event(Ref<InputEvent> const&)]
	<?>.wasm-function[InputDefault::_parse_input_event_impl(Ref<InputEvent> const&, bool)]
	<?>.wasm-function[InputDefault::parse_input_event(Ref<InputEvent> const&)]
	<?>.wasm-function[OS_JavaScript::mouse_button_callback(int, int, double, double, int)]
	wasm-stub
	(anonyme Funktion)
	button_cb (tmp_js_export.js:9:283538)
	button_cb
```

## macOS

Exporting to macOS will result in a running app, however the player cannot move around because the whole level is messed up.
I can still click the "push" icon in the action bar on the left. It reacts to a click. Means: the game is running but not as expected.
It looks as if parts of the code haven't been executed. As I can see two player characters, I assume it never gets to the point where it finishes intializing the game.

![macos](https://user-images.githubusercontent.com/574373/151711158-5f663d5a-7b93-4ca7-9deb-76d899fcc5fb.jpg)

Here are logs generated by the game from start until to the point where it's running. I can tell it does still react because the messages about reducing and increasing the framerate when focus is lost and recovered, but that's all it does.


[2022-01-30_19.18.38_77400.log](https://github.com/godotengine/godot/files/7966604/2022-01-30_19.18.38_77400.log)
[godot.log](https://github.com/godotengine/godot/files/7966605/godot.log)

### Steps to reproduce

HTML: Export the game to HTML5 or run from browser.
For HTML, click on any door, see the player move into the new room, click once more and the game locks up and the error above pops up in the console.

For macOS, simply start the exported app.

### Minimal reproduction project

I can provide a copy of the game on request but don't want to upload the full project here. Please contact me at rene.ruppert@gmail.com or here in this issue and I can send a link to download the project.