A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(native): the host evaluates a script by its size, not by strlen
esengine531f92977c5f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fe9025681..85d3c53fd 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -350,6 +350,13 @@ published separately; it ships inside the editor.### Fixed+- **A native build runs a script that holds a NUL character.** The desktop and+ mobile hosts measured the embedded SDK and the project's scripts with+ `strlen`, so the first NUL byte ended them. The script-graph runner carried+ three, and every packaged desktop game stopped at a SyntaxError in the SDK and+ drew nothing. Both are now evaluated by their size, and the runner writes its+ separator as an escape.+- **A mirror has no seam across it on WebGL2.** The prefiltered atlas stacks itsown mips, and the WebGL2 shader let the hardware pick one: wherever theoctahedral fold makes the derivatives jump, it read the neighbouring column,diff --git a/build-tools/tasks/native.js b/build-tools/tasks/native.jsindex 8ae2e94f3..e893d5eed 100644--- a/build-tools/tasks/native.js+++ b/build-tools/tasks/native.js@@ -130,7 +130,8 @@ async function generateSdkBundle(rootDir, genDir) {const embedded = '\n' + js;// A BYTE ARRAY, not a string literal: MSVC caps a literal at 65535 bytes and// counts the concatenated result too, so for an ~800 KB bundle neither one- // literal nor many works. NUL-terminated, so the host still reads a char*.+ // literal nor many works. NUL-terminated for QuickJS, which wants that byte+ // past the end — but measured by its size: JS may hold a NUL of its own.const bytes = Buffer.from(embedded, 'utf8');const rows = [];for (let at = 0; at < bytes.length; at += 32) {@@ -146,7 +147,8 @@ async function generateSdkBundle(rootDir, genDir) {+ rows.join('\n')+ '\n 0\n};\n'+ 'static const char* const kSdkBundleJS =\n'- + ' reinterpret_cast<const char*>(kSdkBundleBytes);\n';+ + ' reinterpret_cast<const char*>(kSdkBundleBytes);\n'+ + 'static const size_t kSdkBundleSize = sizeof(kSdkBundleBytes) - 1;\n';const headerPath = path.join(genDir, 'esengine_bundle.h');writeFileSync(headerPath, header, 'utf8');writeFileSync(path.join(genDir, 'esengine_bundle.embedded.js'), embedded, 'utf8');diff --git a/native/host/Runtime.cpp b/native/host/Runtime.cppindex adc91d527..d586b56a2 100644--- a/native/host/Runtime.cpp+++ b/native/host/Runtime.cpp@@ -347,9 +347,9 @@ void jsEntry(HostState& h) {JS_UpdateStackTop(h.rt);}-void evalJs(HostState& h, const char* src, const char* name) {+void evalJs(HostState& h, const std::string& src, const char* name) {jsEntry(h);- JSValue r = JS_Eval(h.js, src, strlen(src), name, JS_EVAL_TYPE_GLOBAL);+ JSValue r = JS_Eval(h.js, src.c_str(), src.size(), name, JS_EVAL_TYPE_GLOBAL);if (JS_IsException(r)) logJsError(h.js, name);JS_FreeValue(h.js, r);}@@ -437,7 +437,7 @@ void initRuntime(HostState& h) {// Layer 1: the real SDK bundle, embedded — installs `ESEngine`.const double tCtx = nowMs();std::string bcPath = h.cacheDir.empty() ? std::string() : (h.cacheDir + "/esengine.native.bc");- JSValue br = evalCachedScript(h, kSdkBundleJS, strlen(kSdkBundleJS), "esengine.native.js",+ JSValue br = evalCachedScript(h, kSdkBundleJS, kSdkBundleSize, "esengine.native.js",bcPath, "esengine.native.qjsbc");if (JS_IsException(br)) logJsError(h.js, "SDK bundle");JS_FreeValue(h.js, br);@@ -465,7 +465,7 @@ bool runPackagedGame(HostState& h) {}std::vector<u8> scripts = readAsset(h, "scripts.js");if (!scripts.empty()) {- evalJs(h, std::string(reinterpret_cast<const char*>(scripts.data()), scripts.size()).c_str(),+ evalJs(h, std::string(reinterpret_cast<const char*>(scripts.data()), scripts.size()),"scripts.js");}const double tScripts = nowMs();diff --git a/native/host/Runtime.hpp b/native/host/Runtime.hppindex 0e22bcf20..c6c411704 100644--- a/native/host/Runtime.hpp+++ b/native/host/Runtime.hpp@@ -142,7 +142,7 @@ void logJsError(JSContext* ctx, const char* where);void jsEntry(HostState& h);/** Evaluate a global script; exceptions are logged, not propagated. */-void evalJs(HostState& h, const char* src, const char* name);+void evalJs(HostState& h, const std::string& src, const char* name);/** Call a global function by name; missing is a no-op, exceptions are logged. */void callJs(HostState& h, const char* fn, int argc, JSValue* argv);diff --git a/sdk/src/logic/ScriptGraphRunner.ts b/sdk/src/logic/ScriptGraphRunner.tsindex f5deedcb2..47db6ab97 100644Binary files a/sdk/src/logic/ScriptGraphRunner.ts and b/sdk/src/logic/ScriptGraphRunner.ts differdiff --git a/tools/verify-desktop-render.mjs b/tools/verify-desktop-render.mjsindex ff19eba07..db2b22c58 100644--- a/tools/verify-desktop-render.mjs+++ b/tools/verify-desktop-render.mjs@@ -179,6 +179,10 @@ try {failed += 1;} else if (!verdict.rendered) {console.error(`✗ ${label}: ran and drew nothing — ${JSON.stringify(verdict)}`);+ // The host already said why, and a runner's log is the only place anyone+ // reads it: a SyntaxError in the SDK bundle looked like a blank screen.+ const said = result.output.split('\n').filter((l) => /\bERROR\b/.test(l));+ if (said.length > 0) console.error(said.slice(0, 12).join('\n'));failed += 1;} else {const points = desktopPixelsFor(label);