Get window construction a bit more solid
This commit is contained in:
parent
36eb4bccbc
commit
32d7f4ba5f
2 changed files with 13 additions and 6 deletions
|
|
@ -342,8 +342,10 @@ Window::Window(const std::shared_ptr<input::Manager> &input_manager,
|
|||
width,
|
||||
height,
|
||||
SDL_WINDOW_OPENGL | SDL_WINDOW_MAXIMIZED);
|
||||
if (!window_)
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error("Failed to create new window"));
|
||||
if (!window_) {
|
||||
const auto message = utils::string_format("Failed to create window: %s", SDL_GetError());
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(message));
|
||||
}
|
||||
|
||||
|
||||
SDL_SysWMinfo info;
|
||||
|
|
|
|||
|
|
@ -68,21 +68,26 @@ void WindowCreator::process_events() {
|
|||
}
|
||||
}
|
||||
|
||||
EGLNativeWindowType WindowCreator::create_window(int x, int y, int width, int height) {
|
||||
DEBUG("x %i y %i width %i height %i", x, y, width, height);
|
||||
|
||||
EGLNativeWindowType WindowCreator::create_window(int x, int y, int width, int height)
|
||||
try {
|
||||
if (windows_.size() == 1) {
|
||||
WARNING("Tried to create another window but we currently only allow one");
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto window = std::make_shared<Window>(input_manager_, width, height);
|
||||
windows_.insert({window->native_window(), window});
|
||||
if (not window)
|
||||
BOOST_THROW_EXCEPTION(std::bad_alloc());
|
||||
|
||||
windows_.insert({window->native_window(), window});
|
||||
current_window_ = window;
|
||||
|
||||
return window->native_window();
|
||||
}
|
||||
catch (std::exception &err) {
|
||||
DEBUG("Failed to create window: %s", err.what());
|
||||
return 0;
|
||||
}
|
||||
|
||||
void WindowCreator::destroy_window(EGLNativeWindowType win) {
|
||||
auto iter = windows_.find(win);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue