| 131 | |
| 132 | #if defined(__EMSCRIPTEN__) |
| 133 | static void PreStepEmscripten(void* _ctx) |
| 134 | { |
| 135 | StepContext* ctx = (StepContext*)_ctx; |
| 136 | const RunLoopParams* params = ctx->m_Params; |
| 137 | HEngine engine = (HEngine)ctx->m_Engine; |
| 138 | |
| 139 | int exit_code = 0; |
| 140 | int result = 0; |
| 141 | params->m_EngineGetResult(engine, &result, &exit_code, NULL, NULL); |
| 142 | |
| 143 | if (RESULT_OK != result) |
| 144 | { |
| 145 | dmCrash::SetEnabled(false); // because emscripten_cancel_main_loop throws an 'unwind' exception (emscripten issue #11682) |
| 146 | emscripten_pause_main_loop(); // stop further callbacks |
| 147 | emscripten_cancel_main_loop(); // Causes an exception (emscripten issue #11682) |
| 148 | |
| 149 | params->m_EngineDestroy(engine); |
| 150 | engine = 0; |
| 151 | |
| 152 | if (RESULT_REBOOT == result) |
| 153 | { |
| 154 | // Only request argc/argv when actually rebooting |
| 155 | int argc = 0; |
| 156 | char** argv = NULL; |
| 157 | params->m_EngineGetResult(engine, NULL, NULL, &argc, &argv); |
| 158 | |
| 159 | ctx->m_Engine = params->m_EngineCreate(argc, argv); |
| 160 | |
| 161 | // Free argv allocated within dmEngineGetResult |
| 162 | for (int i = 0; i < argc; ++i) |
| 163 | free(argv[i]); |
| 164 | free(argv); |
| 165 | |
| 166 | if (ctx->m_Engine) |
| 167 | { |
| 168 | // Won't return from this |
| 169 | emscripten_set_main_loop_arg(PerformStep, ctx, 0, 1); |
| 170 | } |
| 171 | else { |
| 172 | dmLogError("Engine failed to reboot"); |
| 173 | exit_code = 1; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | dmLogInfo("Engine exited with code %d", exit_code); |
| 178 | exit(exit_code); |
| 179 | } |
| 180 | |
| 181 | if (!dmCrash::IsEnabled()) { |
| 182 | dmCrash::SetEnabled(true); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | static void PerformStep(void* _ctx) |
| 187 | { |
no test coverage detected