From 7ba2d2caf58bafb40c22c5b773f86bc330e1a041 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 30 Jun 2024 21:57:26 +0200 Subject: [PATCH] Recast: fix trailing extension delimiter on model names when loading .gset files The code assumed an extension of 3 characters, but .gset is 4 and is also supported, causing a trailing '.' as it only truncates the training 4 characters (including the null char). The code now searches for the extension delimiter and gets the actual model name regardless of the length of presence of an extension. --- src/naveditor/main.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/naveditor/main.cpp b/src/naveditor/main.cpp index 4fcf41d8..2fc49955 100644 --- a/src/naveditor/main.cpp +++ b/src/naveditor/main.cpp @@ -119,6 +119,15 @@ void generate_points(float* pts, int count, float dx, float dy, float dz) } } +void get_model_name(const std::string& nameIn, std::string& nameOut) +{ + const size_t charPos = nameIn.find_last_of("."); + + nameOut = charPos == string::npos + ? nameIn + : nameIn.substr(0, charPos); +} + void auto_load(const char* path, BuildContext& ctx, Editor*& editor,InputGeom*& geom, string& meshName) { string geom_path = std::string(path); @@ -140,7 +149,7 @@ void auto_load(const char* path, BuildContext& ctx, Editor*& editor,InputGeom*& if (editor && geom) { editor->handleMeshChanged(geom); - editor->m_modelName = meshName.substr(0, meshName.size() - 4); + get_model_name(meshName, editor->m_modelName); } } @@ -985,7 +994,7 @@ int not_main(int argc, char** argv) if (editor && geom) { editor->handleMeshChanged(geom); - editor->m_modelName = meshName.substr(0, meshName.size() - 4); + get_model_name(meshName, editor->m_modelName); } if (geom || editor) @@ -1059,7 +1068,7 @@ int not_main(int argc, char** argv) if (editor && geom) { editor->handleMeshChanged(geom); - editor->m_modelName = meshName.substr(0, meshName.size() - 4); + get_model_name(meshName, editor->m_modelName); } // This will ensure that tile & poly bits are updated in tiled editor.