Fix C++ STL importer unused function result warning
Fix unused function result warnings for usages of `fread` in the C++ .stl importer, by actually using the returned error code. Reviewed By: sybren Differential Revision: https://developer.blender.org/D15189
This commit is contained in:
parent
c39e932631
commit
5c726dd4ef
|
@ -29,6 +29,17 @@
|
|||
|
||||
namespace blender::io::stl {
|
||||
|
||||
void stl_import_report_error(FILE *file)
|
||||
{
|
||||
fprintf(stderr, "STL Importer: failed to read file");
|
||||
if (feof(file)) {
|
||||
fprintf(stderr, ", end of file reached.\n");
|
||||
}
|
||||
else if (ferror(file)) {
|
||||
perror("Error");
|
||||
}
|
||||
}
|
||||
|
||||
void importer_main(bContext *C, const STLImportParams &import_params)
|
||||
{
|
||||
Main *bmain = CTX_data_main(C);
|
||||
|
@ -56,7 +67,10 @@ void importer_main(Main *bmain,
|
|||
uint32_t num_tri = 0;
|
||||
size_t file_size = BLI_file_size(import_params.filepath);
|
||||
fseek(file, BINARY_HEADER_SIZE, SEEK_SET);
|
||||
fread(&num_tri, sizeof(uint32_t), 1, file);
|
||||
if (fread(&num_tri, sizeof(uint32_t), 1, file) != 1) {
|
||||
stl_import_report_error(file);
|
||||
return;
|
||||
}
|
||||
bool is_ascii_stl = (file_size != (BINARY_HEADER_SIZE + 4 + BINARY_STRIDE * num_tri));
|
||||
|
||||
/* Name used for both mesh and object. */
|
||||
|
@ -64,7 +78,7 @@ void importer_main(Main *bmain,
|
|||
BLI_strncpy(ob_name, BLI_path_basename(import_params.filepath), FILE_MAX);
|
||||
BLI_path_extension_replace(ob_name, FILE_MAX, "");
|
||||
|
||||
Mesh *mesh;
|
||||
Mesh *mesh = nullptr;
|
||||
if (is_ascii_stl) {
|
||||
mesh = read_stl_ascii(import_params.filepath, bmain, ob_name, import_params.use_facet_normal);
|
||||
}
|
||||
|
@ -72,6 +86,11 @@ void importer_main(Main *bmain,
|
|||
mesh = read_stl_binary(file, bmain, ob_name, import_params.use_facet_normal);
|
||||
}
|
||||
|
||||
if (mesh == nullptr) {
|
||||
fprintf(stderr, "STL Importer: Failed to import mesh '%s'\n", import_params.filepath);
|
||||
return;
|
||||
}
|
||||
|
||||
if (import_params.use_mesh_validate) {
|
||||
bool verbose_validate = false;
|
||||
#ifdef DEBUG
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
namespace blender::io::stl {
|
||||
|
||||
void stl_import_report_error(FILE *file);
|
||||
|
||||
/* Main import function used from within Blender. */
|
||||
void importer_main(bContext *C, const STLImportParams &import_params);
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "DNA_mesh_types.h"
|
||||
|
||||
#include "stl_import.hh"
|
||||
#include "stl_import_binary_reader.hh"
|
||||
#include "stl_import_mesh.hh"
|
||||
|
||||
|
@ -33,7 +34,11 @@ Mesh *read_stl_binary(FILE *file, Main *bmain, char *mesh_name, bool use_custom_
|
|||
const int chunk_size = 1024;
|
||||
uint32_t num_tris = 0;
|
||||
fseek(file, BINARY_HEADER_SIZE, SEEK_SET);
|
||||
fread(&num_tris, sizeof(uint32_t), 1, file);
|
||||
if (fread(&num_tris, sizeof(uint32_t), 1, file) != 1) {
|
||||
stl_import_report_error(file);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (num_tris == 0) {
|
||||
return BKE_mesh_add(bmain, mesh_name);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue