18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 21:15:20 +01:00

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.
This commit is contained in:
2026-11-30 15:42:51 +01:00
parent 6a716b6720
commit 0426a44f71
3 changed files with 33 additions and 6 deletions
+2 -2
View File
@@ -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")
+25 -3
View File
@@ -1,17 +1,39 @@
#include "stdafx.h"
#include <thread>
#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);
}
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;
}
+6 -1
View File
@@ -1943,7 +1943,12 @@ void TSubModel::serialize(std::ostream &s, std::vector<TSubModel *> &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);