diff --git a/include/Nazara/Core/ApplicationBase.hpp b/include/Nazara/Core/ApplicationBase.hpp index 90dcf4943..930bd8461 100644 --- a/include/Nazara/Core/ApplicationBase.hpp +++ b/include/Nazara/Core/ApplicationBase.hpp @@ -36,8 +36,8 @@ namespace Nz inline void ClearComponents(); - template T* GetComponent(); - template const T* GetComponent() const; + template T& GetComponent(); + template const T& GetComponent() const; int Run(); diff --git a/include/Nazara/Core/ApplicationBase.inl b/include/Nazara/Core/ApplicationBase.inl index d47b3d75f..6128977c8 100644 --- a/include/Nazara/Core/ApplicationBase.inl +++ b/include/Nazara/Core/ApplicationBase.inl @@ -51,23 +51,23 @@ namespace Nz } template - T* ApplicationBase::GetComponent() + T& ApplicationBase::GetComponent() { std::size_t componentIndex = ApplicationComponentRegistry::GetComponentId(); - if (componentIndex >= m_components.size()) - return nullptr; + if (componentIndex >= m_components.size() || !m_components[componentIndex]) + throw std::runtime_error("component not found"); - return static_cast(m_components[componentIndex].get()); + return static_cast(*m_components[componentIndex]); } template - const T* ApplicationBase::GetComponent() const + const T& ApplicationBase::GetComponent() const { std::size_t componentIndex = ApplicationComponentRegistry::GetComponentId(); - if (componentIndex >= m_components.size()) - return nullptr; + if (componentIndex >= m_components.size() || !m_components[componentIndex]) + throw std::runtime_error("component not found"); - return static_cast(m_components[componentIndex].get()); + return static_cast(*m_components[componentIndex]); } inline void ApplicationBase::Quit()