Skip to content

Commit 2fdfe05

Browse files
committed
texture error handling
1 parent fe44189 commit 2fdfe05

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

map/src/MapWindow/UI/AssetObjectEditor.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "AssetObjectEditor.h"
22

33
#include <imgui.h>
4+
#include <spdlog/spdlog.h>
45

56
#include "ObjectWidgets.h"
67

@@ -35,12 +36,23 @@ void Satisfactory3DMap::UI::AssetObjectEditor::AssetUObjectEditor::visit(s::USta
3536
void Satisfactory3DMap::UI::AssetObjectEditor::AssetUObjectEditor::visit(s::UTexture2D& o) {
3637
visit(static_cast<s::UObject&>(o));
3738
if (ImGui::CollapsingHeader("UTexture2D", ImGuiTreeNodeFlags_DefaultOpen)) {
38-
if (parent_.texture2d_ == nullptr) {
39-
parent_.texture2d_ = std::make_unique<OGLTexture2D>(o);
39+
if (!parent_.texture2d_error_.has_value()) {
40+
if (parent_.texture2d_ == nullptr) {
41+
try {
42+
parent_.texture2d_ = std::make_unique<OGLTexture2D>(o);
43+
} catch (const std::exception& ex) {
44+
parent_.texture2d_error_ = ex.what();
45+
spdlog::error("Error creating Texture2D: {}", ex.what());
46+
}
47+
}
48+
if (parent_.texture2d_ != nullptr) {
49+
ImVec2 size = ImGui::GetContentRegionAvail();
50+
size.y = size.x / static_cast<float>(parent_.texture2d_->sizeX()) *
51+
static_cast<float>(parent_.texture2d_->sizeY());
52+
ImGui::Image(static_cast<ImTextureID>(parent_.texture2d_->name()), size);
53+
}
54+
} else {
55+
ImGui::Text("Texture Error: %s", parent_.texture2d_error_.value().c_str());
4056
}
41-
ImVec2 size = ImGui::GetContentRegionAvail();
42-
size.y =
43-
size.x / static_cast<float>(parent_.texture2d_->sizeX()) * static_cast<float>(parent_.texture2d_->sizeY());
44-
ImGui::Image(static_cast<ImTextureID>(parent_.texture2d_->name()), size);
4557
}
4658
}

map/src/MapWindow/UI/AssetObjectEditor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#pragma once
22

33
#include <memory>
4+
#include <optional>
5+
#include <string>
46
#include <utility>
57

68
#include "SatisfactorySave/Pak/AssetExport.h"
@@ -26,6 +28,7 @@ namespace Satisfactory3DMap::UI {
2628
std::shared_ptr<s::AssetExport> assetExport_;
2729
const EventContext& ctx_;
2830
std::unique_ptr<OGLTexture2D> texture2d_;
31+
std::optional<std::string> texture2d_error_;
2932

3033
class AssetUObjectEditor : public s::AssetObjectVisitor {
3134
protected:

0 commit comments

Comments
 (0)