this repo has no description
0
fork

Configure Feed

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

Changed the error stack to a queue. This, unfortunately, is an implementation detail that affects the API, so maybe it should be renamed someday. However, a queue is the right semantic for this feature, as I want GPU_PopErrorCode() to work as a FIFO container would.

+76 -51
+5 -5
include/SDL_gpu.h
··· 39 39 * \defgroup Logging Debugging, Logging, and Error Handling 40 40 * Use GPU_Log() for normal logging output (e.g. to replace printf). Other logging priorities are handled by GPU_LogWarning() and GPU_LogError(). 41 41 * 42 - * SDL_gpu stores an error stack that you can read and manipulate using GPU_PopErrorCode() and GPU_PushErrorCode(). If you set the debug level using GPU_SetDebugLevel(), you can have any errors automatically logged as they are generated. 42 + * SDL_gpu stores an error queue that you can read and manipulate using GPU_PopErrorCode() and GPU_PushErrorCode(). If you set the debug level using GPU_SetDebugLevel(), you can have any errors automatically logged as they are generated. 43 43 * 44 44 * \defgroup RendererSetup Renderer Setup 45 45 * \defgroup RendererControls Renderer Controls ··· 708 708 /*! Sets a custom callback for handling logging. Use stdio's vsnprintf() to process the va_list into a string. Passing NULL as the callback will reset to the default internal logging. */ 709 709 DECLSPEC void SDLCALL GPU_SetLogCallback(int (*callback)(GPU_LogLevelEnum log_level, const char* format, va_list args)); 710 710 711 - /*! Pushes a new error code onto the error stack. If the stack is full, this function does nothing. 711 + /*! Pushes a new error code into the error queue. If the queue is full, the queue is not modified. 712 712 * \param function The name of the function that pushed the error 713 - * \param error The error code to push on the error stack 713 + * \param error The error code to push on the error queue 714 714 * \param details Additional information string, can be NULL. 715 715 */ 716 716 DECLSPEC void SDLCALL GPU_PushErrorCode(const char* function, GPU_ErrorEnum error, const char* details, ...); 717 717 718 - /*! 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. */ 718 + /*! Pops an error object from the error queue and returns it. If the error queue is empty, it returns an error object with NULL function, GPU_ERROR_NONE error, and NULL details. */ 719 719 DECLSPEC GPU_ErrorObject SDLCALL GPU_PopErrorCode(void); 720 720 721 721 /*! Gets the string representation of an error code. */ 722 722 DECLSPEC const char* SDLCALL GPU_GetErrorString(GPU_ErrorEnum error); 723 723 724 724 /*! Changes the maximum number of error objects that SDL_gpu will store. This deletes all currently stored errors. */ 725 - DECLSPEC void SDLCALL GPU_SetErrorStackMax(unsigned int max); 725 + DECLSPEC void SDLCALL GPU_SetErrorQueueMax(unsigned int max); 726 726 727 727 // End of Logging 728 728 /*! @} */
+71 -46
src/SDL_gpu.c
··· 52 52 #define GPU_DEFAULT_MAX_NUM_ERRORS 20 53 53 #define GPU_ERROR_FUNCTION_STRING_MAX 128 54 54 #define GPU_ERROR_DETAILS_STRING_MAX 512 55 - static GPU_ErrorObject* _gpu_error_code_stack = NULL; 55 + static GPU_ErrorObject* _gpu_error_code_queue = NULL; 56 56 static unsigned int _gpu_num_error_codes = 0; 57 - static unsigned int _gpu_error_code_stack_size = GPU_DEFAULT_MAX_NUM_ERRORS; 57 + static unsigned int _gpu_error_code_queue_size = GPU_DEFAULT_MAX_NUM_ERRORS; 58 + static GPU_ErrorObject _gpu_error_code_result; 58 59 59 60 #define GPU_INITIAL_WINDOW_MAPPINGS_SIZE 10 60 61 static GPU_WindowMapping* _gpu_window_mappings = NULL; ··· 236 237 return _gpu_required_features; 237 238 } 238 239 239 - static void gpu_init_error_stack(void) 240 + static void gpu_init_error_queue(void) 240 241 { 241 - if(_gpu_error_code_stack == NULL) 242 + if(_gpu_error_code_queue == NULL) 242 243 { 243 244 unsigned int i; 244 - _gpu_error_code_stack = (GPU_ErrorObject*)SDL_malloc(sizeof(GPU_ErrorObject)*_gpu_error_code_stack_size); 245 + _gpu_error_code_queue = (GPU_ErrorObject*)SDL_malloc(sizeof(GPU_ErrorObject)*_gpu_error_code_queue_size); 245 246 246 - for(i = 0; i < _gpu_error_code_stack_size; i++) 247 + for(i = 0; i < _gpu_error_code_queue_size; i++) 247 248 { 248 - _gpu_error_code_stack[i].function = (char*)SDL_malloc(GPU_ERROR_FUNCTION_STRING_MAX+1); 249 - _gpu_error_code_stack[i].details = (char*)SDL_malloc(GPU_ERROR_DETAILS_STRING_MAX+1); 249 + _gpu_error_code_queue[i].function = (char*)SDL_malloc(GPU_ERROR_FUNCTION_STRING_MAX+1); 250 + _gpu_error_code_queue[i].error = GPU_ERROR_NONE; 251 + _gpu_error_code_queue[i].details = (char*)SDL_malloc(GPU_ERROR_DETAILS_STRING_MAX+1); 250 252 } 251 253 _gpu_num_error_codes = 0; 254 + 255 + _gpu_error_code_result.function = (char*)SDL_malloc(GPU_ERROR_FUNCTION_STRING_MAX+1); 256 + _gpu_error_code_result.error = GPU_ERROR_NONE; 257 + _gpu_error_code_result.details = (char*)SDL_malloc(GPU_ERROR_DETAILS_STRING_MAX+1); 252 258 } 253 259 } 254 260 ··· 404 410 int i; 405 411 GPU_RendererID renderer_order[GPU_RENDERER_ORDER_MAX]; 406 412 407 - gpu_init_error_stack(); 413 + gpu_init_error_queue(); 408 414 409 415 gpu_init_renderer_register(); 410 416 ··· 437 443 GPU_Renderer* renderer; 438 444 GPU_Target* screen; 439 445 440 - gpu_init_error_stack(); 446 + gpu_init_error_queue(); 441 447 gpu_init_renderer_register(); 442 448 443 449 if(!gpu_init_SDL()) ··· 581 587 image->using_virtual_resolution = 0; 582 588 } 583 589 584 - // Deletes all existing errors 585 - void GPU_SetErrorStackMax(unsigned int max) 590 + void gpu_free_error_queue(void) 586 591 { 587 592 unsigned int i; 588 - // Free the error stack 589 - for(i = 0; i < _gpu_error_code_stack_size; i++) 593 + // Free the error queue 594 + for(i = 0; i < _gpu_error_code_queue_size; i++) 590 595 { 591 - SDL_free(_gpu_error_code_stack[i].function); 592 - _gpu_error_code_stack[i].function = NULL; 593 - SDL_free(_gpu_error_code_stack[i].details); 594 - _gpu_error_code_stack[i].details = NULL; 596 + SDL_free(_gpu_error_code_queue[i].function); 597 + _gpu_error_code_queue[i].function = NULL; 598 + SDL_free(_gpu_error_code_queue[i].details); 599 + _gpu_error_code_queue[i].details = NULL; 595 600 } 596 - SDL_free(_gpu_error_code_stack); 597 - _gpu_error_code_stack = NULL; 601 + SDL_free(_gpu_error_code_queue); 602 + _gpu_error_code_queue = NULL; 598 603 _gpu_num_error_codes = 0; 599 604 605 + SDL_free(_gpu_error_code_result.function); 606 + _gpu_error_code_result.function = NULL; 607 + SDL_free(_gpu_error_code_result.details); 608 + _gpu_error_code_result.details = NULL; 609 + } 610 + 611 + // Deletes all existing errors 612 + void GPU_SetErrorQueueMax(unsigned int max) 613 + { 614 + gpu_free_error_queue(); 615 + 600 616 // Reallocate with new size 601 - _gpu_error_code_stack_size = max; 602 - gpu_init_error_stack(); 617 + _gpu_error_code_queue_size = max; 618 + gpu_init_error_queue(); 603 619 } 604 620 605 621 void GPU_CloseCurrentRenderer(void) ··· 613 629 614 630 void GPU_Quit(void) 615 631 { 616 - unsigned int i; 617 632 if(_gpu_num_error_codes > 0 && GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_1) 618 633 GPU_LogError("GPU_Quit: %d uncleared error%s.\n", _gpu_num_error_codes, (_gpu_num_error_codes > 1? "s" : "")); 619 - 620 - // Free the error stack 621 - for(i = 0; i < _gpu_error_code_stack_size; i++) 622 - { 623 - SDL_free(_gpu_error_code_stack[i].function); 624 - _gpu_error_code_stack[i].function = NULL; 625 - SDL_free(_gpu_error_code_stack[i].details); 626 - _gpu_error_code_stack[i].details = NULL; 627 - } 628 - SDL_free(_gpu_error_code_stack); 629 - _gpu_error_code_stack = NULL; 630 - _gpu_num_error_codes = 0; 634 + 635 + gpu_free_error_queue(); 631 636 632 637 if(_gpu_current_renderer == NULL) 633 638 return; ··· 674 679 675 680 void GPU_PushErrorCode(const char* function, GPU_ErrorEnum error, const char* details, ...) 676 681 { 682 + gpu_init_error_queue(); 683 + 677 684 if(GPU_GetDebugLevel() >= GPU_DEBUG_LEVEL_1) 678 685 { 679 686 // Print the message ··· 691 698 GPU_LogError("%s: %s\n", (function == NULL? "NULL" : function), GPU_GetErrorString(error)); 692 699 } 693 700 694 - if(_gpu_num_error_codes < _gpu_error_code_stack_size) 701 + if(_gpu_num_error_codes < _gpu_error_code_queue_size) 695 702 { 696 703 if(function == NULL) 697 - _gpu_error_code_stack[_gpu_num_error_codes].function[0] = '\0'; 704 + _gpu_error_code_queue[_gpu_num_error_codes].function[0] = '\0'; 698 705 else 699 706 { 700 - strncpy(_gpu_error_code_stack[_gpu_num_error_codes].function, function, GPU_ERROR_FUNCTION_STRING_MAX); 701 - _gpu_error_code_stack[_gpu_num_error_codes].function[GPU_ERROR_FUNCTION_STRING_MAX] = '\0'; 707 + strncpy(_gpu_error_code_queue[_gpu_num_error_codes].function, function, GPU_ERROR_FUNCTION_STRING_MAX); 708 + _gpu_error_code_queue[_gpu_num_error_codes].function[GPU_ERROR_FUNCTION_STRING_MAX] = '\0'; 702 709 } 703 - _gpu_error_code_stack[_gpu_num_error_codes].error = error; 710 + _gpu_error_code_queue[_gpu_num_error_codes].error = error; 704 711 if(details == NULL) 705 - _gpu_error_code_stack[_gpu_num_error_codes].details[0] = '\0'; 712 + _gpu_error_code_queue[_gpu_num_error_codes].details[0] = '\0'; 706 713 else 707 714 { 708 715 va_list lst; 709 716 va_start(lst, details); 710 - vsnprintf(_gpu_error_code_stack[_gpu_num_error_codes].details, GPU_ERROR_DETAILS_STRING_MAX, details, lst); 717 + vsnprintf(_gpu_error_code_queue[_gpu_num_error_codes].details, GPU_ERROR_DETAILS_STRING_MAX, details, lst); 711 718 va_end(lst); 712 719 } 713 720 _gpu_num_error_codes++; ··· 716 723 717 724 GPU_ErrorObject GPU_PopErrorCode(void) 718 725 { 726 + unsigned int i; 727 + GPU_ErrorObject result = {NULL, GPU_ERROR_NONE, NULL}; 728 + 729 + gpu_init_error_queue(); 730 + 719 731 if(_gpu_num_error_codes <= 0) 732 + return result; 733 + 734 + // Pop the oldest 735 + strcpy(_gpu_error_code_result.function, _gpu_error_code_queue[0].function); 736 + _gpu_error_code_result.error = _gpu_error_code_queue[0].error; 737 + strcpy(_gpu_error_code_result.details, _gpu_error_code_queue[0].details); 738 + 739 + // We'll be returning that one 740 + result = _gpu_error_code_result; 741 + 742 + // Move the rest down 743 + _gpu_num_error_codes--; 744 + for(i = 0; i < _gpu_num_error_codes; i++) 720 745 { 721 - GPU_ErrorObject e = {NULL, GPU_ERROR_NONE, NULL}; 722 - return e; 746 + strcpy(_gpu_error_code_queue[i].function, _gpu_error_code_queue[i+1].function); 747 + _gpu_error_code_queue[i].error = _gpu_error_code_queue[i+1].error; 748 + strcpy(_gpu_error_code_queue[i].details, _gpu_error_code_queue[i+1].details); 723 749 } 724 - 725 - return _gpu_error_code_stack[--_gpu_num_error_codes]; 750 + return result; 726 751 } 727 752 728 753 const char* GPU_GetErrorString(GPU_ErrorEnum error)