Removed throw statments
This commit is contained in:
parent
171c582225
commit
c9408a6107
|
@ -1,6 +1,7 @@
|
||||||
#include "Window.hpp"
|
#include "Window.hpp"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <iostream>
|
||||||
#include "util/util.hpp"
|
#include "util/util.hpp"
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
|
@ -9,6 +10,8 @@ namespace sf
|
||||||
void IWindow::Create(Vector2u size, Vector2i position, std::string title,
|
void IWindow::Create(Vector2u size, Vector2i position, std::string title,
|
||||||
Uint32 windowFlags /*= SDL_WINDOW_RESIZABLE*/, Uint32 renderFlags /*= SDL_RENDERER_SOFTWARE*/)
|
Uint32 windowFlags /*= SDL_WINDOW_RESIZABLE*/, Uint32 renderFlags /*= SDL_RENDERER_SOFTWARE*/)
|
||||||
{
|
{
|
||||||
|
m_pCurrentException = "";
|
||||||
|
|
||||||
// Check if SDL was initialized
|
// Check if SDL was initialized
|
||||||
Uint32 mask = SDL_WasInit(0);
|
Uint32 mask = SDL_WasInit(0);
|
||||||
if ((mask & SDLF_REQUIRED_SUBSYSTEMS) != SDLF_REQUIRED_SUBSYSTEMS)
|
if ((mask & SDLF_REQUIRED_SUBSYSTEMS) != SDLF_REQUIRED_SUBSYSTEMS)
|
||||||
|
@ -17,21 +20,30 @@ namespace sf
|
||||||
errorStream << "One or more required subsystems were not initialized. (Expected " <<
|
errorStream << "One or more required subsystems were not initialized. (Expected " <<
|
||||||
SDLF_REQUIRED_SUBSYSTEMS << " but got " << mask << " instead). \n" <<
|
SDLF_REQUIRED_SUBSYSTEMS << " but got " << mask << " instead). \n" <<
|
||||||
"Make sure to call SDL_Init(" << SDLF_REQUIRED_SUBSYSTEMS << ") before instantiating sf::IWindow.";
|
"Make sure to call SDL_Init(" << SDLF_REQUIRED_SUBSYSTEMS << ") before instantiating sf::IWindow.";
|
||||||
throw errorStream.str();
|
m_pCurrentException = const_cast<char*>(errorStream.str().c_str());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create SDL_Window
|
// Create SDL_Window
|
||||||
if (m_pWindow == nullptr)
|
if (m_pWindow == nullptr)
|
||||||
{
|
{
|
||||||
m_pWindow = SDL_CreateWindow(title.c_str(), position.x, position.y, size.x, size.y, windowFlags);
|
m_pWindow = SDL_CreateWindow(title.c_str(), position.x, position.y, size.x, size.y, windowFlags);
|
||||||
THROW_IF_NULLPTR(m_pWindow);
|
if (IS_NULLPTR(m_pWindow))
|
||||||
|
{
|
||||||
|
m_pCurrentException = const_cast<char*>(SDL_GetError());
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create SDL_Renderer
|
// Create SDL_Renderer
|
||||||
if (m_pRenderer == nullptr)
|
if (m_pRenderer == nullptr)
|
||||||
{
|
{
|
||||||
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, renderFlags);
|
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, renderFlags);
|
||||||
THROW_IF_NULLPTR(m_pRenderer);
|
if (IS_NULLPTR(m_pRenderer))
|
||||||
|
{
|
||||||
|
m_pCurrentException = const_cast<char*>(SDL_GetError());
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_oEventFunction = std::bind(&IWindow::OnEvent, this, std::placeholders::_1);
|
m_oEventFunction = std::bind(&IWindow::OnEvent, this, std::placeholders::_1);
|
||||||
|
@ -103,7 +115,7 @@ namespace sf
|
||||||
Uint32 windowFlags /*= SDL_WINDOW_RESIZABLE*/, Uint32 renderFlags /*= SDL_RENDERER_SOFTWARE*/) :
|
Uint32 windowFlags /*= SDL_WINDOW_RESIZABLE*/, Uint32 renderFlags /*= SDL_RENDERER_SOFTWARE*/) :
|
||||||
m_pWindow(nullptr), m_pRenderer(nullptr), m_oEvent(),
|
m_pWindow(nullptr), m_pRenderer(nullptr), m_oEvent(),
|
||||||
m_oSize(size), m_oPosition(position), m_strTitle(title), m_uWindowFlags(windowFlags),
|
m_oSize(size), m_oPosition(position), m_strTitle(title), m_uWindowFlags(windowFlags),
|
||||||
m_uRenderFlags(renderFlags), m_pCurrentScreen(nullptr)
|
m_uRenderFlags(renderFlags), m_pCurrentScreen(nullptr), m_pCurrentException("")
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -111,6 +123,11 @@ namespace sf
|
||||||
void IWindow::MessageLoop()
|
void IWindow::MessageLoop()
|
||||||
{
|
{
|
||||||
Create(m_oSize, m_oPosition, m_strTitle, m_uWindowFlags, m_uRenderFlags);
|
Create(m_oSize, m_oPosition, m_strTitle, m_uWindowFlags, m_uRenderFlags);
|
||||||
|
if (strcmp(m_pCurrentException, ""))
|
||||||
|
{
|
||||||
|
std::cerr << "ERROR: " << m_pCurrentException << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Test if the user instance's creation succeeded
|
// Test if the user instance's creation succeeded
|
||||||
if (!OnCreate())
|
if (!OnCreate())
|
||||||
|
|
|
@ -30,6 +30,8 @@ namespace sf
|
||||||
|
|
||||||
void SwitchScreen(IScreen* screen);
|
void SwitchScreen(IScreen* screen);
|
||||||
|
|
||||||
|
const char* GetCurrentException() const { return m_pCurrentException; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
IWindow(Vector2u size, Vector2i position, std::string title,
|
IWindow(Vector2u size, Vector2i position, std::string title,
|
||||||
Uint32 flags = SDL_WINDOW_RESIZABLE, Uint32 rendererFlags = SDL_RENDERER_SOFTWARE);
|
Uint32 flags = SDL_WINDOW_RESIZABLE, Uint32 rendererFlags = SDL_RENDERER_SOFTWARE);
|
||||||
|
@ -46,6 +48,8 @@ namespace sf
|
||||||
SDL_Event m_oEvent;
|
SDL_Event m_oEvent;
|
||||||
std::atomic_bool m_atomWindowOpen;
|
std::atomic_bool m_atomWindowOpen;
|
||||||
|
|
||||||
|
char* m_pCurrentException;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void MessageLoop();
|
void MessageLoop();
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
Loading…
Reference in a new issue