From daa97196b606daf355427a2b3de14f8e16fe209a Mon Sep 17 00:00:00 2001
From: Joseph Walton-Rivers <joseph@walton-rivers.uk>
Date: Sun, 20 Nov 2022 13:36:57 +0000
Subject: [PATCH] fix issues with assimp loader in release mode

---
 fggl/data/assimp/module.cpp         | 13 +++++++------
 include/fggl/data/assimp/module.hpp | 12 ++++++++++++
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/fggl/data/assimp/module.cpp b/fggl/data/assimp/module.cpp
index afa6b5f..b8d3707 100644
--- a/fggl/data/assimp/module.cpp
+++ b/fggl/data/assimp/module.cpp
@@ -139,7 +139,7 @@ namespace fggl::data::models {
 	}
 
 
-	static assets::AssetRefRaw load_assimp_model(assets::Loader* loader, const assets::AssetID& guid, const assets::LoaderContext& data, void* userPtr) {
+	assets::AssetRefRaw load_assimp_model(assets::Loader* loader, const assets::AssetID& guid, const assets::LoaderContext& data, void* userPtr) {
 //		auto *filePath = std::get<assets::AssetPath *>(data);
 		assets::AssetManager* manager = (assets::AssetManager*)userPtr;
 		auto filePath = data.assetPath;
@@ -191,7 +191,7 @@ namespace fggl::data::models {
 		return nullptr;
 	}
 
-	static assets::AssetRefRaw load_assimp_texture(assets::Loader* loader, const assets::AssetID& guid, const assets::LoaderContext& data, void* userPtr) {
+	assets::AssetRefRaw load_assimp_texture(assets::Loader* loader, const assets::AssetID& guid, const assets::LoaderContext& data, void* userPtr) {
 		assets::AssetManager* manager = (assets::AssetManager*)userPtr;
 
 		if ( manager->has(guid) ) {
@@ -217,7 +217,7 @@ namespace fggl::data::models {
 		return nullptr;
 	}
 
-	static bool load_tex_stb(std::filesystem::path filePath, assets::MemoryBlock& block) {
+	bool load_tex_stb(std::filesystem::path filePath, assets::MemoryBlock& block) {
 		stbi_set_flip_vertically_on_load(true);
 
 		//load the texture data into memory
@@ -238,7 +238,7 @@ namespace fggl::data::models {
 		}
 	}
 
-	static assets::AssetTypeID is_tex_stb(std::filesystem::path filePath) {
+	assets::AssetTypeID is_tex_stb(std::filesystem::path filePath) {
 		// detect jpgs
 		if ( filePath.extension() == ".jpg" || filePath.extension() == ".jpeg" ) {
 			return TEXTURE_RGBA;
@@ -252,7 +252,7 @@ namespace fggl::data::models {
 		return assets::INVALID_ASSET_TYPE;
 	}
 
-	static assets::AssetTypeID is_model_assimp(std::filesystem::path filePath) {
+	assets::AssetTypeID is_model_assimp(std::filesystem::path filePath) {
 		if ( filePath.extension() == ".obj" ){
 			return MODEL_MULTI3D;
 		}
@@ -260,7 +260,7 @@ namespace fggl::data::models {
 		return assets::INVALID_ASSET_TYPE;
 	}
 
-	static bool extract_requirements(const std::string& packName, std::filesystem::path packRoot, assets::ResourceRecord& rr) {
+	bool extract_requirements(const std::string& packName, std::filesystem::path packRoot, assets::ResourceRecord& rr) {
 		Assimp::Importer importer;
 		const aiScene *scene = importer.ReadFile( rr.m_path, aiProcess_Triangulate | aiProcess_FlipUVs);
 		if ( !scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode ) {
@@ -304,6 +304,7 @@ namespace fggl::data::models {
 
 			checkin->setLoader( MIME_OBJ, assets::NEEDS_CHECKIN, is_model_assimp );
 			checkin->setProcessor( MIME_OBJ, extract_requirements);
+			return false;
 		}
 	}
 
diff --git a/include/fggl/data/assimp/module.hpp b/include/fggl/data/assimp/module.hpp
index d5c40db..3a7f71f 100644
--- a/include/fggl/data/assimp/module.hpp
+++ b/include/fggl/data/assimp/module.hpp
@@ -36,6 +36,18 @@ namespace fggl::data::models {
 	constexpr auto MODEL_MULTI3D = assets::make_asset_type("model/multi3D");
 	constexpr auto TEXTURE_RGBA = assets::make_asset_type("texture/rgba");
 
+	// old-style loaders
+	assets::AssetRefRaw load_assimp_model(assets::Loader* loader, const assets::AssetID& guid, const assets::LoaderContext& data, void* userPtr);
+	assets::AssetRefRaw load_assimp_texture(assets::Loader* loader, const assets::AssetID& guid, const assets::LoaderContext& data, void* userPtr);
+
+	// new style loaders (textures)
+	bool load_tex_stb(std::filesystem::path filePath, assets::MemoryBlock& block);
+	static assets::AssetTypeID is_tex_stb(std::filesystem::path filePath);
+
+	// new style loaders (models)
+	assets::AssetTypeID is_model_assimp(std::filesystem::path filePath);
+	bool extract_requirements(const std::string& packName, std::filesystem::path packRoot, assets::ResourceRecord& rr);
+
 	struct AssimpModule {
 		constexpr static const char *name = "fggl::data::Assimp";
 		constexpr static const std::array<modules::ModuleService, 1> provides = {
-- 
GitLab