From 6d09d29093a50fac97b4dd92401d14dc9f6bfdaa Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 18 Feb 2020 04:18:31 +0100 Subject: [PATCH] Be more safe with these functions - this was causing crashes on MSVC 2005 --- gfx/drivers/gl.c | 21 +++++++++++++++++---- gfx/drivers/gl_core.c | 2 +- menu/drivers/xmb.c | 21 +++++++++++---------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 92043e25c1..9f52ef6a50 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -4401,14 +4401,27 @@ static void gl2_get_video_output_next(void *data) static void video_texture_load_gl2( struct texture_image *ti, enum texture_filter_type filter_type, - uintptr_t *id) + uintptr_t *idptr) { + GLuint id; + unsigned width = 0; + unsigned height = 0; + const void *pixels = NULL; /* Generate the OpenGL texture object */ - glGenTextures(1, (GLuint*)id); - gl_load_texture_data((GLuint)*id, + glGenTextures(1, &id); + *idptr = id; + + if (ti) + { + width = ti->width; + height = ti->height; + pixels = ti->pixels; + } + + gl_load_texture_data(id, RARCH_WRAP_EDGE, filter_type, 4 /* TODO/FIXME - dehardcode */, - ti->width, ti->height, ti->pixels, + width, height, pixels, sizeof(uint32_t) /* TODO/FIXME - dehardcode */ ); } diff --git a/gfx/drivers/gl_core.c b/gfx/drivers/gl_core.c index f45c5ccd9f..97d975d445 100644 --- a/gfx/drivers/gl_core.c +++ b/gfx/drivers/gl_core.c @@ -2058,7 +2058,7 @@ static int video_texture_load_wrap_gl_core(void *data) #endif static uintptr_t gl_core_load_texture(void *video_data, void *data, - bool threaded, enum texture_filter_type filter_type) + bool threaded, enum texture_filter_type filter_type) { uintptr_t id = 0; diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 84ae3b2c55..9bd170614a 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -5601,33 +5601,34 @@ error: static void xmb_context_reset_background(const char *iconpath) { - char *path = NULL; settings_t *settings = config_get_ptr(); const char *path_menu_wp = settings->paths.path_menu_wallpaper; if (!string_is_empty(path_menu_wp)) - path = strdup(path_menu_wp); + { + if (path_is_valid(path_menu_wp)) + task_push_image_load(path_menu_wp, + video_driver_supports_rgba(), 0, + menu_display_handle_wallpaper_upload, NULL); + } else if (!string_is_empty(iconpath)) { - path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); + char path[PATH_MAX_LENGTH]; path[0] = '\0'; fill_pathname_join(path, iconpath, "bg.png", PATH_MAX_LENGTH * sizeof(char)); + if (path_is_valid(path)) + task_push_image_load(path, + video_driver_supports_rgba(), 0, + menu_display_handle_wallpaper_upload, NULL); } - if (path_is_valid(path)) - task_push_image_load(path, - video_driver_supports_rgba(), 0, - menu_display_handle_wallpaper_upload, NULL); - #ifdef ORBIS /* To avoid weird behaviour on orbis with remote host */ RARCH_LOG("[XMB] after task\n"); sleep(5); #endif - if (path) - free(path); } static void xmb_context_reset_internal(xmb_handle_t *xmb,