Fixed crash when html file is empty and when canvas fails to aprse
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -48,18 +48,29 @@ namespace Nuake
|
||||
{
|
||||
auto ui = ResourceManager::GetResource<UIResource>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +96,11 @@ namespace NuakeUI
|
||||
|
||||
static void DrawInspector(std::shared_ptr<Canvas> canvas)
|
||||
{
|
||||
if (canvas == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ImGui::Begin("Inspector"))
|
||||
{
|
||||
if (ImGui::BeginTabBar("MyTabBar"))
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user