From e9b7c7267e24c20f3c63c4c8856b25d7cf57b1c4 Mon Sep 17 00:00:00 2001 From: radius Date: Tue, 30 Jan 2018 22:38:03 -0500 Subject: [PATCH] fix some potential crashes when a shader is not set in config --- gfx/drivers/gl.c | 9 ++++++++- menu/menu_shader.c | 2 +- retroarch.c | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 202e43ab4c..a1d521ae01 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -380,9 +380,16 @@ static bool gl_shader_init(gl_t *gl, const gfx_ctx_driver_t *ctx_driver, video_shader_ctx_init_t init_data; settings_t *settings = config_get_ptr(); const char *shader_path = retroarch_get_shader_preset(); - enum rarch_shader_type type = video_shader_parse_type(shader_path, + enum rarch_shader_type type; + + if (shader_path) + { + type = video_shader_parse_type(shader_path, gl->core_context_in_use ? RARCH_SHADER_GLSL : DEFAULT_SHADER_TYPE); + } + else + type = DEFAULT_SHADER_TYPE; switch (type) { diff --git a/menu/menu_shader.c b/menu/menu_shader.c index 951163583e..96c6680484 100644 --- a/menu/menu_shader.c +++ b/menu/menu_shader.c @@ -138,7 +138,7 @@ bool menu_shader_manager_init(void) menu_driver_shader = (struct video_shader*) calloc(1, sizeof(struct video_shader)); - if (!menu_driver_shader) + if (!menu_driver_shader || !path_shader) return false; /* In a multi-config setting, we can't have diff --git a/retroarch.c b/retroarch.c index 00416fb6a6..2f680c17c6 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1945,14 +1945,14 @@ char* retroarch_get_shader_preset(void) { settings_t *settings = config_get_ptr(); if (!settings->bools.video_shader_enable) - return ""; + return NULL; if (!string_is_empty(runtime_shader_preset)) return runtime_shader_preset; else if (!string_is_empty(settings->paths.path_shader)) return settings->paths.path_shader; else - return ""; + return NULL; } bool retroarch_override_setting_is_set(enum rarch_override_setting enum_idx, void *data)