fix: 退出 SIGSEGV 与 VkShaderEXT 泄漏——生命周期三层秩序
- 根因:~Application 体内 Logger::Shutdown() 先于成员析构执行, Device 销毁期间 Vulkan validation 回调仍打日志 → spdlog 悬空调用 - 修复:app 置于 main 独立作用域,所有成员析构完毕后再 Shutdown - 退出序 = waitIdle(~Application 体内)→ 成员析构(shader 等 Device 子对象销毁)→ Logger::Shutdown - 顺带注释掉窗口全透明(调试期遗留)
This commit is contained in:
+55
-38
@@ -14,6 +14,7 @@
|
||||
//
|
||||
|
||||
#include <Engine/Core/Application.h>
|
||||
#include <Engine/Core/Time.h>
|
||||
#include <Engine/Core/Window.h> // SetInputCapture(Application.h 只前置声明)
|
||||
#include <Engine/Core/Log.h>
|
||||
#include <Engine/Core/Stats.h>
|
||||
@@ -67,15 +68,22 @@ namespace
|
||||
// Editor 注入:引擎门面 + 沙盒能力回调(环境异步切换等)
|
||||
InitEditor();
|
||||
|
||||
SetEnv();
|
||||
// 默认环境(IBL 四件套):经资产层加载(compute 预积分,毫秒级),
|
||||
// 其余环境在 Stats 面板里按需 lazy 加载后切换
|
||||
const auto env = GetAssets().LoadEnvironment(kEnvPaths[0]);
|
||||
if (env.Valid()) {
|
||||
GetRenderer().SetEnvironment(GetAssets().GetEnvironment(env));
|
||||
}
|
||||
|
||||
const auto suntemple = GetAssets().LoadModel("assets/models/demo/asset.fbx");
|
||||
/*
|
||||
const auto suntemple = GetAssets().LoadModel(kTemplePath);
|
||||
auto entityhandle = scene.CreateEntity("SunTemple");
|
||||
entityhandle.AddComponent<MeshRendererComponent>(MeshRendererComponent{suntemple});
|
||||
*/
|
||||
|
||||
scene.CreateEntity();
|
||||
scene.CreateEntity();
|
||||
scene.CreateEntity();
|
||||
scene.CreateEntity("test entity");
|
||||
scene.CreateEntity("test entity");
|
||||
scene.CreateEntity("test entity");
|
||||
|
||||
const auto gun = GetAssets().LoadModel("assets/models/m1911/M1911.fbx");
|
||||
if (gun.Valid()) {
|
||||
@@ -84,10 +92,23 @@ namespace
|
||||
m_Gun.AddComponent<AnimationComponent>();
|
||||
auto& gt = m_Gun.GetComponent<TransformComponent>();
|
||||
gt.SetPosition(glm::vec3(0.0f, 1.2f, -6.0f));
|
||||
// 物理验证:Dynamic 刚体(默认 Box halfExtents 0.5),
|
||||
// 出生位置悬空 → 应下落至地面静止(Transform 由物理写回)
|
||||
m_Gun.AddComponent<RigidBodyComponent>();
|
||||
} else {
|
||||
ENGINE_WARN("m1911 model not loaded, animation test skipped");
|
||||
}
|
||||
|
||||
// 地面:程序化纯色平面(半边长 15,中心 y=-0.5)+ 静态盒刚体
|
||||
const auto ground = GetAssets().CreatePlane(15.0f, 140, 140, 145);
|
||||
m_Ground = scene.CreateEntity("Ground");
|
||||
m_Ground.GetComponent<TransformComponent>()
|
||||
.SetPosition(glm::vec3(0.0f, -0.5f, 0.0f)); // dirty → 帧循环统一 Compose
|
||||
m_Ground.AddComponent<MeshRendererComponent>(MeshRendererComponent{ground});
|
||||
auto& groundRb = m_Ground.AddComponent<RigidBodyComponent>();
|
||||
groundRb.type = RigidBodyComponent::BodyType::Static;
|
||||
groundRb.boxHalfExtents = glm::vec3(15.0f, 0.1f, 15.0f); // 平面顶点烘焙 ±15,不能用默认 0.5
|
||||
|
||||
/*
|
||||
const auto gun = GetAssets().LoadModel("assets/models/m1911/M1911.fbx");
|
||||
if (gun.Valid()) {
|
||||
@@ -177,26 +198,24 @@ namespace
|
||||
*/
|
||||
}
|
||||
|
||||
void OnUpdate(f32 deltaTime) override
|
||||
void OnUpdate(const FrameTime& frameTime) override
|
||||
{
|
||||
// 暂停时冻结动画时钟(帧历史验证:暂停后 Temporal Diff
|
||||
// 视图应在 2 帧内整屏变黑;相机移动同样会被 diff 捕捉到)
|
||||
if (!m_PauseAnim)
|
||||
{
|
||||
m_Time += deltaTime;
|
||||
}
|
||||
|
||||
// 相机(WASD/Space/Shift 移动;位姿读写实体 Transform)
|
||||
// 相机(WASD/Space/Shift 移动;位姿读写实体 Transform)。
|
||||
// 编辑器相机走真实轨:暂停(timeScale=0)时仍可飞行观察
|
||||
m_Camera.GetComponent<CameraComponent>()
|
||||
.camera.Update(GetWindow(),
|
||||
m_Camera.GetComponent<TransformComponent>(),
|
||||
deltaTime);
|
||||
frameTime.UnscaledDt());
|
||||
|
||||
// 旋转动画:编辑 Transform 分量后 Compose 重算 world
|
||||
// 旋转动画:编辑 Transform 分量后 Compose 重算 world。
|
||||
// 动画时钟 = Time::Elapsed()(scaled 累计,暂停自动冻结——
|
||||
// 帧历史验证:暂停后 Temporal Diff 视图 2 帧内整屏变黑)
|
||||
for (size_t i = 0; i < m_Spinners.size(); ++i)
|
||||
{
|
||||
auto& t = m_Spinners[i].GetComponent<TransformComponent>();
|
||||
t.SetRotation(glm::vec3(0.0f, m_Time * 60.0f + static_cast<f32>(i) * 40.0f, 0.0f));
|
||||
t.SetRotation(glm::vec3(
|
||||
0.0f, static_cast<f32>(Time::Elapsed()) * 60.0f +
|
||||
static_cast<f32>(i) * 40.0f, 0.0f));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,15 +253,6 @@ namespace
|
||||
ENGINE_INFO("App: window resized to {}x{}", event.width, event.height);
|
||||
}
|
||||
|
||||
void SetEnv(int index = 0) {
|
||||
// 默认环境(IBL 四件套):经资产层加载(compute 预积分,毫秒级),
|
||||
// 其余环境在 Stats 面板里按需 lazy 加载后切换
|
||||
const auto env = GetAssets().LoadEnvironment(kEnvPaths[index]);
|
||||
if (env.Valid()) {
|
||||
GetRenderer().SetEnvironment(GetAssets().GetEnvironment(env));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// Editor 注入:门面指针 + 反向能力回调(面板 → 沙盒)
|
||||
void InitEditor()
|
||||
@@ -254,7 +264,8 @@ namespace
|
||||
ctx.app = this;
|
||||
ctx.getEnvIndex = [this] { return m_EnvIndex; };
|
||||
ctx.setEnvIndex = [this](int index) { m_EnvIndex = index; };
|
||||
ctx.pauseAnim = &m_PauseAnim;
|
||||
// 继承原沙盒默认:初始暂停(StatsPanel 的 Pause Simulation 开关恢复)
|
||||
Time::SetTimeScale(0.0f);
|
||||
m_Editor->Init(ctx);
|
||||
|
||||
// 输入归属:覆盖 EnableImGui 的全局 WantCapture* 谓词
|
||||
@@ -275,8 +286,6 @@ namespace
|
||||
EntityHandle m_Ground{};
|
||||
EntityHandle m_Gun{}; // 骨骼动画验证实体(M1911)
|
||||
std::vector<EntityHandle> m_Spinners;
|
||||
f32 m_Time = 0.0f;
|
||||
bool m_PauseAnim = true; // 冻结动画时钟(Editor 面板可开关)
|
||||
int m_EnvIndex = kDefaultEnv;
|
||||
|
||||
// ---- 异步模型加载(SunTemple)----
|
||||
@@ -287,17 +296,25 @@ namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
SandboxApp app;
|
||||
Logger::Initialize();
|
||||
|
||||
try
|
||||
{
|
||||
app.Run();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
ENGINE_FATAL("Exception: {}", e.what());
|
||||
return -1;
|
||||
}
|
||||
SandboxApp app;
|
||||
|
||||
try
|
||||
{
|
||||
app.Run();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
ENGINE_FATAL("Exception: {}", e.what());
|
||||
Logger::Shutdown();
|
||||
return -1;
|
||||
}
|
||||
} // app 析构:成员(Device/Renderer/Window…)全部销毁完毕
|
||||
|
||||
// 日志必须最后关:Device 析构期间 Vulkan validation 回调仍在
|
||||
// 打日志(销毁资源时报 VUID),logger 先亡 = 悬空调用 SIGSEGV
|
||||
Logger::Shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user