From 615c297b3b4b8db3c70c2873fd0083bfb767bad9 Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 16 May 2020 16:03:55 +0200 Subject: [PATCH] Added Exceptions to RenderWindow --- SDLU/CMakeLists.txt | 1 - SDLU/exceptions/CMakeLists.txt | 4 ---- SDLU/exceptions/Exceptions.hpp | 4 ++-- SDLU/graphics/RenderWindow.cpp | 15 +++++---------- SDLU_Example/main.cpp | 3 +++ 5 files changed, 10 insertions(+), 17 deletions(-) delete mode 100644 SDLU/exceptions/CMakeLists.txt diff --git a/SDLU/CMakeLists.txt b/SDLU/CMakeLists.txt index addb5bf..ad6bc11 100644 --- a/SDLU/CMakeLists.txt +++ b/SDLU/CMakeLists.txt @@ -13,6 +13,5 @@ target_link_libraries(${PNAME} PRIVATE ${CMAKE_BINARY_DIR}/3rdparty/SDL/SDL2d.lib ) -add_subdirectory(exceptions) add_subdirectory(structures) add_subdirectory(graphics) \ No newline at end of file diff --git a/SDLU/exceptions/CMakeLists.txt b/SDLU/exceptions/CMakeLists.txt deleted file mode 100644 index 4e439d5..0000000 --- a/SDLU/exceptions/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -target_sources(${PNAME} PRIVATE - ${CMAKE_CURRENT_SORUCE_DIR}/Exceptions.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ObjectCreationException.hpp -) \ No newline at end of file diff --git a/SDLU/exceptions/Exceptions.hpp b/SDLU/exceptions/Exceptions.hpp index 6add7a9..46faf94 100644 --- a/SDLU/exceptions/Exceptions.hpp +++ b/SDLU/exceptions/Exceptions.hpp @@ -8,5 +8,5 @@ #include "ObjectCreationException.hpp" -#define THROW_IF_NOT( condition, exception ) ( condition ? throw execption : false ) -#define THROW_IF( condition, exception ) ( condition ? false : throw execption ) \ No newline at end of file +#define THROW_IF_NOT( condition, exception ) ( condition ? throw exception : false ) +#define THROW_IF( condition, exception ) ( condition ? false : throw exception ) \ No newline at end of file diff --git a/SDLU/graphics/RenderWindow.cpp b/SDLU/graphics/RenderWindow.cpp index 9643077..8a13654 100644 --- a/SDLU/graphics/RenderWindow.cpp +++ b/SDLU/graphics/RenderWindow.cpp @@ -1,4 +1,5 @@ #include "RenderWindow.hpp" +#include "../exceptions/Exceptions.hpp" #define IS_NULLPTR( x ) (x == nullptr) @@ -28,17 +29,11 @@ namespace sdlu SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, dimension.x, dimension.y, windowFlags); - if (IS_NULLPTR(m_pWindow)) - { - // TODO: Implement exception - return - } + THROW_IF(IS_NULLPTR(m_pWindow), + ObjectCreationException("Failed to create SDL_Window.")); m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, rendererFlags); - if (IS_NULLPTR(m_pRenderer)) - { - // TODO: Implement exception - return - } + THROW_IF(IS_NULLPTR(m_pRenderer), + ObjectCreationException("Failed to create SDL_Renderer.")); } } \ No newline at end of file diff --git a/SDLU_Example/main.cpp b/SDLU_Example/main.cpp index e947d4b..33480e4 100644 --- a/SDLU_Example/main.cpp +++ b/SDLU_Example/main.cpp @@ -12,5 +12,8 @@ int main(int argc, char** argv) vec *= 1.8f; std::cout << "Vector2f: " << vec.x << ", " << vec.y << std::endl; + + sdlu::RenderWindow window; + window.Create(sdlu::Vec2u(800, 800), "First test window", NULL, NULL); return 0; } \ No newline at end of file