diff options
author | John Stebbins <[email protected]> | 2017-02-10 10:53:11 -0700 |
---|---|---|
committer | John Stebbins <[email protected]> | 2017-02-10 10:56:27 -0700 |
commit | e232f46b7dd9614e73c92765dbd506cb0c3f9936 (patch) | |
tree | 1eadc0f06a1e3f2f7f523b96d94298faef6c8db5 /gtk/src | |
parent | 2b9eec937c8646ed002a675cc098e355c2d5b2ec (diff) |
LinGui: fix crash when changing video encoders
Attempt to access invalid encoder preset index accesses invalid memory
Diffstat (limited to 'gtk/src')
-rw-r--r-- | gtk/src/videohandler.c | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/gtk/src/videohandler.c b/gtk/src/videohandler.c index e93c34c88..13cbc0e7a 100644 --- a/gtk/src/videohandler.c +++ b/gtk/src/videohandler.c @@ -40,10 +40,10 @@ int ghb_get_video_encoder(GhbValue *settings) return hb_video_encoder_get_from_name(encoder); } -void ghb_set_video_preset(GhbValue *settings, int encoder, const char * preset) +int ghb_set_video_preset(GhbValue *settings, int encoder, const char * preset) { const char * const * videoPresets; - int ii; + int ii, result = 0; videoPresets = hb_video_encoder_get_presets(encoder); for (ii = 0; preset && videoPresets && videoPresets[ii]; ii++) @@ -51,6 +51,7 @@ void ghb_set_video_preset(GhbValue *settings, int encoder, const char * preset) if (!strcasecmp(preset, videoPresets[ii])) { ghb_dict_set_int(settings, "VideoPresetSlider", ii); + result = 1; break; } } @@ -58,6 +59,7 @@ void ghb_set_video_preset(GhbValue *settings, int encoder, const char * preset) { ghb_dict_set_string(settings, "VideoPreset", preset); } + return result; } G_MODULE_EXPORT void @@ -125,14 +127,33 @@ ghb_video_setting_changed(GtkWidget *widget, signal_user_data_t *ud) ghb_widget_to_setting(ud->settings, widget); int encoder = ghb_get_video_encoder(ud->settings); - int presetIndex = ghb_dict_get_int(ud->settings, "VideoPresetSlider"); - const char * const *video_presets; - const char *preset; + const char * const * video_presets; + video_presets = hb_video_encoder_get_presets(encoder); if (video_presets != NULL) { - preset = video_presets[presetIndex]; - ghb_dict_set_string(ud->settings, "VideoPreset", preset); + const char *preset; + + // Try to set same preset value + preset = ghb_dict_get_string(ud->settings, "VideoPreset"); + if (!ghb_set_video_preset(ud->settings, encoder, preset)) + { + int presetIndex, count = 0; + + // Try to set same preset index + presetIndex = ghb_dict_get_int(ud->settings, "VideoPresetSlider"); + while (video_presets[count]) count++; + if (presetIndex < count) + { + preset = video_presets[presetIndex]; + ghb_dict_set_string(ud->settings, "VideoPreset", preset); + } + else + { + // Try to set same preset "medium" preset + ghb_set_video_preset(ud->settings, encoder, "medium"); + } + } } if (!ghb_dict_get_bool(ud->settings, "x264UseAdvancedOptions") && |