diff --git a/src/mesh.cpp b/src/mesh.cpp index 0d114b1..ed22eb4 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -129,7 +129,6 @@ copyMeshInfo(const char* data_dir, const aiScene* scene, aiMesh* mesh) std::string file_path; file_path.append(data_dir).append("/").append(file_name.C_Str()); LOG(INFO) << "Loading texture file: " << file_name.C_Str() << "\n"; - mi->diffuse_texture_path = file_path.c_str(); mi->diffuse_texture = utilLoadImage(file_path.c_str()); } } @@ -140,10 +139,8 @@ copyMeshInfo(const char* data_dir, const aiScene* scene, aiMesh* mesh) void freeMesh(meMeshInfo* mesh) { - if (mesh->diffuse_texture.pixels != 0) { + if (mesh->diffuse_texture.pixels != 0) utilFreeImage(mesh->diffuse_texture); - mesh->diffuse_texture_path = 0; - } utilSafeFree(mesh->vertices); utilSafeFree(mesh->normals); diff --git a/src/mesh.h b/src/mesh.h index ef8ba99..fca6e14 100644 --- a/src/mesh.h +++ b/src/mesh.h @@ -19,7 +19,6 @@ struct meMeshInfo uint* indices = nullptr; glm::vec3 diffuse_color; - const char* diffuse_texture_path; util_image diffuse_texture; }; diff --git a/src/util.cpp b/src/util.cpp index 8b64892..2785280 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" @@ -66,8 +67,10 @@ util_image utilLoadImage(const char* filename) { LOG(INFO) << "Loading Image: " << filename << "\n"; + assert(std::strlen(filename) < 256); util_image image; + std::memcpy(image.file_path, filename, std::strlen(filename) + 1); image.pixels = stbi_load(filename, &image.w, &image.h, &image.num_channels, 0); image.data_len = image.w * image.h * image.num_channels; // NOTE: assumes 8 bits per channel @@ -89,5 +92,6 @@ utilFreeImage(util_image image) image.w = image.h = image.data_len = 0; image.bits_per_channel = 8; image.num_channels = 4; + std::memset(image.file_path, 0, std::strlen(image.file_path) + 1); utilSafeFree(image.pixels); } diff --git a/src/util.h b/src/util.h index 7fc03ca..eadd418 100644 --- a/src/util.h +++ b/src/util.h @@ -57,6 +57,7 @@ struct util_image int32 num_channels = 4; uint data_len = 0; uint8* pixels = nullptr; + char file_path[256]; }; inline real32