From 9b916e9256217360c833b929ec5cfd3a81153c2f Mon Sep 17 00:00:00 2001
From: Joseph Walton-Rivers <joseph@walton-rivers.uk>
Date: Thu, 23 Jun 2022 21:32:55 +0100
Subject: [PATCH] ensure game scenes without cameras do not crash

---
 fggl/gfx/ogl/renderer.cpp | 6 +++++-
 fggl/scenes/game.cpp      | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/fggl/gfx/ogl/renderer.cpp b/fggl/gfx/ogl/renderer.cpp
index d267708..602cb37 100644
--- a/fggl/gfx/ogl/renderer.cpp
+++ b/fggl/gfx/ogl/renderer.cpp
@@ -207,7 +207,11 @@ namespace fggl::gfx {
 
 		if ( m_debugRenderer ) {
 			auto cameras = world.findMatching<gfx::Camera>();
-			auto cameraEnt = cameras[0];
+			if ( cameras.empty() ) {
+				return;
+			}
+
+			auto cameraEnt = cameras.front();
 
 			auto* const camTransform = world.get<math::Transform>(cameraEnt);
 			auto* const camComp = world.get<gfx::Camera>(cameraEnt);
diff --git a/fggl/scenes/game.cpp b/fggl/scenes/game.cpp
index 10574ef..607ef4e 100644
--- a/fggl/scenes/game.cpp
+++ b/fggl/scenes/game.cpp
@@ -43,6 +43,8 @@ namespace fggl::scenes {
 	}
 
 	void Game::update() {
+		assert( m_world );
+
 		if ( m_input != nullptr ) {
 			bool escapePressed = m_input->keyboard.pressed(glfwGetKeyScancode(GLFW_KEY_ESCAPE));
 			if (escapePressed) {
-- 
GitLab