Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-van-bergen committed Jul 20, 2021
1 parent 606c4b1 commit b9fbadb
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions Src/Assets/BVHLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ bool BVHLoader::try_to_load(const char * filename, MeshData & mesh_data, BVH & b
int bvh_filename_size = strlen(filename) + strlen(BVH_FILE_EXTENSION) + 1;
char * bvh_filename = MALLOCA(char, bvh_filename_size);

if (!bvh_filename) return false;

strcpy_s(bvh_filename, bvh_filename_size, filename);
strcat_s(bvh_filename, bvh_filename_size, BVH_FILE_EXTENSION);

Expand All @@ -32,18 +34,16 @@ bool BVHLoader::try_to_load(const char * filename, MeshData & mesh_data, BVH & b
return false;
}

FILE * file;
fopen_s(&file, bvh_filename, "rb");
FILE * file; fopen_s(&file, bvh_filename, "rb");

BVHFileHeader header = { };

bool success = false;

if (!file) {
printf("WARNING: Unable to open BVH file '%s'!\n", bvh_filename);
goto exit;
}

fread(reinterpret_cast<char *>(&header), sizeof(header), 1, file);

if (strcmp(header.filetype_identifier, "BVH") != 0) {
Expand Down Expand Up @@ -81,28 +81,27 @@ bool BVHLoader::try_to_load(const char * filename, MeshData & mesh_data, BVH & b
success = true;

exit:
fclose(file);
if (file) fclose(file);

FREEA(bvh_filename);

return success;
}

bool BVHLoader::save(const char * filename, MeshData & mesh_data, BVH & bvh) {
int bvh_filename_length = strlen(filename) + strlen(BVH_FILE_EXTENSION) + 1;
char * bvh_filename = MALLOCA(char, bvh_filename_length);

if (!bvh_filename) return false;

strcpy_s(bvh_filename, bvh_filename_length, filename);
strcat_s(bvh_filename, bvh_filename_length, BVH_FILE_EXTENSION);

FILE * file;
fopen_s(&file, bvh_filename, "wb");
FILE * file; fopen_s(&file, bvh_filename, "wb");

if (file == nullptr) {
if (!file) {
printf("WARNING: Unable to save BVH to file %s!\n", bvh_filename);

FREEA(bvh_filename);

return false;
}

Expand Down Expand Up @@ -132,6 +131,5 @@ bool BVHLoader::save(const char * filename, MeshData & mesh_data, BVH & bvh) {
fclose(file);

FREEA(bvh_filename);

return true;
}

0 comments on commit b9fbadb

Please sign in to comment.