1
0
mirror of synced 2025-01-10 21:41:53 +01:00

impr: Better 3D Visualizer error messages, wrap long visualizer errors (#1969)

### Problem description
Long error messages were forcing the width of the window to span the
entire screen.

### Implementation description
The fix was sending the long message to the log and outputting a short
message to the 3d visualizer window.

---------

Co-authored-by: WerWolv <werwolv98@gmail.com>
This commit is contained in:
paxcut 2024-12-15 02:12:14 -07:00 committed by GitHub
parent c6f1525f55
commit df5e01d4eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 51 additions and 37 deletions

View File

@ -27,8 +27,20 @@ namespace hex::ui {
ImGui::TextUnformatted("hex.ui.pattern_drawer.visualizer.unknown"_lang);
}
if (!m_lastVisualizerError.empty())
ImGui::TextUnformatted(m_lastVisualizerError.c_str());
if (!m_lastVisualizerError.empty()) {
auto windowWidth = ImGui::GetContentRegionAvail().x-2 * ImGuiStyleVar_WindowPadding;
auto errorMessageSize = ImGui::CalcTextSize(m_lastVisualizerError.c_str());
if (errorMessageSize.x > windowWidth)
errorMessageSize.y *= 2;
auto errorMessageWindowSize = ImVec2(windowWidth, errorMessageSize.y);
if (ImGui::BeginChild("##error_message", errorMessageWindowSize, 0, ImGuiWindowFlags_HorizontalScrollbar)) {
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0F, 0.0F, 0.0F, 1.0F));
ImGui::TextUnformatted(m_lastVisualizerError.c_str());
ImGui::PopStyleColor();
}
ImGui::EndChild();
}
}
}

View File

