From 29282c2a500e24e7834dcea9b4d2c9aad4aed4f5 Mon Sep 17 00:00:00 2001 From: Birk Magnussen <6238428+BMagnu@users.noreply.github.com> Date: Sat, 13 Jun 2026 13:21:00 +0900 Subject: [PATCH 1/2] Add safeguards for invalidated model instances and texture replace specifically --- code/model/modelrender.cpp | 6 +++++- code/ship/ship.cpp | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/code/model/modelrender.cpp b/code/model/modelrender.cpp index 5743cc874e2..23bd0275851 100644 --- a/code/model/modelrender.cpp +++ b/code/model/modelrender.cpp @@ -3195,8 +3195,12 @@ void model_render_set_wireframe_color(const color* clr) void modelinstance_replace_active_texture(polymodel_instance* pmi, const char* old_name, const char* new_name) { - Assert(pmi != nullptr); + if (pmi == nullptr) + return; + polymodel* pm = model_get(pmi->model_num); + if (pm == nullptr) + return; int final_index = -1; diff --git a/code/ship/ship.cpp b/code/ship/ship.cpp index 31485fc7c2d..bf8c6089f6a 100644 --- a/code/ship/ship.cpp +++ b/code/ship/ship.cpp @@ -8986,6 +8986,7 @@ void ship_delete( object * obj ) ct_ship_delete(shipp); model_delete_instance(shipp->model_instance_num); + shipp->model_instance_num = -1; // free up any weapon model instances for (int i = 0; i < shipp->weapons.num_primary_banks; ++i) From 5d6cbab97dd763883a27a43a95ced4b2173dde09 Mon Sep 17 00:00:00 2001 From: Birk Magnussen <6238428+BMagnu@users.noreply.github.com> Date: Sat, 13 Jun 2026 13:41:49 +0900 Subject: [PATCH 2/2] More guards --- code/ship/ship.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/ship/ship.cpp b/code/ship/ship.cpp index bf8c6089f6a..b95c7fb01af 100644 --- a/code/ship/ship.cpp +++ b/code/ship/ship.cpp @@ -19698,6 +19698,9 @@ void ship_page_out_textures(int ship_index, bool release) void ship_replace_active_texture(int ship_index, const char* old_name, const char* new_name) { + if (Ships[ship_index].model_instance_num < 0) + return; + polymodel_instance* pmi = model_get_instance(Ships[ship_index].model_instance_num); modelinstance_replace_active_texture(pmi, old_name, new_name); }