fix: 修复项目切换时运行时和系统重复初始化问题
This commit is contained in:
@@ -631,6 +631,13 @@ function App() {
|
|||||||
await pluginLoader.unloadProjectPlugins(pluginManager);
|
await pluginLoader.unloadProjectPlugins(pluginManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 清理场景(会清理所有实体和系统)
|
||||||
|
// Clear scene (clears all entities and systems)
|
||||||
|
const scene = Core.scene;
|
||||||
|
if (scene) {
|
||||||
|
scene.end();
|
||||||
|
}
|
||||||
|
|
||||||
// 清理模块系统
|
// 清理模块系统
|
||||||
const engineService = EngineService.getInstance();
|
const engineService = EngineService.getInstance();
|
||||||
engineService.clearModuleSystems();
|
engineService.clearModuleSystems();
|
||||||
|
|||||||
@@ -14,6 +14,15 @@ import { EditorEngineSync } from '../services/EditorEngineSync';
|
|||||||
let engineInitialized = false;
|
let engineInitialized = false;
|
||||||
let engineInitializing = false;
|
let engineInitializing = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置引擎初始化状态(在项目关闭时调用)
|
||||||
|
* Reset engine initialization state (called when project is closed)
|
||||||
|
*/
|
||||||
|
export function resetEngineState(): void {
|
||||||
|
engineInitialized = false;
|
||||||
|
engineInitializing = false;
|
||||||
|
}
|
||||||
|
|
||||||
export interface EngineState {
|
export interface EngineState {
|
||||||
initialized: boolean;
|
initialized: boolean;
|
||||||
running: boolean;
|
running: boolean;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import {
|
|||||||
type GameRuntimeConfig
|
type GameRuntimeConfig
|
||||||
} from '@esengine/runtime-core';
|
} from '@esengine/runtime-core';
|
||||||
import { getMaterialManager } from '@esengine/material-system';
|
import { getMaterialManager } from '@esengine/material-system';
|
||||||
|
import { resetEngineState } from '../hooks/useEngine';
|
||||||
import { convertFileSrc } from '@tauri-apps/api/core';
|
import { convertFileSrc } from '@tauri-apps/api/core';
|
||||||
import { IdGenerator } from '../utils/idGenerator';
|
import { IdGenerator } from '../utils/idGenerator';
|
||||||
import { TauriAssetReader } from './TauriAssetReader';
|
import { TauriAssetReader } from './TauriAssetReader';
|
||||||
@@ -245,7 +246,14 @@ export class EngineService {
|
|||||||
ctx.uiInputSystem.unbind?.();
|
ctx.uiInputSystem.unbind?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 清理 viewport | Clear viewport
|
||||||
|
this.unregisterViewport('editor-viewport');
|
||||||
|
|
||||||
|
// 重置 useEngine 的模块级状态 | Reset useEngine module-level state
|
||||||
|
resetEngineState();
|
||||||
|
|
||||||
this._modulesInitialized = false;
|
this._modulesInitialized = false;
|
||||||
|
this._initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1159,6 +1159,11 @@ export class PluginManager implements IService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 重置初始化状态,允许下次重新初始化运行时
|
||||||
|
// Reset initialized flag to allow re-initialization
|
||||||
|
this.initialized = false;
|
||||||
|
logger.debug('Scene systems cleared, runtime can be re-initialized');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user