From 9afe7868abe83f6982cc76b7acdbfb538547b798 Mon Sep 17 00:00:00 2001
From: Joseph Walton-Rivers <joseph@walton-rivers.uk>
Date: Wed, 12 Jul 2023 19:36:06 +0100
Subject: [PATCH] deal with crash when unknown types are encounted

---
 include/fggl/ds/graph.hpp                     | 19 +++++++++----------
 .../lua/include/fggl/script/lua/module.hpp    |  1 +
 integrations/lua/src/module.cpp               |  9 +++++----
 3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/include/fggl/ds/graph.hpp b/include/fggl/ds/graph.hpp
index 4433730..eefd9a0 100644
--- a/include/fggl/ds/graph.hpp
+++ b/include/fggl/ds/graph.hpp
@@ -142,20 +142,19 @@ namespace fggl::ds {
 
 				auto myDeps = m_edges.at(idx);
 				for (auto& dep : myDeps) {
-
-					if ( m_edges.find(dep) == m_edges.end() ) {
-						debug::warning("dependency was in graph, but does not exist as vertex: {}", dep.get());
-						continue;
-					}
-
-					assert( m_edges.contains(dep) );
-					// ensure dependency loops don't cause errors
 					if ( visited.contains(dep) ) {
-						debug::warning("Dependency loop detected, aborting");
 						continue;
 					}
 
-					sortUtilRev(dep, visited, stack);
+					// if this node exists in the graph, fetch its dependencies to
+					if ( m_edges.contains(dep) ) {
+						sortUtilRev(dep, visited, stack);
+					} else {
+						// !? we don't know about this asset but someone wants it, stick it in the queue
+						// this will probably cause an error when chain loading, but then it will let people
+						// know it's missing.
+						stack.push(dep);
+					}
 				}
 
 				stack.push(idx);
diff --git a/integrations/lua/include/fggl/script/lua/module.hpp b/integrations/lua/include/fggl/script/lua/module.hpp
index 0137152..22593f5 100644
--- a/integrations/lua/include/fggl/script/lua/module.hpp
+++ b/integrations/lua/include/fggl/script/lua/module.hpp
@@ -37,6 +37,7 @@ namespace fggl::script::lua {
 	struct Lua : public services::Module {
 		FGGL_MODULE(fggl::script::Lua, fggl::filesystem::API)
 
+		void setup(services::Generator*) override;
 		void wireServices(services::ModuleBinder& binder) override;
 	};
 
diff --git a/integrations/lua/src/module.cpp b/integrations/lua/src/module.cpp
index dd1ba35..d649599 100644
--- a/integrations/lua/src/module.cpp
+++ b/integrations/lua/src/module.cpp
@@ -28,12 +28,13 @@ namespace fggl::script::lua {
 		return assets::INVALID_ASSET_TYPE;
 	}
 
+	void Lua::setup(fggl::services::Generator *generator) {
+		auto adapted = generator->getLazy<assets::CheckinAdapted>();
+		adapted->setLoader(MIME_LUA, assets::NEEDS_CHECKIN, is_lua);
+	}
+
 	void Lua::wireServices(services::ModuleBinder &binder) {
 		binder.bind<ScriptProvider>().to<LuaScriptProvider, fggl::filesystem::Locator>();
-
-		//TODO
-		//auto *assetPacker = serviceManager.get<assets::CheckinAdapted>();
-		//assetPacker->setLoader(MIME_LUA, assets::NEEDS_CHECKIN, is_lua);
 	}
 
 }
\ No newline at end of file
-- 
GitLab