openbsd-ports/emulators/zsnes/patches/patch-src_linux_sdllink_c
wcobb 03b58b1dfa - don't crash if there is no available video device.
- check the return value of SDL calls.
2002-08-31 04:19:14 +00:00

106 lines
3.4 KiB
Plaintext

$OpenBSD: patch-src_linux_sdllink_c,v 1.1 2002/08/31 04:19:14 wcobb Exp $
--- src/linux/sdllink.c.orig Sat Aug 31 01:01:05 2002
+++ src/linux/sdllink.c Sat Aug 31 01:11:38 2002
@@ -350,14 +350,24 @@ int Main_Proc(void)
if(cvidmode != 16) {
surface = SDL_SetVideoMode(WindowWidth, WindowHeight,
BitDepth, surface->flags & ~SDL_RESIZABLE);
- adjustMouseXScale();
- adjustMouseYScale();
+ if (surface == NULL) {
+ printf("SDL_SetVideoMode: %s\n",
+ SDL_GetError());
+ break;
+ }
+ adjustMouseXScale();
+ adjustMouseYScale();
break;
}
WindowWidth = SurfaceX = event.resize.w;
WindowHeight = SurfaceY = event.resize.h;
surface = SDL_SetVideoMode(WindowWidth,
WindowHeight, BitDepth, surface->flags);
+ if (surface == NULL) {
+ printf("SDL_SetVideoMode: %s\n",
+ SDL_GetError());
+ break;
+ }
adjustMouseXScale();
adjustMouseYScale();
glViewport(0,0, WindowWidth, WindowHeight);
@@ -526,7 +536,7 @@ int InitSound(void)
if (SDL_OpenAudio(&wanted, NULL) < 0)
{
- fprintf(stderr, "Sound init failed!\n");
+ fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError());
fprintf(stderr, "freq: %d, channels: %d, samples: %d\n",
wanted.freq, wanted.channels, wanted.samples);
SoundEnabled = 0;
@@ -552,7 +562,10 @@ BOOL InitJoystickInput(void)
// If it is possible to use SDL_NumJoysticks
// before initialising SDL_INIT_JOYSTICK then
// this call can be replaced with SDL_InitSubSystem
- SDL_InitSubSystem (SDL_INIT_JOYSTICK);
+ if (SDL_InitSubSystem (SDL_INIT_JOYSTICK) != 0) {
+ printf("SDL_InitSubSystem: %s\n", SDL_GetError());
+ return FALSE;
+ }
max_num_joysticks = SDL_NumJoysticks();
if (!max_num_joysticks)
{
@@ -566,6 +579,10 @@ BOOL InitJoystickInput(void)
for (i = 0; i < max_num_joysticks; i++)
{
JoystickInput[i] = SDL_JoystickOpen(i);
+ if (JoystickInput[i] == NULL) {
+ printf("SDL_JoystickOpen[%d]: %s\n", i, SDL_GetError());
+ return FALSE;
+ }
printf("Joystick %i (%i Buttons): %s\n", i,
SDL_JoystickNumButtons(JoystickInput[i]),
SDL_JoystickName(i));
@@ -584,7 +601,11 @@ int saybitdepth()
{
int MyBitsPerPixel;
const SDL_VideoInfo *info;
- SDL_Init(SDL_INIT_VIDEO);
+
+ if (SDL_Init(SDL_INIT_VIDEO) != 0) {
+ printf("SDL_INIT_VIDEO: %s\n", SDL_GetError());
+ return FALSE;
+ }
info = SDL_GetVideoInfo();
MyBitsPerPixel = info->vfmt->BitsPerPixel;
switch (MyBitsPerPixel)
@@ -593,7 +614,7 @@ int saybitdepth()
case 16: break;
default: printf("You are running in %d bpp, but ZSNES is forcing 16 bpp.\nYou may experience poor performance and/or crashing.\n\n", MyBitsPerPixel); break;
}
- return 0;
+ return TRUE;
}
int startgame(void)
@@ -605,7 +626,8 @@ int startgame(void)
if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_TIMER |
SDL_INIT_VIDEO) < 0)
{
- fprintf(stderr, "Could not initialize SDL: %s", SDL_GetError());
+ fprintf(stderr, "Could not initialize SDL: %s\n",
+ SDL_GetError());
return FALSE;
}
sdl_state = vid_none;
@@ -614,7 +636,9 @@ int startgame(void)
if (sdl_state == vid_soft) sw_end();
#ifdef __OPENGL__
else if (sdl_state == vid_gl) gl_end();
- saybitdepth();
+ if (saybitdepth() == FALSE) {
+ return FALSE;
+ }
if (UseOpenGL)
{
status = gl_start(WindowWidth, WindowHeight, BitDepth, FullScreen);