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:
parent
c6f1525f55
commit
df5e01d4eb
@ -27,8 +27,20 @@ namespace hex::ui {
|
|||||||
ImGui::TextUnformatted("hex.ui.pattern_drawer.visualizer.unknown"_lang);
|
ImGui::TextUnformatted("hex.ui.pattern_drawer.visualizer.unknown"_lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_lastVisualizerError.empty())
|
if (!m_lastVisualizerError.empty()) {
|
||||||
ImGui::TextUnformatted(m_lastVisualizerError.c_str());
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <romfs/romfs.hpp>
|
#include <romfs/romfs.hpp>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
#include <hex/helpers/logger.hpp>
|
||||||
|
|
||||||
namespace hex::plugin::visualizers {
|
namespace hex::plugin::visualizers {
|
||||||
|
|
||||||
@ -97,7 +98,6 @@ namespace hex::plugin::visualizers {
|
|||||||
ImGuiExt::Texture s_texture;
|
ImGuiExt::Texture s_texture;
|
||||||
std::fs::path s_texturePath;
|
std::fs::path s_texturePath;
|
||||||
|
|
||||||
std::fs::path s_texturePathOld;
|
|
||||||
u32 s_vertexCount;
|
u32 s_vertexCount;
|
||||||
|
|
||||||
const auto isIndexInRange = [](auto index) {
|
const auto isIndexInRange = [](auto index) {
|
||||||
@ -153,10 +153,10 @@ namespace hex::plugin::visualizers {
|
|||||||
if (minCamera[3] != 0)
|
if (minCamera[3] != 0)
|
||||||
minCamera = minCamera * (1.0F / minCamera[3]);
|
minCamera = minCamera * (1.0F / minCamera[3]);
|
||||||
|
|
||||||
float max_X = std::max(std::fabs(minCamera[0]), std::fabs(maxCamera[0]));
|
float maxX = std::max(std::fabs(minCamera[0]), std::fabs(maxCamera[0]));
|
||||||
float max_Y = std::max(std::fabs(minCamera[1]), std::fabs(maxCamera[1]));
|
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) {
|
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);
|
buffers.indices = gl::Buffer<T>(gl::BufferType::Index, vectors.indices);
|
||||||
|
|
||||||
if (validateVector(vectors.vertices, vertexCount, 3, "Positions", errorMessage)) {
|
if (validateVector(vectors.vertices, vertexCount, 3, "Positions", errorMessage)) {
|
||||||
if ((indexType == IndexType::Undefined || vectors.indices.empty()) && vertexCount % 3 != 0)
|
if ((indexType == IndexType::Undefined || vectors.indices.empty()) && vertexCount % 3 != 0) {
|
||||||
throw std::runtime_error("Without indices vertices must be a multiple of 3");
|
throw std::runtime_error("Error: Vertex count must be a multiple of 3");
|
||||||
else
|
} else
|
||||||
buffers.vertices = gl::Buffer<float>(gl::BufferType::Vertex, vectors.vertices);
|
buffers.vertices = gl::Buffer<float>(gl::BufferType::Vertex, vectors.vertices);
|
||||||
} else
|
} else {
|
||||||
throw std::runtime_error(errorMessage);
|
throw std::runtime_error(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
if (validateVector(vectors.colors, vertexCount, 4, "Colors", errorMessage))
|
if (validateVector(vectors.colors, vertexCount, 4, "Colors", errorMessage))
|
||||||
buffers.colors = gl::Buffer<float>(gl::BufferType::Vertex, vectors.colors);
|
buffers.colors = gl::Buffer<float>(gl::BufferType::Vertex, vectors.colors);
|
||||||
else
|
else {
|
||||||
throw std::runtime_error(errorMessage);
|
throw std::runtime_error(errorMessage);
|
||||||
|
}
|
||||||
if (validateVector(vectors.normals, vertexCount, 3, "Normals", errorMessage))
|
if (validateVector(vectors.normals, vertexCount, 3, "Normals", errorMessage))
|
||||||
buffers.normals = gl::Buffer<float>(gl::BufferType::Vertex, vectors.normals);
|
buffers.normals = gl::Buffer<float>(gl::BufferType::Vertex, vectors.normals);
|
||||||
else
|
else {
|
||||||
throw std::runtime_error(errorMessage);
|
throw std::runtime_error(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
if (validateVector(vectors.uv, vertexCount, 2, "UV coordinates", errorMessage))
|
if (validateVector(vectors.uv, vertexCount, 2, "UV coordinates", errorMessage))
|
||||||
buffers.uv = gl::Buffer<float>(gl::BufferType::Vertex, vectors.uv);
|
buffers.uv = gl::Buffer<float>(gl::BufferType::Vertex, vectors.uv);
|
||||||
else
|
else {
|
||||||
throw std::runtime_error(errorMessage);
|
throw std::runtime_error(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
vertexArray.addBuffer(0, buffers.vertices);
|
vertexArray.addBuffer(0, buffers.vertices);
|
||||||
vertexArray.addBuffer(1, buffers.colors, 4);
|
vertexArray.addBuffer(1, buffers.colors, 4);
|
||||||
@ -428,18 +431,18 @@ namespace hex::plugin::visualizers {
|
|||||||
lineBuffers.indices = gl::Buffer<T>(gl::BufferType::Index, lineVectors.indices);
|
lineBuffers.indices = gl::Buffer<T>(gl::BufferType::Index, lineVectors.indices);
|
||||||
|
|
||||||
if (validateVector(lineVectors.vertices, vertexCount, 3, "Positions", errorMessage)) {
|
if (validateVector(lineVectors.vertices, vertexCount, 3, "Positions", errorMessage)) {
|
||||||
if ((indexType == IndexType::Undefined || lineVectors.indices.empty()) && vertexCount % 3 != 0)
|
if ((indexType == IndexType::Undefined || lineVectors.indices.empty()) && vertexCount % 3 != 0) {
|
||||||
throw std::runtime_error("Without indices vertices must be a multiple of 3");
|
throw std::runtime_error("Error: Vertex count must be a multiple of 3");
|
||||||
else
|
} else
|
||||||
lineBuffers.vertices = gl::Buffer<float>(gl::BufferType::Vertex, lineVectors.vertices);
|
lineBuffers.vertices = gl::Buffer<float>(gl::BufferType::Vertex, lineVectors.vertices);
|
||||||
} else
|
} else {
|
||||||
throw std::runtime_error(errorMessage);
|
throw std::runtime_error(errorMessage);
|
||||||
|
}
|
||||||
if (validateVector(lineVectors.colors, vertexCount, 4, "Colors", errorMessage))
|
if (validateVector(lineVectors.colors, vertexCount, 4, "Colors", errorMessage))
|
||||||
lineBuffers.colors = gl::Buffer<float>(gl::BufferType::Vertex, lineVectors.colors);
|
lineBuffers.colors = gl::Buffer<float>(gl::BufferType::Vertex, lineVectors.colors);
|
||||||
else
|
else {
|
||||||
throw std::runtime_error(errorMessage);
|
throw std::runtime_error(errorMessage);
|
||||||
|
}
|
||||||
vertexArray.addBuffer(0, lineBuffers.vertices);
|
vertexArray.addBuffer(0, lineBuffers.vertices);
|
||||||
vertexArray.addBuffer(1, lineBuffers.colors, 4);
|
vertexArray.addBuffer(1, lineBuffers.colors, 4);
|
||||||
|
|
||||||
@ -594,7 +597,7 @@ namespace hex::plugin::visualizers {
|
|||||||
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
|
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
|
||||||
ImGui::SameLine();
|
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_translation = { { 0.0F, 0.0F, -3.0F } };
|
||||||
s_rotation = { { 0.0F, 0.0F, 0.0F } };
|
s_rotation = { { 0.0F, 0.0F, 0.0F } };
|
||||||
s_scaling = 1.0F;
|
s_scaling = 1.0F;
|
||||||
@ -638,7 +641,6 @@ namespace hex::plugin::visualizers {
|
|||||||
if (s_shouldReset) {
|
if (s_shouldReset) {
|
||||||
s_shouldReset = false;
|
s_shouldReset = false;
|
||||||
s_shouldUpdateLightSource = true;
|
s_shouldUpdateLightSource = true;
|
||||||
|
|
||||||
if (s_drawMode == GL_TRIANGLES) {
|
if (s_drawMode == GL_TRIANGLES) {
|
||||||
Vectors<T> vectors;
|
Vectors<T> vectors;
|
||||||
|
|
||||||
@ -649,17 +651,17 @@ namespace hex::plugin::visualizers {
|
|||||||
s_badIndices.clear();
|
s_badIndices.clear();
|
||||||
auto indexCount = vectors.indices.size();
|
auto indexCount = vectors.indices.size();
|
||||||
if (indexCount < 3 || indexCount % 3 != 0) {
|
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);
|
auto booleans = std::views::transform(vectors.indices,isIndexInRange);
|
||||||
if (!std::accumulate(std::begin(booleans), std::end(booleans), true, std::logical_and<>())) {
|
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)
|
for (auto badIndex : s_badIndices)
|
||||||
badIndicesStr += std::to_string(badIndex) + ", ";
|
errorMessage += std::to_string(badIndex) + ", ";
|
||||||
badIndicesStr.pop_back();
|
errorMessage.pop_back();
|
||||||
badIndicesStr.pop_back();
|
errorMessage.pop_back();
|
||||||
badIndicesStr += hex::format(" for {} vertices",s_vertexCount);
|
errorMessage += hex::format(" for {} vertices",s_vertexCount);
|
||||||
throw std::runtime_error(badIndicesStr);
|
throw std::runtime_error(errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -682,17 +684,17 @@ namespace hex::plugin::visualizers {
|
|||||||
lineVectors.indices = patternToArray<T>(indicesPattern.get());
|
lineVectors.indices = patternToArray<T>(indicesPattern.get());
|
||||||
auto indexCount = lineVectors.indices.size();
|
auto indexCount = lineVectors.indices.size();
|
||||||
if (indexCount < 3 || indexCount % 3 != 0) {
|
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();
|
s_badIndices.clear();
|
||||||
if (!std::ranges::all_of(lineVectors.indices,isIndexInRange)) {
|
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)
|
for (auto badIndex : s_badIndices)
|
||||||
badIndicesStr += std::to_string(badIndex) + ", ";
|
errorMessage += std::to_string(badIndex) + ", ";
|
||||||
badIndicesStr.pop_back();
|
errorMessage.pop_back();
|
||||||
badIndicesStr.pop_back();
|
errorMessage.pop_back();
|
||||||
badIndicesStr += hex::format(" for {} vertices",s_vertexCount);
|
errorMessage += hex::format(" for {} vertices",s_vertexCount);
|
||||||
throw std::runtime_error(badIndicesStr);
|
throw std::runtime_error(errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user