From e56b8aa2143170ce74491adb9afe8429fc7c61d2 Mon Sep 17 00:00:00 2001 From: T1ti <40864460+T1ti@users.noreply.github.com> Date: Sun, 31 Mar 2024 01:44:29 +0100 Subject: [PATCH] fix crashes and build bugs --- src/noggit/SceneObject.hpp | 1 + src/noggit/application/NoggitApplication.cpp | 1 + src/noggit/project/ApplicationProjectWriter.cpp | 1 + src/noggit/rendering/LiquidRender.cpp | 4 ++++ src/noggit/rendering/WMOGroupRender.cpp | 8 ++++++-- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/noggit/SceneObject.hpp b/src/noggit/SceneObject.hpp index 617aaa6a..2f8cd8d0 100755 --- a/src/noggit/SceneObject.hpp +++ b/src/noggit/SceneObject.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/src/noggit/application/NoggitApplication.cpp b/src/noggit/application/NoggitApplication.cpp index 56cebb13..043ac159 100755 --- a/src/noggit/application/NoggitApplication.cpp +++ b/src/noggit/application/NoggitApplication.cpp @@ -1,5 +1,6 @@ #include #include +#include namespace Noggit::Application { diff --git a/src/noggit/project/ApplicationProjectWriter.cpp b/src/noggit/project/ApplicationProjectWriter.cpp index a24f21a7..0ea1aeee 100755 --- a/src/noggit/project/ApplicationProjectWriter.cpp +++ b/src/noggit/project/ApplicationProjectWriter.cpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace Noggit::Project { diff --git a/src/noggit/rendering/LiquidRender.cpp b/src/noggit/rendering/LiquidRender.cpp index c66dbc2b..87148bb2 100755 --- a/src/noggit/rendering/LiquidRender.cpp +++ b/src/noggit/rendering/LiquidRender.cpp @@ -51,6 +51,10 @@ void LiquidRender::draw(math::frustum const& frustum } else { + // In some cases samplers_upload_buf becomes empty and causes crash + if (samplers_upload_buf.size() < N_SAMPLERS) + samplers_upload_buf.resize(N_SAMPLERS); + std::fill(samplers_upload_buf.begin(), samplers_upload_buf.end(), -1); for (std::size_t j = 0; j < render_layer.texture_samplers.size(); ++j) diff --git a/src/noggit/rendering/WMOGroupRender.cpp b/src/noggit/rendering/WMOGroupRender.cpp index 31c5e663..c995920b 100755 --- a/src/noggit/rendering/WMOGroupRender.cpp +++ b/src/noggit/rendering/WMOGroupRender.cpp @@ -338,9 +338,13 @@ void WMOGroupRender::initRenderBatches() std::size_t batch_counter = 0; for (auto& batch : _wmo_group->_batches) { - for (std::size_t i = 0; i < (batch.vertex_end - batch.vertex_start + 1); ++i) + // some custom models have bugged batch.vertex_end as 0, avoid crash + if (batch.vertex_end >= batch.vertex_start) { - _render_batch_mapping[batch.vertex_start + i] = static_cast(batch_counter + 1); + for (std::size_t i = 0; i < (batch.vertex_end - batch.vertex_start + 1); ++i) + { + _render_batch_mapping[batch.vertex_start + i] = static_cast(batch_counter + 1); + } } std::uint32_t flags = 0;