diff --git a/src/editor/engine/lua/LuaSharedSandbox.js b/src/editor/engine/lua/LuaSharedSandbox.js index 4c12ef2..7883bbd 100644 --- a/src/editor/engine/lua/LuaSharedSandbox.js +++ b/src/editor/engine/lua/LuaSharedSandbox.js @@ -115,8 +115,8 @@ export class LuaSharedSandbox { // Запускаем main-loop сразу — он начнёт tick'ать как только будут coroutines. this._lastTickAt = performance.now(); this._startMainLoop(); - // Init батчами по 20 с yield между ними, чтобы UI не подвисал на 700+ скриптах. - const BATCH_SIZE = 20; + // Init батчами по 5 с задержкой 20мс между ними, чтобы UI отзывался. + const BATCH_SIZE = 5; let idx = 0; const initBatch = () => { if (this._isStopped) return; @@ -130,7 +130,7 @@ export class LuaSharedSandbox { } idx = end; if (idx < pending.length) { - setTimeout(initBatch, 0); + setTimeout(initBatch, 20); } else { // eslint-disable-next-line no-console console.log(`[LuaSharedSandbox] all ${pending.length} scripts kicked off`); @@ -199,13 +199,11 @@ export class LuaSharedSandbox { }) local co = coroutine.create(function() -- WATCHDOG: каждые 100000 инструкций — yield 1 кадр. - -- Защищает от tight-loop. yield обёрнут в pcall так как - -- внутри C-call boundary yield бросает ошибку — но в этом - -- случае tight-loop наш hook просто будет вызываться позже - -- (когда Lua вернётся из C-call) и yield сработает. + -- НЕ оборачиваем в pcall — внутри C-call boundary yield + -- упадёт ошибкой, что прервёт скрипт. Это лучше чем виснуть. debug.sethook(function() - pcall(coroutine.yield, 0.016) - end, "", 100000) + coroutine.yield(0.016) + end, "", 20000) -- pcall защищает от runtime-ошибок которые иначе крашат -- coroutine и могут повредить WASM-стейт. Возвраты -- handler'а намеренно поглощаются. diff --git a/src/editor/engine/lua/RobloxShim.js b/src/editor/engine/lua/RobloxShim.js index 114676e..5cc004c 100644 --- a/src/editor/engine/lua/RobloxShim.js +++ b/src/editor/engine/lua/RobloxShim.js @@ -1642,11 +1642,9 @@ export function registerRobloxShim(lua, opts) { -- (ok, ret1, ret2, ...) — мы их не используем. local co = coroutine.create(function() -- Тот же watchdog что и в _startSingleScript. - -- yield обёрнут в pcall: внутри C-call boundary yield бросает - -- ошибку, но hook будет вызван позже когда Lua вернётся. debug.sethook(function() - pcall(coroutine.yield, 0.016) - end, "", 100000) + coroutine.yield(0.016) + end, "", 20000) pcall(fn, a1, a2, a3, a4) end) __rbxl_register_coroutine(handlerId, co)