[Bf-blender-cvs] [c5f984d96c4] soc-2020-io-performance: Log errors in fopen and fclose.
Ankit Meel
noreply at git.blender.org
Wed Sep 16 13:05:52 CEST 2020
Commit: c5f984d96c4d1a34c1744f99020dd43e3b6f2721
Author: Ankit Meel
Date: Wed Sep 16 11:20:32 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rBc5f984d96c4d1a34c1744f99020dd43e3b6f2721
Log errors in fopen and fclose.
===================================================================
M source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
M source/blender/io/wavefront_obj/intern/obj_export_file_writer.hh
M source/blender/io/wavefront_obj/intern/obj_exporter.cc
===================================================================
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc b/source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
index ce329e00776..de3b1e5d910 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
+++ b/source/blender/io/wavefront_obj/intern/obj_export_file_writer.cc
@@ -109,6 +109,7 @@ bool OBJWriter::init_writer(const char *filepath)
{
outfile_ = fopen(filepath, "w");
if (!outfile_) {
+ std::perror(std::string("Error in creating the file at: ").append(filepath).c_str());
return false;
}
fprintf(outfile_, "# Blender %s\n# www.blender.org\n", BKE_blender_version_string());
@@ -448,14 +449,18 @@ MTLWriter::MTLWriter(const char *obj_filepath)
BLI_path_extension_replace(mtl_filepath, FILE_MAX, ".mtl");
mtl_outfile_ = fopen(mtl_filepath, "a");
if (!mtl_outfile_) {
- fprintf(stderr, "Error in opening file at %s\n", mtl_filepath);
+ std::perror(std::string("Error in creating the file at: ").append(mtl_filepath_).c_str());
return;
}
}
MTLWriter::~MTLWriter()
{
- fclose(mtl_outfile_);
+ if (mtl_outfile_ && fclose(mtl_outfile_)) {
+ std::cerr << "Error: could not close the MTL file properly, file may be corrupted."
+ << std::endl;
+ }
+}
}
void MTLWriter::append_materials(const OBJMesh &mesh_to_export)
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_file_writer.hh b/source/blender/io/wavefront_obj/intern/obj_export_file_writer.hh
index 847e32d1e6e..4734e1acc5f 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_file_writer.hh
+++ b/source/blender/io/wavefront_obj/intern/obj_export_file_writer.hh
@@ -61,9 +61,13 @@ class OBJWriter {
OBJWriter(const OBJExportParams &export_params) : export_params_(export_params)
{
}
+
~OBJWriter()
{
- fclose(outfile_);
+ if (outfile_ && fclose(outfile_)) {
+ std::cerr << "Error: could not close the OBJ file properly, file may be corrupted."
+ << std::endl;
+ }
}
bool init_writer(const char *filepath);
diff --git a/source/blender/io/wavefront_obj/intern/obj_exporter.cc b/source/blender/io/wavefront_obj/intern/obj_exporter.cc
index 90d284e24cc..06bb7599b62 100644
--- a/source/blender/io/wavefront_obj/intern/obj_exporter.cc
+++ b/source/blender/io/wavefront_obj/intern/obj_exporter.cc
@@ -112,7 +112,6 @@ static void export_frame(ViewLayer *view_layer,
{
OBJWriter frame_writer(export_params);
if (!frame_writer.init_writer(filepath)) {
- fprintf(stderr, "Error in creating the file: %s\n", filepath);
return;
}
More information about the Bf-blender-cvs
mailing list