riscos: Improve error reporting SDL-1.2
authorCameron Cawley <ccawley2011@gmail.com>
Tue, 18 Jun 2019 23:55:01 +0100
branchSDL-1.2
changeset 12913d07b4feae69c
parent 12831 f1f5878be5db
child 12914 87d60cae0273
riscos: Improve error reporting
src/joystick/riscos/SDL_sysjoystick.c
src/video/riscos/SDL_riscosFullScreenVideo.c
src/video/riscos/SDL_riscosmouse.c
src/video/riscos/SDL_riscossprite.c
src/video/riscos/SDL_riscostask.c
src/video/riscos/SDL_riscosvideo.c
src/video/riscos/SDL_wimpvideo.c
     1.1 --- a/src/joystick/riscos/SDL_sysjoystick.c	Tue Jun 11 06:28:12 2019 -0700
     1.2 +++ b/src/joystick/riscos/SDL_sysjoystick.c	Tue Jun 18 23:55:01 2019 +0100
     1.3 @@ -89,8 +89,10 @@
     1.4   */
     1.5  int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
     1.6  {
     1.7 -	if(!(joystick->hwdata=SDL_malloc(sizeof(struct joystick_hwdata))))
     1.8 +	if(!(joystick->hwdata=SDL_malloc(sizeof(struct joystick_hwdata)))) {
     1.9 +		SDL_OutOfMemory();
    1.10  		return -1;
    1.11 +	}
    1.12  
    1.13  	/* Don't know how to get exact count of buttons so assume max of 4 for now */
    1.14  	joystick->nbuttons=4;
     2.1 --- a/src/video/riscos/SDL_riscosFullScreenVideo.c	Tue Jun 11 06:28:12 2019 -0700
     2.2 +++ b/src/video/riscos/SDL_riscosFullScreenVideo.c	Tue Jun 18 23:55:01 2019 +0100
     2.3 @@ -88,7 +88,6 @@
     2.4     const RISCOS_SDL_PixelFormat *fmt = FULLSCREEN_SetMode(width, height, bpp);
     2.5     if (fmt == NULL)
     2.6     {
     2.7 -	   SDL_SetError("Couldn't set requested mode");
     2.8  	   return (NULL);
     2.9     }
    2.10  
    2.11 @@ -96,8 +95,7 @@
    2.12  
    2.13  	/* Allocate the new pixel format for the screen */
    2.14  	if ( ! SDL_ReallocFormat(current, fmt->sdl_bpp, fmt->rmask, fmt->gmask, fmt->bmask, 0) ) {
    2.15 -	    RISCOS_RestoreWimpMode();
    2.16 -		SDL_SetError("Couldn't allocate new pixel format for requested mode");
    2.17 +		RISCOS_RestoreWimpMode();
    2.18  		return(NULL);
    2.19  	}
    2.20  
    2.21 @@ -154,14 +152,16 @@
    2.22           ** This is turned on by setting the enviromental variable
    2.23           ** SDL$<name>$BackBuffer >= 1
    2.24           */
    2.25 -       if (riscos_backbuffer == 3)
    2.26 +       if (riscos_backbuffer == 3) {
    2.27            this->hidden->bank[0] = WIMP_CreateBuffer(width, height, &fmt->ro);
    2.28 -       else
    2.29 +       } else {
    2.30            this->hidden->bank[0] = SDL_malloc(height * current->pitch);
    2.31 +          if (this->hidden->bank[0] == 0)
    2.32 +             SDL_OutOfMemory();
    2.33 +       }
    2.34         if (this->hidden->bank[0] == 0)
    2.35         {
    2.36 - 	       RISCOS_RestoreWimpMode();
    2.37 -           SDL_SetError("Couldnt allocate memory for back buffer");
    2.38 +           RISCOS_RestoreWimpMode();
    2.39             return (NULL);
    2.40         }
    2.41         /* Surface updated in programs is now a software surface */
     3.1 --- a/src/video/riscos/SDL_riscosmouse.c	Tue Jun 11 06:28:12 2019 -0700
     3.2 +++ b/src/video/riscos/SDL_riscosmouse.c	Tue Jun 18 23:55:01 2019 +0100
     3.3 @@ -69,14 +69,14 @@
     3.4  
     3.5  	/* Check to make sure the cursor size is okay */
     3.6  	if ( (w > 32) || (h > 32) ) {
     3.7 -		SDL_SetError("Only with width and height <= 32 pixels are allowed");
     3.8 +		SDL_SetError("Only cursors with width and height <= 32 pixels are allowed");
     3.9  		return(NULL);
    3.10  	}
    3.11  
    3.12  	/* Allocate the cursor */
    3.13  	cursor = (WMcursor *)SDL_malloc(sizeof(*cursor));
    3.14  	if ( cursor == NULL ) {
    3.15 -		SDL_SetError("Out of memory");
    3.16 +		SDL_OutOfMemory();
    3.17  		return(NULL);
    3.18  	}
    3.19  
    3.20 @@ -85,7 +85,7 @@
    3.21  	if (cursor_data == NULL)
    3.22  	{
    3.23  		SDL_free(cursor);
    3.24 -		SDL_SetError("Out of memory");
    3.25 +		SDL_OutOfMemory();
    3.26  		return(NULL);
    3.27  	}
    3.28  
    3.29 @@ -160,7 +160,7 @@
    3.30  
    3.31  			if (_kernel_osword(21, (int *)cursor_def) != 0)
    3.32  			{
    3.33 -				SDL_SetError("RISCOS couldn't create the cursor to show");
    3.34 +				SDL_SetError("RISC OS couldn't create the cursor to show");
    3.35  				return(0);
    3.36  			}
    3.37  			defined_cursor = cursor;
     4.1 --- a/src/video/riscos/SDL_riscossprite.c	Tue Jun 11 06:28:12 2019 -0700
     4.2 +++ b/src/video/riscos/SDL_riscossprite.c	Tue Jun 18 23:55:01 2019 +0100
     4.3 @@ -96,6 +96,7 @@
     4.4     char sprite_name[12] = "display";
     4.5     unsigned char *buffer;
     4.6     _kernel_swi_regs regs;
     4.7 +   _kernel_oserror *error;
     4.8     int bytesPerPixel = 1 << (format->log2bpp-3);
     4.9     int bytesPerRow;
    4.10     int offsetToSpriteData = 60;
    4.11 @@ -114,7 +115,10 @@
    4.12     size = bytesPerRow * height;
    4.13  
    4.14     buffer = SDL_malloc( (size_t) size + offsetToSpriteData );
    4.15 -   if (!buffer) return NULL;
    4.16 +   if (!buffer) {
    4.17 +      SDL_OutOfMemory();
    4.18 +      return NULL;
    4.19 +   }
    4.20  
    4.21     /* Initialise a sprite area */
    4.22  
    4.23 @@ -132,7 +136,8 @@
    4.24     regs.r[4] = width;
    4.25     regs.r[5] = height;
    4.26     regs.r[6] = format->sprite_mode_word;
    4.27 -   if (_kernel_swi(OS_SpriteOp, &regs, &regs) == NULL)
    4.28 +   error = _kernel_swi(OS_SpriteOp, &regs, &regs);
    4.29 +   if (error == NULL)
    4.30     {
    4.31         if (format->log2bpp == 3)
    4.32         {
    4.33 @@ -162,6 +167,7 @@
    4.34         }
    4.35     } else
    4.36     {
    4.37 +      SDL_SetError("Unable to create sprite: %s (%i)", error->errmess, error->errnum);
    4.38        SDL_free(buffer);
    4.39        buffer = NULL;
    4.40     }
     5.1 --- a/src/video/riscos/SDL_riscostask.c	Tue Jun 11 06:28:12 2019 -0700
     5.2 +++ b/src/video/riscos/SDL_riscostask.c	Tue Jun 18 23:55:01 2019 +0100
     5.3 @@ -58,7 +58,7 @@
     5.4  
     5.5  /* Local function */
     5.6  
     5.7 -static int RISCOS_GetTaskName(char *task_name, size_t maxlen);
     5.8 +static void RISCOS_GetTaskName(char *task_name, size_t maxlen);
     5.9  
    5.10  /* Uncomment next line to copy mode changes/restores to stderr */
    5.11  /* #define DUMP_MODE */
    5.12 @@ -94,9 +94,10 @@
    5.13  {
    5.14     char task_name[32];
    5.15     _kernel_swi_regs regs;
    5.16 +   _kernel_oserror *error;
    5.17     int messages[4];
    5.18  
    5.19 -   if (RISCOS_GetTaskName(task_name, SDL_arraysize(task_name)) == 0) return 0;
    5.20 +   RISCOS_GetTaskName(task_name, SDL_arraysize(task_name));
    5.21  
    5.22     messages[0] = 9;       /* Palette changed */
    5.23     messages[1] = 0x400c1; /* Mode changed */
    5.24 @@ -108,7 +109,8 @@
    5.25  	regs.r[2] = (unsigned int)task_name;
    5.26  	regs.r[3] = (unsigned int)messages;
    5.27  
    5.28 -   if (_kernel_swi(Wimp_Initialise, &regs, &regs) == 0)
    5.29 +   error = _kernel_swi(Wimp_Initialise, &regs, &regs);
    5.30 +   if (error == 0)
    5.31     {
    5.32  	   wimp_version = regs.r[0];
    5.33  	   task_handle = regs.r[1];
    5.34 @@ -119,6 +121,7 @@
    5.35     main_thread = pthread_self();
    5.36  #endif
    5.37  
    5.38 +   SDL_SetError("Unable to start task: %s (%i)", error->errmess, error->errnum);
    5.39     return 0;
    5.40  }
    5.41  
    5.42 @@ -182,7 +185,7 @@
    5.43  
    5.44  ***************************************************************************/
    5.45  
    5.46 -int RISCOS_GetTaskName(char *task_name, size_t maxlen)
    5.47 +void RISCOS_GetTaskName(char *task_name, size_t maxlen)
    5.48  {
    5.49  	_kernel_swi_regs regs;
    5.50  
    5.51 @@ -262,8 +265,6 @@
    5.52     }
    5.53  
    5.54     if (task_name[0] == 0) SDL_strlcpy(task_name, "SDL Task", maxlen);
    5.55 -
    5.56 -   return 1;
    5.57  }
    5.58  
    5.59  /*****************************************************************
     6.1 --- a/src/video/riscos/SDL_riscosvideo.c	Tue Jun 11 06:28:12 2019 -0700
     6.2 +++ b/src/video/riscos/SDL_riscosvideo.c	Tue Jun 18 23:55:01 2019 +0100
     6.3 @@ -201,7 +201,6 @@
     6.4  
     6.5  	if (RISCOS_InitTask() == 0)
     6.6  	{
     6.7 -		SDL_SetError("Unable to start task");
     6.8  		return 0;
     6.9  	}
    6.10  
     7.1 --- a/src/video/riscos/SDL_wimpvideo.c	Tue Jun 11 06:28:12 2019 -0700
     7.2 +++ b/src/video/riscos/SDL_wimpvideo.c	Tue Jun 18 23:55:01 2019 +0100
     7.3 @@ -72,7 +72,7 @@
     7.4  		fmt = WIMP_FindSupportedSpriteFormat(bpp);
     7.5  		if (fmt == NULL)
     7.6  		{
     7.7 -			SDL_SetError("Pixel depth not supported");
     7.8 +			SDL_SetError("Pixel depth %d not supported", bpp);
     7.9  			return NULL;
    7.10  		}
    7.11  	}
    7.12 @@ -88,7 +88,6 @@
    7.13  
    7.14  	/* Allocate the new pixel format for the screen */
    7.15  	if ( ! SDL_ReallocFormat(current, fmt->sdl_bpp, fmt->rmask, fmt->gmask, fmt->bmask, 0) ) {
    7.16 -		SDL_SetError("Couldn't allocate new pixel format for requested mode");
    7.17  		return(NULL);
    7.18  	}
    7.19  
    7.20 @@ -100,7 +99,6 @@
    7.21  	buffer = WIMP_CreateBuffer(width, height, &fmt->ro);
    7.22  	if (buffer == NULL)
    7.23  	{
    7.24 -		SDL_SetError("Couldn't create sprite for video memory");
    7.25  		return (NULL);
    7.26  	}
    7.27  
    7.28 @@ -133,7 +131,6 @@
    7.29  
    7.30  	if (WIMP_SetupWindow(this, current) == 0)
    7.31  	{
    7.32 -		SDL_SetError("Unable to create window to display surface");
    7.33  		return NULL;
    7.34  	}
    7.35  
    7.36 @@ -213,6 +210,7 @@
    7.37  unsigned int WIMP_SetupWindow(_THIS, SDL_Surface *surface)
    7.38  {
    7.39  	_kernel_swi_regs regs;
    7.40 +	_kernel_oserror *error;
    7.41  	int window_data[23];
    7.42      int	*window_block = window_data+1;
    7.43  	int x = ((this->hidden->screen_width << this->hidden->xeig) - (surface->w << 1)) / 2;
    7.44 @@ -255,7 +253,8 @@
    7.45     regs.r[1] = (unsigned int)(window_block);
    7.46     
    7.47     /* Create the window */
    7.48 -   if (_kernel_swi(Wimp_CreateWindow, &regs, &regs) == NULL)
    7.49 +   error = _kernel_swi(Wimp_CreateWindow, &regs, &regs);
    7.50 +   if (error == NULL)
    7.51     {
    7.52  	   this->hidden->window_handle = window_data[0] = regs.r[0];
    7.53  
    7.54 @@ -268,8 +267,10 @@
    7.55         {
    7.56  		  WIMP_DeleteWindow(this);
    7.57  	   }
    7.58 +   } else {
    7.59 +       SDL_SetError("Unable to create window: %s (%i)", error->errmess, error->errnum);
    7.60     }
    7.61 -   
    7.62 +
    7.63     return this->hidden->window_handle;
    7.64  }
    7.65