From ab6d3b2e15d9671a7f7748470a5ad39b22f71535 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 16 Nov 2021 15:04:46 +0100 Subject: [PATCH] gobj: Show better error if calling tex.write() with unknown extension --- panda/src/gobj/texture.cxx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index d6c30296d9..940944daef 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -30,6 +30,7 @@ #include "pnmImage.h" #include "pnmReader.h" #include "pfmFile.h" +#include "pnmFileTypeRegistry.h" #include "virtualFileSystem.h" #include "datagramInputFile.h" #include "datagramOutputFile.h" @@ -5176,11 +5177,19 @@ do_write_one(CData *cdata, const Filename &fullpath, int z, int n) { success = pfm.write(fullpath); } else { // Writing a normal, integer texture. + PNMFileType *type = + PNMFileTypeRegistry::get_global_ptr()->get_type_from_extension(fullpath); + if (type == nullptr) { + gobj_cat.error() + << "Texture::write() - couldn't determine type from extension: " << fullpath << endl; + return false; + } + PNMImage pnmimage; if (!do_store_one(cdata, pnmimage, z, n)) { return false; } - success = pnmimage.write(fullpath); + success = pnmimage.write(fullpath, type); } if (!success) {