From 0426a44f71b3a5fb7aafc623e94ef2c6a96b8926 Mon Sep 17 00:00:00 2001 From: Hirek193 Date: Mon, 30 Nov 2026 15:42:51 +0100 Subject: [PATCH] fix(e3d): the -e3d export no longer crashes on a submodel without a matrix A submodel whose definition breaks off before its transform (no "type:" in its header) is still attached to the tree, without a matrix, and TSubModel::serialize dereferenced that matrix. It is written as -1 now, which the binary loader reads back as no matrix, so the .e3d holds the same tree the .t3d gives. The -e3d mode also runs the log service now. Without it nothing logged during the conversion came out, neither the included files the conversion scripts read from the standard output nor the error that names the broken submodel. A model that loaded nothing ends with exit code 1 and a message instead of a crash. --- EU07.cpp | 4 ++-- export_e3d_standalone.cpp | 28 +++++++++++++++++++++++++--- model/Model3d.cpp | 7 ++++++- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/EU07.cpp b/EU07.cpp index 19703dbe1..6b7ed17b9 100644 --- a/EU07.cpp +++ b/EU07.cpp @@ -48,7 +48,7 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others #endif #endif -void export_e3d_standalone(std::string in, std::string out, int flags, bool dynamic); +int export_e3d_standalone(std::string in, std::string out, int flags, bool dynamic); int export_btf_standalone(std::string in, std::string out); int generate_nodebank_previews(int Argc, char *Argv[]); @@ -144,7 +144,7 @@ int main(int argc, char *argv[]) std::string out(argv[3]); int flags = std::stoi(std::string(argv[4])); int dynamic = std::stoi(std::string(argv[5])); - export_e3d_standalone(in, out, flags, dynamic); + exitcode = export_e3d_standalone(in, out, flags, dynamic); } // standalone generation of preview images of the node bank models: -generate-nodebank-previews [options] else if (argc >= 2 && std::string(argv[1]) == "-generate-nodebank-previews") diff --git a/export_e3d_standalone.cpp b/export_e3d_standalone.cpp index ecdd4ab9c..6a1ae29fc 100644 --- a/export_e3d_standalone.cpp +++ b/export_e3d_standalone.cpp @@ -1,17 +1,39 @@ #include "stdafx.h" +#include + #include "model/Model3d.h" #include "utilities/Globals.h" +#include "utilities/Logs.h" #include "rendering/renderer.h" -void export_e3d_standalone(std::string in, std::string out, int flags, bool dynamic) +int export_e3d_standalone(std::string in, std::string out, int flags, bool dynamic) { Global.iConvertModels = flags; Global.iWriteLogEnabled = 2; Global.ParserLogIncludes = true; + // the log goes to the standard output only, where the conversion scripts read the included files from, so it is + // written from the start. without the log service nothing logged here would come out at all + OpenLogFiles(); + std::jthread logservice(LogService); + GfxRenderer = gfx_renderer_factory::get_instance()->create("null"); TModel3d model; model.LoadFromTextFile(in, dynamic); model.Init(); - model.SaveToBinFile(out); -} \ No newline at end of file + auto result{0}; + if (model.GetSMRoot() == nullptr) + { + ErrorLog("Bad model: failed to load 3d model \"" + in + "\""); + result = 1; + } + else + { + model.SaveToBinFile(out); + } + + // the process ends without destructors, so the log service writes out what's left before it goes + StopLogService(); + logservice.join(); + return result; +} diff --git a/model/Model3d.cpp b/model/Model3d.cpp index f3ddbc4a5..7f60b0bc8 100644 --- a/model/Model3d.cpp +++ b/model/Model3d.cpp @@ -1943,7 +1943,12 @@ void TSubModel::serialize(std::ostream &s, std::vector &models, std if (m_material > 0 && Global.iConvertModels & 16) flags &= ~0x30; // don't save phase information, will be guessed on binary load from material sn_utils::ls_uint32(s, flags); - sn_utils::ls_int32(s, (int32_t)get_container_pos(transforms, *fMatrix)); + // a submodel whose definition broke off before its transform (see Load()) has no matrix. -1 is what the binary + // loader reads back as no matrix + if (fMatrix != nullptr) + sn_utils::ls_int32(s, (int32_t)get_container_pos(transforms, *fMatrix)); + else + sn_utils::ls_int32(s, -1); sn_utils::ls_int32(s, m_geometry.vertex_count); sn_utils::ls_int32(s, m_geometry.vertex_offset);