@ -19,6 +19,7 @@
#include <romfs/romfs.hpp>
#include <numeric>
#include <hex/helpers/logger.hpp>
namespace hex::plugin::visualizers {
@ -97,7 +98,6 @@ namespace hex::plugin::visualizers {
ImGuiExt::Texture s_texture;
std::fs::path s_texturePath;
std::fs::path s_texturePathOld;
u32 s_vertexCount;
const auto isIndexInRange = [](auto index) {
@ -153,10 +153,10 @@ namespace hex::plugin::visualizers {
if (minCamera[3] != 0)
minCamera = minCamera * (1.0F / minCamera[3]);
float max_X = std::max(std::fabs(minCamera[0]), std::fabs(maxCamera[0]));
float max_Y = std::max(std::fabs(minCamera[1]), std::fabs(maxCamera[1]));
float maxX = std::max(std::fabs(minCamera[0]), std::fabs(maxCamera[0]));
float maxY = std::max(std::fabs(minCamera[1]), std::fabs(maxCamera[1]));
return std::max(max_X, max_Y);
return std::max(maxX, maxY);
}
void setDefaultUVs(std::vector<float> &uv, size_t size) {
@ -376,27 +376,30 @@ namespace hex::plugin::visualizers {
buffers.indices = gl::Buffer<T>(gl::BufferType::Index, vectors.indices);
if (validateVector(vectors.vertices, vertexCount, 3, "Positions", errorMessage)) {
if ((indexType == IndexType::Undefined || vectors.indices.empty()) && vertexCount % 3 != 0)
throw std::runtime_error("Without indices vertices must be a multiple of 3");
else
if ((indexType == IndexType::Undefined || vectors.indices.empty()) && vertexCount % 3 != 0) {
throw std::runtime_error("Error: Vertex count must be a multiple of 3");
} else
buffers.vertices = gl::Buffer<float>(gl::BufferType::Vertex, vectors.vertices);
} else
} else {
throw std::runtime_error(errorMessage);
}
if (validateVector(vectors.colors, vertexCount, 4, "Colors", errorMessage))
buffers.colors = gl::Buffer<float>(gl::BufferType::Vertex, vectors.colors);
else
else {
throw std::runtime_error(errorMessage);
}
if (validateVector(vectors.normals, vertexCount, 3, "Normals", errorMessage))
buffers.normals = gl::Buffer<float>(gl::BufferType::Vertex, vectors.normals);
else
else {
throw std::runtime_error(errorMessage);
}
if (validateVector(vectors.uv, vertexCount, 2, "UV coordinates", errorMessage))
buffers.uv = gl::Buffer<float>(gl::BufferType::Vertex, vectors.uv);
else
else {
throw std::runtime_error(errorMessage);
}
vertexArray.addBuffer(0, buffers.vertices);
vertexArray.addBuffer(1, buffers.colors, 4);
@ -428,18 +431,18 @@ namespace hex::plugin::visualizers {
lineBuffers.indices = gl::Buffer<T>(gl::BufferType::Index, lineVectors.indices);
if (validateVector(lineVectors.vertices, vertexCount, 3, "Positions", errorMessage)) {
if ((indexType == IndexType::Undefined || lineVectors.indices.empty()) && vertexCount % 3 != 0)
throw std::runtime_error("Without indices vertices must be a multiple of 3");
else
if ((indexType == IndexType::Undefined || lineVectors.indices.empty()) && vertexCount % 3 != 0) {
throw std::runtime_error("Error: Vertex count must be a multiple of 3");
} else
lineBuffers.vertices = gl::Buffer<float>(gl::BufferType::Vertex, lineVectors.vertices);
} else
} else {
throw std::runtime_error(errorMessage);
}
if (validateVector(lineVectors.colors, vertexCount, 4, "Colors", errorMessage))
lineBuffers.colors = gl::Buffer<float>(gl::BufferType::Vertex, lineVectors.colors);
else
else {
throw std::runtime_error(errorMessage);
}
vertexArray.addBuffer(0, lineBuffers.vertices);
vertexArray.addBuffer(1, lineBuffers.colors, 4);
@ -594,7 +597,7 @@ namespace hex::plugin::visualizers {
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
ImGui::SameLine();
if (ImGuiExt::DimmedButton("hex.ui.common.reset"_lang, ImVec2(renderingWindowSize.x-ImGui::GetCursorPosX(), 0))) {
if (ImGuiExt::DimmedButton("hex.ui.common.reset"_lang, ImVec2(renderingWindowSize.x+5-ImGui::GetCursorPosX(), 0))) {
s_translation = { { 0.0F, 0.0F, -3.0F } };
s_rotation = { { 0.0F, 0.0F, 0.0F } };
s_scaling = 1.0F;
@ -638,7 +641,6 @@ namespace hex::plugin::visualizers {
if (s_shouldReset) {
s_shouldReset = false;
s_shouldUpdateLightSource = true;
if (s_drawMode == GL_TRIANGLES) {
Vectors<T> vectors;
@ -649,17 +651,17 @@ namespace hex::plugin::visualizers {
s_badIndices.clear();
auto indexCount = vectors.indices.size();
if (indexCount < 3 || indexCount % 3 != 0) {
throw std::runtime_error("Index count must be a multiple of 3");
throw std::runtime_error("Error: IndexCount must be a multiple of 3");
}
auto booleans = std::views::transform(vectors.indices,isIndexInRange);
if (!std::accumulate(std::begin(booleans), std::end(booleans), true, std::logical_and<>())) {
std::string badIndicesStr = "Invalid indices: ";
std::string errorMessage = "Error: indices must be between 0 and the number of vertices minus one. Invalid indices: ";
for (auto badIndex : s_badIndices)
badIndicesStr += std::to_string(badIndex) + ", ";
badIndicesStr.pop_back();
badIndicesStr.pop_back();
badIndicesStr += hex::format(" for {} vertices",s_vertexCount);
throw std::runtime_error(badIndicesStr);
errorMessage += std::to_string(badIndex) + ", ";
errorMessage.pop_back();
errorMessage.pop_back();
errorMessage += hex::format(" for {} vertices",s_vertexCount);
throw std::runtime_error(errorMessage);
}
}
@ -682,17 +684,17 @@ namespace hex::plugin::visualizers {
lineVectors.indices = patternToArray<T>(indicesPattern.get());
auto indexCount = lineVectors.indices.size();
if (indexCount < 3 || indexCount % 3 != 0) {
throw std::runtime_error("Index count must be a multiple of 3");
throw std::runtime_error("Error: IndexCount must be a multiple of 3");
}
s_badIndices.clear();
if (!std::ranges::all_of(lineVectors.indices,isIndexInRange)) {
std::string badIndicesStr = "Invalid indices: ";
std::string errorMessage = "Error: indices must be between 0 and the number of vertices minus one. Invalid indices: ";
for (auto badIndex : s_badIndices)
badIndicesStr += std::to_string(badIndex) + ", ";
badIndicesStr.pop_back();
badIndicesStr.pop_back();
badIndicesStr += hex::format(" for {} vertices",s_vertexCount);
throw std::runtime_error(badIndicesStr);
errorMessage += std::to_string(badIndex) + ", ";
errorMessage.pop_back();
errorMessage.pop_back();
errorMessage += hex::format(" for {} vertices",s_vertexCount);
throw std::runtime_error(errorMessage);
}
}