shithub: cstory

Download patch

ref: dcd4bcf1b28cbce4156351590a69dfb8f423a06b
parent: 5fc0f5852529a4c186ebb701680a8f06f22a628e
author: Gabriel Ravier <[email protected]>
date: Sat Apr 11 20:42:24 EDT 2020

Backends: Fix some of the error handling and replaced some printf calls

Signed-off-by: Gabriel Ravier <[email protected]>

--- a/src/Backends/Audio/SDL2.cpp
+++ b/src/Backends/Audio/SDL2.cpp
@@ -67,12 +67,12 @@
 {
 	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 @@
 	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 @@
 
 	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;
 }
--- a/src/Backends/GLFW3/Misc.cpp
+++ b/src/Backends/GLFW3/Misc.cpp
@@ -154,7 +154,7 @@
 
 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)
--- a/src/Backends/Rendering/OpenGL3.cpp
+++ b/src/Backends/Rendering/OpenGL3.cpp
@@ -567,7 +567,7 @@
 	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));
 }
 
 // ====================
--- a/src/Backends/Rendering/SDLSurface.cpp
+++ b/src/Backends/Rendering/SDLSurface.cpp
@@ -74,7 +74,7 @@
 				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 @@
 	}
 	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());
 	}
 
--- a/src/Backends/Rendering/SDLTexture.cpp
+++ b/src/Backends/Rendering/SDLTexture.cpp
@@ -113,7 +113,7 @@
 		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 @@
 	{
 		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 @@
 		{
 			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 @@
 
 	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 @@
 
 	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 @@
 
 	// 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 @@
 		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 @@
 		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));
 }