From 2c6a1ffc6c456a6f713c869d07dd66de4a37227a Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Fri, 1 Mar 2024 12:16:30 +0100 Subject: [PATCH 1/3] Fix #95411: Collada export crashes if temporary file is not accessible This can happen e.g. when relative "//" is in Preferences > File Paths > Temporary Files is used. It seems other libraries (such as USD) guard against this themselves, for Collada, we apparently have to step in. Now check if file could be accessed and not export anything otherwise. --- source/blender/io/collada/DocumentExporter.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/blender/io/collada/DocumentExporter.cpp b/source/blender/io/collada/DocumentExporter.cpp index f2039a3d7aa..3c5f9a9d7e6 100644 --- a/source/blender/io/collada/DocumentExporter.cpp +++ b/source/blender/io/collada/DocumentExporter.cpp @@ -171,6 +171,15 @@ int DocumentExporter::exportCurrentScene() clear_global_id_map(); COLLADABU::NativeString native_filename = make_temp_filepath(nullptr, ".dae"); + + /* Avoid crash if temp file cannot be written to. */ + if (BLI_access(native_filename.c_str(), W_OK) != 0) { + fprintf(stderr, + "Collada: Temp file (%s) cannot be written to. No Objects will be exported.\n", + native_filename.c_str()); + return 1; + } + COLLADASW::StreamWriter *writer = new COLLADASW::StreamWriter(native_filename); /* open */ -- 2.30.2 From ed3932e165c28549e03bef47b4f648dc4fd919e1 Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Fri, 1 Mar 2024 13:26:04 +0100 Subject: [PATCH 2/3] add missing include for windows --- source/blender/io/collada/DocumentExporter.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/blender/io/collada/DocumentExporter.cpp b/source/blender/io/collada/DocumentExporter.cpp index 3c5f9a9d7e6..05e7378d68d 100644 --- a/source/blender/io/collada/DocumentExporter.cpp +++ b/source/blender/io/collada/DocumentExporter.cpp @@ -109,6 +109,10 @@ extern "C" char build_hash[]; #include +#ifdef WIN32 +# include "BLI_winstuff.h" /* For `W_OK`. */ +#endif + const char *bc_CustomData_get_layer_name(const CustomData *data, const eCustomDataType type, int n) { int layer_index = CustomData_get_layer_index(data, type); -- 2.30.2 From 48fdb527ec441b33f51b492e347b649dadb51da1 Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Mon, 4 Mar 2024 16:20:10 +0100 Subject: [PATCH 3/3] catch COLLADASW::StreamWriterException instead of testing permissions --- .../blender/io/collada/DocumentExporter.cpp | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/source/blender/io/collada/DocumentExporter.cpp b/source/blender/io/collada/DocumentExporter.cpp index 05e7378d68d..68f05180da3 100644 --- a/source/blender/io/collada/DocumentExporter.cpp +++ b/source/blender/io/collada/DocumentExporter.cpp @@ -19,6 +19,7 @@ #include "COLLADASWColorOrTexture.h" #include "COLLADASWConstants.h" #include "COLLADASWEffectProfile.h" +#include "COLLADASWException.h" #include "COLLADASWImage.h" #include "COLLADASWInputList.h" #include "COLLADASWInstanceCamera.h" @@ -109,10 +110,6 @@ extern "C" char build_hash[]; #include -#ifdef WIN32 -# include "BLI_winstuff.h" /* For `W_OK`. */ -#endif - const char *bc_CustomData_get_layer_name(const CustomData *data, const eCustomDataType type, int n) { int layer_index = CustomData_get_layer_index(data, type); @@ -175,17 +172,16 @@ int DocumentExporter::exportCurrentScene() clear_global_id_map(); COLLADABU::NativeString native_filename = make_temp_filepath(nullptr, ".dae"); - - /* Avoid crash if temp file cannot be written to. */ - if (BLI_access(native_filename.c_str(), W_OK) != 0) { - fprintf(stderr, - "Collada: Temp file (%s) cannot be written to. No Objects will be exported.\n", - native_filename.c_str()); + COLLADASW::StreamWriter *writer; + try { + writer = new COLLADASW::StreamWriter(native_filename); + } + catch (COLLADASW::StreamWriterException &e) { + e.printMessage(); + fprintf(stderr, "Collada: No Objects will be exported.\n"); return 1; } - COLLADASW::StreamWriter *writer = new COLLADASW::StreamWriter(native_filename); - /* open */ writer->startDocument(); -- 2.30.2