Added error handling in display update.
This commit is contained in:
parent
8f63135415
commit
519ae78ada
|
|
@ -99,9 +99,13 @@ inline int display_clear(void)
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
inline void display_update(void)
|
||||
inline int display_update(void)
|
||||
{
|
||||
SDL_RenderPresent(renderer);
|
||||
if(!SDL_RenderPresent(renderer))
|
||||
{
|
||||
error_printf("Failed to present renderer : %s", SDL_GetError());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
#if DEBUG >= 1
|
||||
float fps = 1000.0f / game.delta_time_ms;
|
||||
|
|
@ -118,8 +122,16 @@ inline void display_update(void)
|
|||
{
|
||||
fps_update_delta_time = 0.0f;
|
||||
char title[100];
|
||||
sprintf(title, "2D_Engine | cur: %.2ffps | max: %.2ffps | low: %.2ffps", fps, max_fps_10s, low_fps_10s);
|
||||
SDL_SetWindowTitle(window, title);
|
||||
if(sprintf(title, "2D_Engine | cur: %.2ffps | max: %.2ffps | low: %.2ffps", fps, max_fps_10s, low_fps_10s) == -1)
|
||||
{
|
||||
error_printf("Sprintf failed : %d", errno);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if(!SDL_SetWindowTitle(window, title))
|
||||
{
|
||||
error_printf("Failed to set window title : %s", SDL_GetError());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
static float fps_max_low_update_delta_time = 0.0f;
|
||||
|
|
@ -132,6 +144,8 @@ inline void display_update(void)
|
|||
low_fps_10s = 10000000.0f;
|
||||
}
|
||||
#endif // DEBUG >= 1
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int display_draw_texture(texture_t *texture, const rect_t *src_rect, const frect_t *dst_frect, bool flip)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ int display_init(void);
|
|||
void display_exit(void);
|
||||
|
||||
int display_clear(void);
|
||||
void display_update(void);
|
||||
int display_update(void);
|
||||
|
||||
int display_draw_texture(texture_t *texture, const rect_t *src_rect, const frect_t *dst_frect, bool flip);
|
||||
int display_draw_frect(const frect_t *frect, unsigned int r, unsigned int g, unsigned int b, unsigned int a);
|
||||
|
|
|
|||
Loading…
Reference in New Issue