Add a mechanism to report errors on event handling
This paves the way to workaround HiDPI issues, which may recreate the renderer and texture (which may fail) on window event.
This commit is contained in:
parent
04a31ef7b9
commit
f3b7712ea2
@ -128,6 +128,7 @@ enum event_result {
|
||||
EVENT_RESULT_CONTINUE,
|
||||
EVENT_RESULT_STOPPED_BY_USER,
|
||||
EVENT_RESULT_STOPPED_BY_EOS,
|
||||
EVENT_RESULT_STOPPED_BY_ERROR,
|
||||
};
|
||||
|
||||
static enum event_result
|
||||
@ -150,7 +151,9 @@ handle_event(SDL_Event *event, bool control) {
|
||||
}
|
||||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
screen_handle_window_event(&screen, &event->window);
|
||||
if (!screen_handle_window_event(&screen, &event->window)) {
|
||||
return EVENT_RESULT_STOPPED_BY_ERROR;
|
||||
}
|
||||
break;
|
||||
case SDL_TEXTINPUT:
|
||||
if (!control) {
|
||||
@ -222,6 +225,9 @@ event_loop(bool display, bool control) {
|
||||
case EVENT_RESULT_STOPPED_BY_EOS:
|
||||
LOGW("Device disconnected");
|
||||
return false;
|
||||
case EVENT_RESULT_STOPPED_BY_ERROR:
|
||||
LOGC("Stopping due to unrecoverable error");
|
||||
return false;
|
||||
case EVENT_RESULT_CONTINUE:
|
||||
break;
|
||||
}
|
||||
|
@ -518,7 +518,7 @@ screen_resize_to_pixel_perfect(struct screen *screen) {
|
||||
content_size.height);
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
screen_handle_window_event(struct screen *screen,
|
||||
const SDL_WindowEvent *event) {
|
||||
switch (event->event) {
|
||||
@ -558,6 +558,8 @@ screen_handle_window_event(struct screen *screen,
|
||||
apply_windowed_size(screen);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
struct point
|
||||
|
@ -111,7 +111,8 @@ void
|
||||
screen_set_rotation(struct screen *screen, unsigned rotation);
|
||||
|
||||
// react to window events
|
||||
void
|
||||
// return true on success, false on unrecoverable error
|
||||
bool
|
||||
screen_handle_window_event(struct screen *screen, const SDL_WindowEvent *event);
|
||||
|
||||
// convert point from window coordinates to frame coordinates
|
||||
|
Loading…
x
Reference in New Issue
Block a user