release textures and model memory when a model load fails

The failure checks after parsing (bad detail levels, debris objects or
parents, and too many textures) run after the TXTR and GLOW chunks have
already loaded bitmaps, but model_load only deleted the polymodel, so
those bitmap slots were never released.  Page out the textures and free
the model through model_free, as the virtual POF cache already does for
models it loads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Goober5000andClaude Opus 5.5 committed 2026-10-08 03:04:02 -04:00
1 parent 4ff6c8c447
commit 5dd9f56deb
1 file changed
+5 -3
+5 -3
View File
@@ -3436,10 +3436,12 @@ int model_load(const char* filename, ship_info* sip, ErrorType error_type, bool
model_read_deferred_tasks deferredTasks;
if (read_and_process_model_file(pm, filename, n_subsystems, subsystems, error_type, deferredTasks) == modelread_status::FAIL) {
if (pm != NULL) {
delete pm;
if (pm != nullptr) {
// the load can fail after textures have been loaded and memory allocated
model_page_out_textures(pm, true);
model_free(pm);
}
Polygon_models[num] = NULL;
Polygon_models[num] = nullptr;
unpause_parse();
return -1;