Skip to content

Commit

Permalink
better error handling in osu_ui’s constructor
Browse files Browse the repository at this point in the history
osu_paint_resources is not quite good yet, but osu_ui does its job now.
Now that we have exceptions at our disposal, maybe more and more
functions will start being void and raise exceptions on error.
  • Loading branch information
fmang committed Apr 3, 2020
1 parent afbc15d commit 6421ad2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/ui/osu.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct osu_ui : public widget {
*
* Sliders are not painted. Instead, you must call #oshu::osu_paint_slider.
*/
int osu_paint_resources(oshu::osu_ui&);
void osu_paint_resources(oshu::osu_ui&);

/**
* Paint a slider.
Expand Down
8 changes: 2 additions & 6 deletions lib/ui/osu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,14 @@ static void connect_hits(oshu::osu_ui &view, oshu::hit *a, oshu::hit *b)

namespace oshu {

/**
* \todo
* Handle errors.
*/
osu_ui::osu_ui(oshu::display *display, oshu::osu_game &game)
: display(display), game(game)
{
assert (display != nullptr);
oshu::osu_view(display);
int rc = oshu::osu_paint_resources(*this);
oshu::osu_paint_resources(*this);
if (oshu::create_cursor(display, &cursor) < 0)
rc = -1;
throw std::runtime_error("could not create cursor");
oshu::reset_view(display);
mouse = std::make_shared<osu_mouse>(display);
game.mouse = mouse;
Expand Down
3 changes: 1 addition & 2 deletions lib/ui/osu_paint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ static int paint_connector(oshu::osu_ui &view)
* \todo
* Handle errors.
*/
int oshu::osu_paint_resources(oshu::osu_ui &view)
void oshu::osu_paint_resources(oshu::osu_ui &view)
{
oshu::game_base *game = &view.game;
int start = SDL_GetTicks();
Expand Down Expand Up @@ -365,7 +365,6 @@ int oshu::osu_paint_resources(oshu::osu_ui &view)

int end = SDL_GetTicks();
oshu_log_debug("done generating the common textures in %.3f seconds", (end - start) / 1000.);
return 0;
}

void oshu::osu_free_resources(oshu::osu_ui &view)
Expand Down

0 comments on commit 6421ad2

Please sign in to comment.