this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Changed storage of error stack so it holds allocated strings. This lets GPU_PushErrorCode() accept a variadic details string and now certain error messages can include more specific details.

+73 -31
+16 -16
SDL_gpu/GL_common/SDL_gpu_GL_common.inl
··· 1037 1037 renderer->id.minor_version = 0; 1038 1038 #endif 1039 1039 1040 - GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to parse OpenGL version string"); 1040 + GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to parse OpenGL version string: \"%s\"", version_string); 1041 1041 } 1042 1042 #else 1043 1043 // GLES doesn't have GL_MAJOR_VERSION. Check via version string instead. ··· 1055 1055 renderer->id.minor_version = 0; 1056 1056 #endif 1057 1057 1058 - GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to parse OpenGL version string"); 1058 + GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Failed to parse OpenGL version string: \"%s\"", version_string); 1059 1059 } 1060 1060 } 1061 1061 #endif ··· 1064 1064 if(renderer->id.major_version < renderer->requested_id.major_version) 1065 1065 { 1066 1066 #ifdef SDL_GPU_USE_GLES 1067 - GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Renderer is incompatible with the available OpenGL runtime library."); 1067 + GPU_PushErrorCode("GPU_CreateTargetFromWindow", GPU_ERROR_BACKEND_ERROR, "Renderer version (%d) is incompatible with the available OpenGL runtime library version (%d).", renderer->requested_id.major_version, renderer->id.major_version); 1068 1068 #endif 1069 1069 return NULL; 1070 1070 } ··· 1513 1513 1514 1514 if(channels < 1 || channels > 4) 1515 1515 { 1516 - GPU_PushErrorCode("GPU_CreateUninitializedImage", GPU_ERROR_DATA_ERROR, "Unsupported number of color channels"); 1516 + GPU_PushErrorCode("GPU_CreateUninitializedImage", GPU_ERROR_DATA_ERROR, "Unsupported number of color channels (%d)", channels); 1517 1517 return NULL; 1518 1518 } 1519 1519 ··· 1574 1574 { 1575 1575 if(format < 1 || format > GPU_FORMAT_RGBA) 1576 1576 { 1577 - GPU_PushErrorCode("GPU_CreateImage", GPU_ERROR_DATA_ERROR, "Unsupported image format"); 1577 + GPU_PushErrorCode("GPU_CreateImage", GPU_ERROR_DATA_ERROR, "Unsupported image format (%x)", format); 1578 1578 return NULL; 1579 1579 } 1580 1580 ··· 1789 1789 result = stbi_write_tga(filename, image->w, image->h, image->channels, (void*)data); 1790 1790 else 1791 1791 { 1792 - GPU_PushErrorCode("GPU_SaveImage", GPU_ERROR_DATA_ERROR, "Unsupported output file format"); 1792 + GPU_PushErrorCode("GPU_SaveImage", GPU_ERROR_DATA_ERROR, "Unsupported output file format (%s)", extension); 1793 1793 result = 0; 1794 1794 } 1795 1795 ··· 1809 1809 } 1810 1810 if(target->w < 1 || target->h < 1) 1811 1811 { 1812 - GPU_PushErrorCode("GPU_CopySurfaceFromTarget", GPU_ERROR_DATA_ERROR, "Invalid target dimensions"); 1812 + GPU_PushErrorCode("GPU_CopySurfaceFromTarget", GPU_ERROR_DATA_ERROR, "Invalid target dimensions (%dx%d)", target->w, target->h); 1813 1813 return NULL; 1814 1814 } 1815 1815 ··· 1841 1841 } 1842 1842 if(image->w < 1 || image->h < 1) 1843 1843 { 1844 - GPU_PushErrorCode("GPU_CopySurfaceFromImage", GPU_ERROR_DATA_ERROR, "Invalid image dimensions"); 1844 + GPU_PushErrorCode("GPU_CopySurfaceFromImage", GPU_ERROR_DATA_ERROR, "Invalid image dimensions (%dx%d)", image->w, image->h); 1845 1845 return NULL; 1846 1846 } 1847 1847 ··· 1939 1939 #endif 1940 1940 return 1; 1941 1941 default: 1942 - GPU_PushErrorCode("GPU_CompareFormats", GPU_ERROR_DATA_ERROR, "Invalid texture format"); 1942 + GPU_PushErrorCode("GPU_CompareFormats", GPU_ERROR_DATA_ERROR, "Invalid texture format (%x)", glFormat); 1943 1943 return -1; 1944 1944 } 1945 1945 } ··· 2016 2016 } 2017 2017 return 1; 2018 2018 default: 2019 - GPU_PushErrorCode("GPU_CompareFormats", GPU_ERROR_DATA_ERROR, "Invalid texture format"); 2019 + GPU_PushErrorCode("GPU_CompareFormats", GPU_ERROR_DATA_ERROR, "Invalid texture format (%x)", glFormat); 2020 2020 return -1; 2021 2021 } 2022 2022 } ··· 2447 2447 channels = fmt->BytesPerPixel; 2448 2448 if(channels < 1 || channels > 4) 2449 2449 { 2450 - GPU_PushErrorCode("GPU_CopyImageFromSurface", GPU_ERROR_DATA_ERROR, "Unsupported number of channels in surface"); 2450 + GPU_PushErrorCode("GPU_CopyImageFromSurface", GPU_ERROR_DATA_ERROR, "Unsupported number of channels in surface (%d)", channels); 2451 2451 return NULL; 2452 2452 } 2453 2453 ··· 3908 3908 magFilter = GL_LINEAR; 3909 3909 break; 3910 3910 default: 3911 - GPU_PushErrorCode("GPU_SetImageFilter", GPU_ERROR_USER_ERROR, "Unsupported value for filter"); 3911 + GPU_PushErrorCode("GPU_SetImageFilter", GPU_ERROR_USER_ERROR, "Unsupported value for filter (%x)", filter); 3912 3912 return; 3913 3913 } 3914 3914 ··· 3954 3954 } 3955 3955 break; 3956 3956 default: 3957 - GPU_PushErrorCode("GPU_SetWrapMode", GPU_ERROR_USER_ERROR, "Unsupported value for wrap_mode_x"); 3957 + GPU_PushErrorCode("GPU_SetWrapMode", GPU_ERROR_USER_ERROR, "Unsupported value for wrap_mode_x (%x)", wrap_mode_x); 3958 3958 return; 3959 3959 } 3960 3960 ··· 3976 3976 } 3977 3977 break; 3978 3978 default: 3979 - GPU_PushErrorCode("GPU_SetWrapMode", GPU_ERROR_USER_ERROR, "Unsupported value for wrap_mode_y"); 3979 + GPU_PushErrorCode("GPU_SetWrapMode", GPU_ERROR_USER_ERROR, "Unsupported value for wrap_mode_y (%x)", wrap_mode_y); 3980 3980 return; 3981 3981 } 3982 3982 ··· 4967 4967 return; 4968 4968 if(num_rows < 2 || num_rows > 4 || num_columns < 2 || num_columns > 4) 4969 4969 { 4970 - GPU_PushErrorCode("GPU_SetUniformMatrixfv", GPU_ERROR_DATA_ERROR, "Given invalid dimensions"); 4970 + GPU_PushErrorCode("GPU_SetUniformMatrixfv", GPU_ERROR_DATA_ERROR, "Given invalid dimensions (%dx%d)", num_rows, num_columns); 4971 4971 return; 4972 4972 } 4973 4973 #if defined(SDL_GPU_USE_GLES) ··· 4980 4980 #define glUniformMatrix4x3fv glUniformMatrix2fv 4981 4981 if(num_rows != num_columns) 4982 4982 { 4983 - GPU_PushErrorCode("GPU_SetUniformMatrixfv", GPU_ERROR_DATA_ERROR, "GLES renderers do not accept non-square matrices"); 4983 + GPU_PushErrorCode("GPU_SetUniformMatrixfv", GPU_ERROR_DATA_ERROR, "GLES renderers do not accept non-square matrices (given %dx%d)", num_rows, num_columns); 4984 4984 return; 4985 4985 } 4986 4986 #endif
+1 -1
SDL_gpu/GL_common/SDL_gpu_GL_matrix.c
··· 132 132 GPU_MatrixStack* stack = (target->context->matrix_mode == GPU_MODELVIEW? &target->context->modelview_matrix : &target->context->projection_matrix); 133 133 if(stack->size + 1 >= GPU_MATRIX_STACK_MAX) 134 134 { 135 - GPU_PushErrorCode(__func__, GPU_ERROR_USER_ERROR, "Matrix stack is full."); 135 + GPU_PushErrorCode(__func__, GPU_ERROR_USER_ERROR, "Matrix stack is full (%d)", GPU_MATRIX_STACK_MAX); 136 136 return; 137 137 } 138 138 GPU_MatrixCopy(stack->matrix[stack->size], stack->matrix[stack->size-1]);
+52 -10
SDL_gpu/SDL_gpu.c
··· 16 16 #define CHECK_RENDERER (current_renderer != NULL) 17 17 #define CHECK_CONTEXT (current_renderer->current_context_target != NULL) 18 18 #define CHECK_FUNCTION_POINTER(fn) (current_renderer->fn != NULL) 19 - #define RETURN_ERROR(code, details) do{ GPU_PushErrorCode(__func__, code, details); return; } while(0) 19 + #define RETURN_ERROR(code, details) do{ GPU_PushErrorCode(__func__, code, "%s", details); return; } while(0) 20 20 21 21 void GPU_InitRendererRegister(void); 22 22 ··· 24 24 25 25 static GPU_DebugLevelEnum debug_level = GPU_DEBUG_LEVEL_0; 26 26 27 - #define GPU_MAX_NUM_ERRORS 30 27 + #define GPU_MAX_NUM_ERRORS 20 28 + #define GPU_ERROR_FUNCTION_STRING_MAX 128 29 + #define GPU_ERROR_DETAILS_STRING_MAX 512 28 30 static GPU_ErrorObject error_code_stack[GPU_MAX_NUM_ERRORS]; 29 31 static int num_error_codes = 0; 30 32 ··· 148 150 149 151 GPU_Target* GPU_Init(Uint16 w, Uint16 h, GPU_WindowFlagEnum SDL_flags) 150 152 { 153 + // Init the error stack 154 + int i; 155 + for(i = 0; i < GPU_MAX_NUM_ERRORS; i++) 156 + { 157 + error_code_stack[i].function = (char*)malloc(GPU_ERROR_FUNCTION_STRING_MAX); 158 + error_code_stack[i].details = (char*)malloc(GPU_ERROR_DETAILS_STRING_MAX); 159 + } 160 + 151 161 GPU_InitRendererRegister(); 152 162 153 163 if(!init_SDL()) ··· 158 168 GPU_GetRendererOrder(&renderer_order_size, renderer_order); 159 169 160 170 // Init the renderers in order 161 - int i; 162 171 for(i = 0; i < renderer_order_size; i++) 163 172 { 164 173 GPU_Target* screen = GPU_InitRendererByID(renderer_order[i], w, h, SDL_flags); ··· 278 287 { 279 288 if(num_error_codes > 0 && GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_1) 280 289 GPU_LogError("GPU_Quit: %d uncleared errors.\n", num_error_codes); 290 + 291 + // Free the error stack 292 + int i; 293 + for(i = 0; i < GPU_MAX_NUM_ERRORS; i++) 294 + { 295 + free(error_code_stack[i].function); 296 + error_code_stack[i].function = NULL; 297 + free(error_code_stack[i].details); 298 + error_code_stack[i].details = NULL; 299 + } 281 300 282 301 // FIXME: Remove all renderers 283 302 if(current_renderer == NULL) ··· 303 322 return debug_level; 304 323 } 305 324 306 - void GPU_PushErrorCode(const char* function, GPU_ErrorEnum error, const char* details) 325 + void GPU_PushErrorCode(const char* function, GPU_ErrorEnum error, const char* details, ...) 307 326 { 308 327 if(GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_1) 309 328 { 310 329 // Print the message 311 330 if(details != NULL) 312 - GPU_LogError("%s: %s - %s\n", (function == NULL? "NULL" : function), GPU_GetErrorString(error), details); 331 + { 332 + char buf[GPU_ERROR_DETAILS_STRING_MAX]; 333 + va_list lst; 334 + va_start(lst, details); 335 + vsnprintf(buf, GPU_ERROR_DETAILS_STRING_MAX, details, lst); 336 + va_end(lst); 337 + 338 + GPU_LogError("%s: %s - %s\n", (function == NULL? "NULL" : function), GPU_GetErrorString(error), buf); 339 + } 313 340 else 314 341 GPU_LogError("%s: %s\n", (function == NULL? "NULL" : function), GPU_GetErrorString(error)); 315 342 } 316 343 317 344 if(num_error_codes < GPU_MAX_NUM_ERRORS) 318 345 { 319 - GPU_ErrorObject e = {function, error, details}; 320 - error_code_stack[num_error_codes] = e; 346 + if(function == NULL) 347 + error_code_stack[num_error_codes].function[0] = '\0'; 348 + else 349 + { 350 + strncpy(error_code_stack[num_error_codes].function, function, GPU_ERROR_FUNCTION_STRING_MAX); 351 + error_code_stack[num_error_codes].function[GPU_ERROR_FUNCTION_STRING_MAX] = '\0'; 352 + } 353 + error_code_stack[num_error_codes].error = error; 354 + if(details == NULL) 355 + error_code_stack[num_error_codes].details[0] = '\0'; 356 + else 357 + { 358 + va_list lst; 359 + va_start(lst, details); 360 + vsnprintf(error_code_stack[num_error_codes].details, GPU_ERROR_DETAILS_STRING_MAX, details, lst); 361 + va_end(lst); 362 + } 321 363 num_error_codes++; 322 364 } 323 365 } ··· 509 551 510 552 if(data == NULL) 511 553 { 512 - GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, stbi_failure_reason()); 554 + GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "Failed to load \"%s\": %s", filename, stbi_failure_reason()); 513 555 return NULL; 514 556 } 515 557 if(channels < 1 || channels > 4) 516 558 { 517 - GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "Unsupported pixel format"); 559 + GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "Failed to load \"%s\": Unsupported pixel format", filename); 518 560 stbi_image_free(data); 519 561 return NULL; 520 562 } ··· 1745 1787 SDL_RWops* rwops = SDL_RWFromFile(filename, "r"); 1746 1788 if(rwops == NULL) 1747 1789 { 1748 - GPU_PushErrorCode(__func__, GPU_ERROR_FILE_NOT_FOUND, filename); 1790 + GPU_PushErrorCode(__func__, GPU_ERROR_FILE_NOT_FOUND, "%s", filename); 1749 1791 return 0; 1750 1792 } 1751 1793 Uint32 result = GPU_CompileShader_RW(shader_type, rwops);
+3 -3
SDL_gpu/SDL_gpu.h
··· 407 407 408 408 typedef struct GPU_ErrorObject 409 409 { 410 - const char* function; 410 + char* function; 411 411 GPU_ErrorEnum error; 412 - const char* details; 412 + char* details; 413 413 } GPU_ErrorObject; 414 414 415 415 ··· 834 834 * \param error The error code to push on the error stack 835 835 * \param details Additional information string, can be NULL. 836 836 */ 837 - void GPU_PushErrorCode(const char* function, GPU_ErrorEnum error, const char* details); 837 + void GPU_PushErrorCode(const char* function, GPU_ErrorEnum error, const char* details, ...); 838 838 839 839 /*! Pops an error object from the error stack and returns it. If the error stack is empty, it returns an error object with NULL function, GPU_ERROR_NONE error, and NULL details. */ 840 840 GPU_ErrorObject GPU_PopErrorCode(void);
+1 -1
SDL_gpu/SDL_gpu_Renderer.c
··· 242 242 243 243 if(order_size > GPU_RENDERER_ORDER_MAX) 244 244 { 245 - GPU_PushErrorCode(__func__, GPU_ERROR_USER_ERROR, "Given order_size is greater than GPU_RENDERER_ORDER_MAX."); 245 + GPU_PushErrorCode(__func__, GPU_ERROR_USER_ERROR, "Given order_size (%d) is greater than GPU_RENDERER_ORDER_MAX (%d)", order_size, GPU_RENDERER_ORDER_MAX); 246 246 order_size = GPU_RENDERER_ORDER_MAX; 247 247 } 248 248