From b7be825ba7b408ae4c70d12d041c192b6540f87b Mon Sep 17 00:00:00 2001 From: ts-korhonen Date: Sat, 17 Apr 2021 00:12:49 +0300 Subject: [PATCH] win_opengl: Fix MSVC build errors and warnings --- src/include/86box/win_opengl.h | 4 ++-- src/win/win_opengl.c | 22 ++++++++++++---------- src/win/win_opengl_glslp.c | 11 ++++++++++- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/include/86box/win_opengl.h b/src/include/86box/win_opengl.h index 9202c6aaf..8ac402ecc 100644 --- a/src/include/86box/win_opengl.h +++ b/src/include/86box/win_opengl.h @@ -19,8 +19,8 @@ #include extern int opengl_init(HWND hwnd); -extern int opengl_pause(); -extern void opengl_close(); +extern int opengl_pause(void); +extern void opengl_close(void); extern void opengl_set_fs(int fs); extern void opengl_resize(int w, int h); diff --git a/src/win/win_opengl.c b/src/win/win_opengl.c index c469d9397..86732e0eb 100644 --- a/src/win/win_opengl.c +++ b/src/win/win_opengl.c @@ -39,6 +39,9 @@ #include #include +#include +#include + #include <86box/86box.h> #include <86box/plat.h> #include <86box/video.h> @@ -51,8 +54,7 @@ static const int INIT_HEIGHT = 400; /* Option; Target framerate: Sync with emulation / 25 fps / 30 fps / 50 fps / 60 fps / 75 fps */ static const int SYNC_WITH_BLITTER = 1; -static const int TARGET_FRAMERATE = 75; -static const int TARGET_FRAMETIME = 1000 / TARGET_FRAMERATE; +static const int TARGET_FRAMETIME = 13; /* Option; Vsync: Off / On */ static const int VSYNC = 0; @@ -90,7 +92,7 @@ static union HANDLE blit_waiting; }; HANDLE asArray[3]; -} sync_objects = {}; +} sync_objects = { 0 }; /** * @brief Signal from OpenGL thread that it's done with video buffer. @@ -103,7 +105,7 @@ static HANDLE blit_done = NULL; static volatile struct { int x, y, y1, y2, w, h, resized; -} blit_info = {}; +} blit_info = { 0 }; /** * @brief Resize event parameters. @@ -111,7 +113,7 @@ static volatile struct static volatile struct { int width, height, fullscreen, scaling_mode; -} resize_info = {}; +} resize_info = { 0 }; /** * @brief Identifiers to OpenGL objects and uniforms. @@ -250,7 +252,7 @@ static gl_identifiers initialize_glcontext() 1.f, -1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f }; - gl_identifiers gl = {}; + gl_identifiers gl = { 0 }; glGenVertexArrays(1, &gl.vertexArrayID); @@ -361,7 +363,7 @@ static void render_and_swap(gl_identifiers gl) * OpenGL context should be accessed only from this single thread. * Events are used to synchronize communication. */ -static void opengl_main() +static void opengl_main(void* param) { SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1"); /* Is this actually doing anything...? */ @@ -372,7 +374,7 @@ static void opengl_main() /* Keep track of certain parameters, only changed in this thread to avoid race conditions */ int fullscreen = resize_info.fullscreen, video_width = INIT_WIDTH, video_height = INIT_HEIGHT; - SDL_SysWMinfo wmi; + SDL_SysWMinfo wmi = { 0 }; SDL_VERSION(&wmi.version); SDL_GetWindowWMInfo(window, &wmi); @@ -602,12 +604,12 @@ int opengl_init(HWND hwnd) return 1; } -int opengl_pause() +int opengl_pause(void) { return 0; } -void opengl_close() +void opengl_close(void) { if (thread == NULL) return; diff --git a/src/win/win_opengl_glslp.c b/src/win/win_opengl_glslp.c index adfaa9cc0..0b7e54c77 100644 --- a/src/win/win_opengl_glslp.c +++ b/src/win/win_opengl_glslp.c @@ -34,6 +34,7 @@ #include #include #include +#include #include <86box/86box.h> #include <86box/plat.h> @@ -80,13 +81,21 @@ static char* read_file_to_string(const char* path) { /* get file size */ fseek(file_handle, 0, SEEK_END); - long file_size = ftell(file_handle); + + size_t file_size = (size_t)ftell(file_handle); + fseek(file_handle, 0, SEEK_SET); /* read to buffer and close */ char* content = (char*)malloc(sizeof(char) * (file_size + 1)); + + if (!content) + return NULL; + size_t length = fread(content, sizeof(char), file_size, file_handle); + fclose(file_handle); + content[length] = 0; return content;