Fix crash when taking screenshots with widgets enabled

This commit is contained in:
jdgleaver 2020-06-08 12:41:22 +01:00
parent e7082d3e5b
commit 0c7f0df41a

View File

@ -74,6 +74,7 @@ static gfx_widget_screenshot_state_t* gfx_widget_screenshot_get_ptr(void)
static void gfx_widget_screenshot_fadeout(void *userdata)
{
dispgfx_widget_t *p_dispwidget = (dispgfx_widget_t*)userdata;
gfx_widget_screenshot_state_t* state = gfx_widget_screenshot_get_ptr();
gfx_animation_ctx_entry_t entry;
@ -81,7 +82,7 @@ static void gfx_widget_screenshot_fadeout(void *userdata)
entry.duration = SCREENSHOT_DURATION_OUT;
entry.easing_enum = EASING_OUT_QUAD;
entry.subject = &state->alpha;
entry.tag = gfx_widgets_get_generic_tag(userdata);
entry.tag = gfx_widgets_get_generic_tag(p_dispwidget);
entry.target_value = 0.0f;
entry.userdata = NULL;
@ -90,6 +91,7 @@ static void gfx_widget_screenshot_fadeout(void *userdata)
static void gfx_widgets_play_screenshot_flash(void *data)
{
dispgfx_widget_t *p_dispwidget = (dispgfx_widget_t*)data;
gfx_widget_screenshot_state_t* state = gfx_widget_screenshot_get_ptr();
gfx_animation_ctx_entry_t entry;
@ -97,9 +99,9 @@ static void gfx_widgets_play_screenshot_flash(void *data)
entry.duration = SCREENSHOT_DURATION_IN;
entry.easing_enum = EASING_IN_QUAD;
entry.subject = &state->alpha;
entry.tag = gfx_widgets_get_generic_tag(data);
entry.tag = gfx_widgets_get_generic_tag(p_dispwidget);
entry.target_value = 1.0f;
entry.userdata = data;
entry.userdata = p_dispwidget;
gfx_animation_push(&entry);
}
@ -108,8 +110,10 @@ void gfx_widget_screenshot_taken(
void *data,
const char *shotname, const char *filename)
{
dispgfx_widget_t *p_dispwidget = (dispgfx_widget_t*)data;
gfx_widget_screenshot_state_t* state = gfx_widget_screenshot_get_ptr();
gfx_widgets_play_screenshot_flash(data);
gfx_widgets_play_screenshot_flash(p_dispwidget);
strlcpy(state->filename, filename, sizeof(state->filename));
strlcpy(state->shotname, shotname, sizeof(state->shotname));
}
@ -117,6 +121,7 @@ void gfx_widget_screenshot_taken(
static void gfx_widget_screenshot_dispose(void *userdata)
{
gfx_widget_screenshot_state_t* state = gfx_widget_screenshot_get_ptr();
state->loaded = false;
video_driver_texture_unload(&state->texture);
state->texture = 0;
@ -125,13 +130,14 @@ static void gfx_widget_screenshot_dispose(void *userdata)
static void gfx_widget_screenshot_end(void *userdata)
{
gfx_animation_ctx_entry_t entry;
dispgfx_widget_t *p_dispwidget = (dispgfx_widget_t*)userdata;
gfx_widget_screenshot_state_t* state = gfx_widget_screenshot_get_ptr();
entry.cb = gfx_widget_screenshot_dispose;
entry.duration = MSG_QUEUE_ANIMATION_DURATION;
entry.easing_enum = EASING_OUT_QUAD;
entry.subject = &state->y;
entry.tag = gfx_widgets_get_generic_tag(userdata);
entry.tag = gfx_widgets_get_generic_tag(p_dispwidget);
entry.target_value = -((float)state->height);
entry.userdata = NULL;
@ -141,7 +147,8 @@ static void gfx_widget_screenshot_end(void *userdata)
static void gfx_widget_screenshot_free(void)
{
gfx_widget_screenshot_state_t* state = gfx_widget_screenshot_get_ptr();
state->alpha = 0.0f;
state->alpha = 0.0f;
gfx_widget_screenshot_dispose(NULL);
}
@ -151,9 +158,10 @@ static void gfx_widget_screenshot_frame(void* data, void *user_data)
void *userdata = video_info->userdata;
unsigned video_width = video_info->width;
unsigned video_height = video_info->height;
gfx_widget_font_data_t* font_regular = gfx_widgets_get_font_regular(user_data);
float* pure_white = gfx_widgets_get_pure_white();
dispgfx_widget_t *p_dispwidget = (dispgfx_widget_t*)user_data;
gfx_widget_screenshot_state_t* state = gfx_widget_screenshot_get_ptr();
gfx_widget_font_data_t* font_regular = gfx_widgets_get_font_regular(p_dispwidget);
float* pure_white = gfx_widgets_get_pure_white();
int padding = (state->height - (font_regular->line_height * 2.0f)) / 2.0f;
/* Screenshot */
@ -234,9 +242,10 @@ static void gfx_widget_screenshot_iterate(
const char *dir_assets, char *font_path,
bool is_threaded)
{
dispgfx_widget_t *p_dispwidget = (dispgfx_widget_t*)user_data;
gfx_widget_screenshot_state_t* state = gfx_widget_screenshot_get_ptr();
unsigned padding = gfx_widgets_get_padding(user_data);
gfx_widget_font_data_t* font_regular = gfx_widgets_get_font_regular(user_data);
unsigned padding = gfx_widgets_get_padding(p_dispwidget);
gfx_widget_font_data_t* font_regular = gfx_widgets_get_font_regular(p_dispwidget);
/* Load screenshot and start its animation */
if (state->filename[0] != '\0')
@ -268,7 +277,7 @@ static void gfx_widget_screenshot_iterate(
timer.cb = gfx_widget_screenshot_end;
timer.duration = SCREENSHOT_NOTIFICATION_DURATION;
timer.userdata = NULL;
timer.userdata = p_dispwidget;
gfx_timer_start(&state->timer, &timer);