Skip to content

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.

fix(native): the embedded SDK bundle is chunked, and BootLog's POSIX half is guarded

esengined2169a561f7b
diff --git a/build-tools/tasks/native.js b/build-tools/tasks/native.js
index b09db6f84..95b70945e 100644
--- a/build-tools/tasks/native.js
+++ b/build-tools/tasks/native.js
@@ -127,13 +127,26 @@ async function generateSdkBundle(rootDir, genDir) {
// out as a file too, because the bytecode step must compile these exact bytes
// for the host to accept the result (see precompileBundleBytecode).
const embedded = '\n' + js;
+ // MSVC refuses a string literal over 65535 bytes and the bundle is ~800 KB, so
+ // it is emitted as ADJACENT raw literals, which the language concatenates.
+ const CHUNK = 16384;
+ // The delimiter is what makes splitting safe at any offset; a bundle that
+ // contained it would end a literal early and ship truncated, silently.
+ if (embedded.includes(')ESJS"')) {
+ throw new Error('The SDK bundle contains the raw-string delimiter `)ESJS"` — '
+ + 'embedding it would truncate the bundle. Change the delimiter in generateSdkBundle.');
+ }
+ const chunks = [];
+ for (let at = 0; at < embedded.length; at += CHUNK) {
+ chunks.push(`R"ESJS(${embedded.slice(at, at + CHUNK)})ESJS"`);
+ }
const header =
'// The real esengine SDK, bundled (dist/index.native.bundled.js) — installs\n'
+ '// globalThis.ESEngine. Embedded by `cli native --quickjs` — DO NOT EDIT.\n'
+ '#pragma once\n'
- + 'static const char* kSdkBundleJS = R"ESJS('
- + embedded
- + ')ESJS";\n';
+ + 'static const char* kSdkBundleJS =\n'
+ + chunks.join('\n')
+ + ';\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/BootLog.cpp b/native/host/BootLog.cpp
index 7168e3408..76c21ef3e 100644
--- a/native/host/BootLog.cpp
+++ b/native/host/BootLog.cpp
@@ -9,12 +9,17 @@
#include <ctime>
#include <string>
-#include <sys/stat.h>
+#include <filesystem>
+// The crash handler is POSIX: signals, libunwind, dladdr. Windows catches a crash
+// through SEH and DbgHelp instead — a different implementation, not a different
+// spelling — so there the boot record works and the handler is absent.
+#if !defined(_WIN32)
#include <csignal>
#include <dlfcn.h>
#include <unistd.h>
#include <unwind.h>
+#endif
namespace eshost {
namespace {
@@ -58,11 +63,8 @@ std::string fileStamp() {
/** mkdir -p, for a public directory this app has never written to before. */
void mkdirs(const std::string& dir) {
- for (size_t i = 1; i <= dir.size(); i++) {
- if (i < dir.size() && dir[i] != '/') continue;
- const std::string part = dir.substr(0, i);
- if (!part.empty()) mkdir(part.c_str(), 0775);
- }
+ std::error_code ignored;
+ std::filesystem::create_directories(dir, ignored);
}
void writeLine(const char* prefix, const char* text) {
@@ -157,6 +159,15 @@ std::string publishPreviousCrash(const std::vector<std::string>& dirs) {
return {};
}
+#if defined(_WIN32)
+
+// A Windows crash handler is SetUnhandledExceptionFilter + DbgHelp, which is its
+// own piece of work; until it exists a crash leaves the boot record it had
+// written, and no backtrace.
+void installCrashHandler() {}
+
+#else
+
// =============================================================================
// The crash handler
// =============================================================================
@@ -258,4 +269,6 @@ void installCrashHandler() {
for (int sig : {SIGSEGV, SIGABRT, SIGBUS, SIGFPE, SIGILL}) sigaction(sig, &sa, nullptr);
}
+#endif // _WIN32
+
} // namespace eshost