From c6a2d916a8e4962b22fecdf8a2db765f42ea4a93 Mon Sep 17 00:00:00 2001 From: antopilo Date: Mon, 16 Sep 2024 21:42:35 -0400 Subject: [PATCH] Fixed crash when html file is empty and when canvas fails to aprse --- Nuake/src/Resource/UI.cpp | 10 +++++----- Nuake/src/Scene/Systems/UISystem.cpp | 29 +++++++++++++++++++--------- Nuake/src/UI/Inspector.h | 5 +++++ Nuake/src/UI/Nodes/Canvas.cpp | 6 +----- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/Nuake/src/Resource/UI.cpp b/Nuake/src/Resource/UI.cpp index 24fdbe1f..d2c44f64 100644 --- a/Nuake/src/Resource/UI.cpp +++ b/Nuake/src/Resource/UI.cpp @@ -28,7 +28,7 @@ UIResource::UIResource(const std::string& path) : canvas->uuid = this->ID; canvas = CanvasParser::Get().Parse(canvas, FileSystem::RelativeToAbsolute(path)); - if (!canvas) + if (canvas != nullptr) { canvas->SetInputManager(inputManager); canvas->ComputeLayout(defaultSize); @@ -37,7 +37,7 @@ UIResource::UIResource(const std::string& path) : void UIResource::Tick() { - if (canvas) + if (canvas != nullptr) { canvas->Tick(); } @@ -50,7 +50,7 @@ void UIResource::Draw() RenderCommand::SetClearColor({ 0, 0, 0, 0 }); RenderCommand::Clear(); - if (canvas) + if (canvas != nullptr) { canvas->Draw(); } @@ -61,7 +61,7 @@ void UIResource::Draw() void UIResource::Resize(const Vector2& size) { framebuffer->QueueResize(size); - if (canvas) + if (canvas != nullptr) { canvas->ComputeLayout(size); } @@ -75,7 +75,7 @@ void UIResource::Reload() } canvas = CanvasParser::Get().Parse(canvas, FileSystem::RelativeToAbsolute(filePath)); - if (canvas) + if (canvas != nullptr) { canvas->SetInputManager(inputManager); canvas->ComputeLayout(framebuffer->GetSize()); diff --git a/Nuake/src/Scene/Systems/UISystem.cpp b/Nuake/src/Scene/Systems/UISystem.cpp index aa301723..000f9572 100644 --- a/Nuake/src/Scene/Systems/UISystem.cpp +++ b/Nuake/src/Scene/Systems/UISystem.cpp @@ -48,18 +48,29 @@ namespace Nuake { auto ui = ResourceManager::GetResource(uiViewComponent.UIResource); bool sourceHasChanged = false; - for (auto& fileAssociated : ui->GetCanvas()->GetSourceFiles()) + if (ui->GetCanvas() == nullptr) { - if (!fileAssociated) - { - continue; - } - - // Re-fetching the file object because the Scan might have invalided the pointer. - if (FileSystem::GetFile(fileAssociated->GetRelativePath())->GetHasBeenModified()) + if (FileSystem::GetFile(uiViewComponent.UIFilePath.file->GetRelativePath())->GetHasBeenModified()) { sourceHasChanged = true; - FileSystem::GetFile(fileAssociated->GetRelativePath())->SetHasBeenModified(false); + FileSystem::GetFile(uiViewComponent.UIFilePath.file->GetRelativePath())->SetHasBeenModified(false); + } + } + else + { + for (auto& fileAssociated : ui->GetCanvas()->GetSourceFiles()) + { + if (!fileAssociated) + { + continue; + } + + // Re-fetching the file object because the Scan might have invalided the pointer. + if (FileSystem::GetFile(fileAssociated->GetRelativePath())->GetHasBeenModified()) + { + sourceHasChanged = true; + FileSystem::GetFile(fileAssociated->GetRelativePath())->SetHasBeenModified(false); + } } } diff --git a/Nuake/src/UI/Inspector.h b/Nuake/src/UI/Inspector.h index 05443e39..0e907bd7 100644 --- a/Nuake/src/UI/Inspector.h +++ b/Nuake/src/UI/Inspector.h @@ -96,6 +96,11 @@ namespace NuakeUI static void DrawInspector(std::shared_ptr canvas) { + if (canvas == nullptr) + { + return; + } + if (ImGui::Begin("Inspector")) { if (ImGui::BeginTabBar("MyTabBar")) diff --git a/Nuake/src/UI/Nodes/Canvas.cpp b/Nuake/src/UI/Nodes/Canvas.cpp index 3d36d836..a1aaf676 100644 --- a/Nuake/src/UI/Nodes/Canvas.cpp +++ b/Nuake/src/UI/Nodes/Canvas.cpp @@ -55,15 +55,11 @@ namespace NuakeUI void Canvas::ComputeLayout(Vector2 size) { - if (!mRootNode) + if (!mRootNode || mInputManager) return; Renderer::Get().SetViewportSize(size); - float x, y; - x = mInputManager->GetMouseX(); - y = mInputManager->GetMouseY(); - auto root = mRootNode->GetYogaNode(); // Recompute the node tree.