| 36 | } |
| 37 | |
| 38 | bool ScriptRunner::start(std::string scriptPath, std::string displayName, std::string titleIdHex) |
| 39 | { |
| 40 | if (mState.load() != State::Idle) { |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | mPath = std::move(scriptPath); |
| 45 | mName = std::move(displayName); |
| 46 | mTitleIdHex = std::move(titleIdHex); |
| 47 | mBridge.reset(); |
| 48 | ScriptConsole::get().reset(); |
| 49 | ckpt_script_abort_reset(); |
| 50 | |
| 51 | // Breadcrumb the start on the main thread: if the worker faults mid-run the |
| 52 | // "exited with" line from ScriptEngine::run never appears, so this line being |
| 53 | // the last script trace pins the crash to this script's execution. |
| 54 | Logging::info("[script] starting '{}' ({}), title {}", mName, mPath, mTitleIdHex.empty() ? "<none>" : mTitleIdHex); |
| 55 | |
| 56 | mState.store(State::Running); |
| 57 | if (!Threads::create(std::optional<size_t>(THREAD_STACK), ScriptRunner::runThread)) { |
| 58 | mState.store(State::Idle); |
| 59 | Logging::error("[script] worker thread creation failed for '{}'", mName); |
| 60 | return false; |
| 61 | } |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | void ScriptRunner::runThread(void) |
| 66 | { |