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: prevent editor crash when importing large number of assets
esengine877f92c889e3
diff --git a/editor/src/asset/AssetDatabase.ts b/editor/src/asset/AssetDatabase.tsindex 1ce9d14c0..43e70815e 100644--- a/editor/src/asset/AssetDatabase.ts+++ b/editor/src/asset/AssetDatabase.ts@@ -460,6 +460,8 @@ export class AssetDatabase {const entries = await this.fs_.listDirectoryDetailed(absolutePath);+ const pendingMetas: string[] = [];+for (const entry of entries) {const childAbsolute = joinPath(absolutePath, entry.name);const childRelative = `${relativePath}/${entry.name}`;@@ -492,11 +494,19 @@ export class AssetDatabase {if (ASSET_EXTENSIONS.has(ext)) {const metaAbsolute = `${childAbsolute}.meta`;if (!await this.fs_.exists(metaAbsolute)) {- await this.ensureMeta(childRelative);+ pendingMetas.push(childRelative);}}}}++ const META_BATCH_SIZE = 50;+ for (let i = 0; i < pendingMetas.length; i++) {+ await this.ensureMeta(pendingMetas[i]);+ if (i > 0 && i % META_BATCH_SIZE === 0) {+ await new Promise(r => setTimeout(r, 0));+ }+ }}// =========================================================================diff --git a/editor/src/panels/content-browser/ContentBrowserPanel.ts b/editor/src/panels/content-browser/ContentBrowserPanel.tsindex c8c6b879b..90698acbf 100644--- a/editor/src/panels/content-browser/ContentBrowserPanel.ts+++ b/editor/src/panels/content-browser/ContentBrowserPanel.ts@@ -41,6 +41,8 @@ export class ContentBrowserPanel implements ContentBrowserState {private disposables_ = new DisposableStore();private refreshing_ = false;private refreshPending_ = false;+ private lastRefreshTime_ = 0;+ private refreshTimer_: ReturnType<typeof setTimeout> | null = null;private thumbnailCache_ = new ThumbnailCache();private disposeNavReg_: (() => void) | null = null;private treeVisible_ = localStorage.getItem('esengine.cb.treeVisible') !== 'false';@@ -191,11 +193,26 @@ export class ContentBrowserPanel implements ContentBrowserState {}async refresh(): Promise<void> {+ const THROTTLE_MS = 500;+if (this.refreshing_) {this.refreshPending_ = true;return;}++ const elapsed = Date.now() - this.lastRefreshTime_;+ if (elapsed < THROTTLE_MS) {+ if (!this.refreshTimer_) {+ this.refreshTimer_ = setTimeout(() => {+ this.refreshTimer_ = null;+ this.refresh();+ }, THROTTLE_MS - elapsed);+ }+ return;+ }+this.refreshing_ = true;+ this.lastRefreshTime_ = Date.now();try {if (this.rootFolder && this.projectPath) {this.rootFolder.loaded = false;diff --git a/editor/src/utils/path.ts b/editor/src/utils/path.tsindex 56b2d7002..172d82265 100644--- a/editor/src/utils/path.ts+++ b/editor/src/utils/path.ts@@ -56,6 +56,7 @@ export function isTransientFile(path: string): boolean {if (name === '.DS_Store' || name === 'Thumbs.db') return true;if (name.startsWith('.')) return true;if (name.endsWith('~') || name.endsWith('.swp') || name.endsWith('.bak')) return true;+ if (name.endsWith('.meta')) return true;if (TRANSIENT_PATTERN.test(name)) return true;return false;}