From dcd4bcf1b28cbce4156351590a69dfb8f423a06b Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Sun, 12 Apr 2020 00:42:24 +0200 Subject: [PATCH] Backends: Fix some of the error handling and replaced some printf calls Signed-off-by: Gabriel Ravier --- src/Backends/Audio/SDL2.cpp | 8 ++++---- src/Backends/GLFW3/Misc.cpp | 2 +- src/Backends/Rendering/OpenGL3.cpp | 2 +- src/Backends/Rendering/SDLSurface.cpp | 4 ++-- src/Backends/Rendering/SDLTexture.cpp | 28 +++++++++++++-------------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Backends/Audio/SDL2.cpp b/src/Backends/Audio/SDL2.cpp index 74581987..b47bc3ea 100644 --- a/src/Backends/Audio/SDL2.cpp +++ b/src/Backends/Audio/SDL2.cpp @@ -67,12 +67,12 @@ BOOL AudioBackend_Init(void) { if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { - std::string errorMessage = std::string("'SDL_InitSubSystem(SDL_INIT_AUDIO)' failed : ") + SDL_GetError(); + std::string errorMessage = std::string("'SDL_InitSubSystem(SDL_INIT_AUDIO)' failed: ") + SDL_GetError(); Backend_ShowMessageBox("Fatal error (SDL2 audio backend)", errorMessage.c_str()); return FALSE; } - puts("Available SDL2 audio drivers:"); + Backend_PrintInfo("Available SDL2 audio drivers:"); for (int i = 0; i < SDL_GetNumAudioDrivers(); ++i) puts(SDL_GetAudioDriver(i)); @@ -89,7 +89,7 @@ BOOL AudioBackend_Init(void) device_id = SDL_OpenAudioDevice(NULL, 0, &specification, &obtained_specification, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE); if (device_id == 0) { - std::string error_message = std::string("'SDL_OpenAudioDevice' failed : ") + SDL_GetError(); + std::string error_message = std::string("'SDL_OpenAudioDevice' failed: ") + SDL_GetError(); Backend_ShowMessageBox("Fatal error (SDL2 audio backend)", error_message.c_str()); return FALSE; } @@ -99,7 +99,7 @@ BOOL AudioBackend_Init(void) SDL_PauseAudioDevice(device_id, 0); - printf("Selected SDL2 audio driver: %s\n", SDL_GetCurrentAudioDriver()); + Backend_PrintInfo("Selected SDL2 audio driver: %s", SDL_GetCurrentAudioDriver()); return TRUE; } diff --git a/src/Backends/GLFW3/Misc.cpp b/src/Backends/GLFW3/Misc.cpp index 6665d98c..f6f032bb 100644 --- a/src/Backends/GLFW3/Misc.cpp +++ b/src/Backends/GLFW3/Misc.cpp @@ -154,7 +154,7 @@ static void DragAndDropCallback(GLFWwindow *window, int count, const char **path static void ErrorCallback(int code, const char *description) { - Backend_PrintError("GLFW error received (%d) : %s", code, description); + Backend_PrintError("GLFW error received (%d): %s", code, description); } BOOL Backend_Init(void) diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index b62f7af5..ee1fc520 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -567,7 +567,7 @@ static void PostGLCallCallback(const char *name, void *function_pointer, int len GLenum error_code = glad_glGetError(); // Manually use glad_glGetError. Otherwise, glad_debug_glGetError would be called and we'd get infinite recursion into this function if (error_code != GL_NO_ERROR) - Backend_PrintError("Error %d in %s : %s", error_code, name, GetOpenGLErrorCodeDescription(error_code)); + Backend_PrintError("Error %d in %s: %s", error_code, name, GetOpenGLErrorCodeDescription(error_code)); } // ==================== diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index e72aa97c..a125bc82 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -74,7 +74,7 @@ RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_w return &framebuffer; } - std::string error_message = std::string("Could not create framebuffer surface : ") + SDL_GetError(); + std::string error_message = std::string("Could not create framebuffer surface: ") + SDL_GetError(); Backend_ShowMessageBox("Fatal error (SDLSurface rendering backend)", error_message.c_str()); } @@ -82,7 +82,7 @@ RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_w } else { - std::string error_message = std::string("Could not create window : ") + SDL_GetError(); + std::string error_message = std::string("Could not create window: ") + SDL_GetError(); Backend_ShowMessageBox("Fatal error (SDLSurface rendering backend)", error_message.c_str()); } diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 17005fe5..f58a2a87 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -113,7 +113,7 @@ static SPRITEBATCH_U64 GlyphBatch_CreateTexture(void *pixels, int w, int h, void Backend_PrintError("Couldn't create texture for renderer: %s", SDL_GetError()); if (SDL_UpdateTexture(texture, NULL, pixels, w * 4) < 0) - Backend_PrintError("Couldn't update texture : %s", SDL_GetError()); + Backend_PrintError("Couldn't update texture: %s", SDL_GetError()); return (SPRITEBATCH_U64)texture; } @@ -134,7 +134,7 @@ RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_w { SDL_RendererInfo info; if (SDL_GetRenderDriverInfo(i, &info) < 0) - Backend_PrintError("Couldn't get render driver information : %s", SDL_GetError()); + Backend_PrintError("Couldn't get render driver information: %s", SDL_GetError()); else Backend_PrintInfo("%s", info.name); } @@ -159,7 +159,7 @@ RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_w { SDL_RendererInfo info; if (SDL_GetRendererInfo(renderer, &info) < 0) - Backend_PrintError("Couldn't get selected render driver information : %s", SDL_GetError()); + Backend_PrintError("Couldn't get selected render driver information: %s", SDL_GetError()); else Backend_PrintInfo("Selected SDL2 render driver: %s", info.name); @@ -315,7 +315,7 @@ void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int wi if (!buffer) { - Backend_PrintError("Couldn't allocate memory for surface buffer : %s", SDL_GetError()); + Backend_PrintError("Couldn't allocate memory for surface buffer: %s", SDL_GetError()); return; } @@ -345,7 +345,7 @@ void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int wi SDL_Rect rect = {0, 0, (int)width, (int)height}; if (SDL_UpdateTexture(surface->texture, &rect, buffer, width * 4) < 0) - Backend_PrintError("Couldn't update part of texture : %s", SDL_GetError()); + Backend_PrintError("Couldn't update part of texture: %s", SDL_GetError()); free(buffer); } @@ -362,13 +362,13 @@ void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RECT *rect, // Blit the texture if (SDL_SetTextureBlendMode(source_surface->texture, colour_key ? SDL_BLENDMODE_BLEND : SDL_BLENDMODE_NONE) < 0) - Backend_PrintError("Couldn't set texture blend mode : %s", SDL_GetError()); + Backend_PrintError("Couldn't set texture blend mode: %s", SDL_GetError()); if (SDL_SetRenderTarget(renderer, destination_surface->texture) < 0) - Backend_PrintError("Couldn't set current rendering target : %s", SDL_GetError()); + Backend_PrintError("Couldn't set current rendering target: %s", SDL_GetError()); if (SDL_RenderCopy(renderer, source_surface->texture, &source_rect, &destination_rect) < 0) - Backend_PrintError("Couldn't copy part of texture to rendering target : %s", SDL_GetError()); + Backend_PrintError("Couldn't copy part of texture to rendering target: %s", SDL_GetError()); } void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) @@ -386,20 +386,20 @@ void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RECT *rect, alpha = 0; if (SDL_SetRenderDrawColor(renderer, red, green, blue, alpha) < 0) - Backend_PrintError("Couldn't set color for drawing operations : %s", SDL_GetError()); + Backend_PrintError("Couldn't set color for drawing operations: %s", SDL_GetError()); // Draw colour if (SDL_SetRenderTarget(renderer, surface->texture) < 0) - Backend_PrintError("Couldn't set texture current rendering target : %s", SDL_GetError()); + Backend_PrintError("Couldn't set texture current rendering target: %s", SDL_GetError()); if (SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE) < 0) - Backend_PrintError("Couldn't disable blending for drawing operations : %s", SDL_GetError()); + Backend_PrintError("Couldn't disable blending for drawing operations: %s", SDL_GetError()); if (SDL_RenderFillRect(renderer, &sdl_rect) < 0) - Backend_PrintError("Couldn't fill rectangle on current rendering target : %s", SDL_GetError()); + Backend_PrintError("Couldn't fill rectangle on current rendering target: %s", SDL_GetError()); if (SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND) < 0) - Backend_PrintError("Couldn't enable alpha blending for drawing operations : %s", SDL_GetError()); + Backend_PrintError("Couldn't enable alpha blending for drawing operations: %s", SDL_GetError()); } RenderBackend_Glyph* RenderBackend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch) @@ -453,7 +453,7 @@ void RenderBackend_PrepareToDrawGlyphs(RenderBackend_Surface *destination_surfac return; if (SDL_SetRenderTarget(renderer, destination_surface->texture) < 0) - Backend_PrintError("Couldn't set texture as current rendering target : %s", SDL_GetError()); + Backend_PrintError("Couldn't set texture as current rendering target: %s", SDL_GetError()); memcpy(glyph_colour_channels, colour_channels, sizeof(glyph_colour_channels)); }