test/testerror.c
author Patrice Mandin <patmandin@gmail.com>
Thu, 19 Jan 2006 21:28:52 +0000
changeset 1257 448a9a64537b
parent 1151 be9c9c8f6d53
child 1659 14717b52abc0
permissions -rw-r--r--
[PATCH] SDL_GetVideoMode() does not find best mode, part 2

Following commit 1.51, I come accross a problem when SDL must choose between
several video modes that could suit the one asked.

If I ask 320x240 with this list:
768x480 768x240 640x400 640x200 384x480 384x240 320x400 320x200

The smallest selectables modes are 384x240 and 320x400. And SDL choose the later
in this list, but 384x240 is more suitable. So I added a check to compare
the pixel count (surface) of modes, and select the one which has the smallest
pixel count.

In my example, 384x240 has 92160 pixels, and 320x400 has 128000 pixels. So now
SDL will choose 384x240 for the asked 320x240 mode.
slouken@0
     1
slouken@0
     2
/* Simple test of the SDL threading code and error handling */
slouken@0
     3
slouken@0
     4
#include <stdio.h>
slouken@0
     5
#include <stdlib.h>
slouken@0
     6
#include <signal.h>
slouken@0
     7
slouken@0
     8
#include "SDL.h"
slouken@0
     9
#include "SDL_thread.h"
slouken@0
    10
slouken@0
    11
static int alive = 0;
slouken@0
    12
icculus@1151
    13
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
icculus@1151
    14
static void quit(int rc)
icculus@1151
    15
{
icculus@1151
    16
	SDL_Quit();
icculus@1151
    17
	exit(rc);
icculus@1151
    18
}
icculus@1151
    19
slouken@0
    20
int ThreadFunc(void *data)
slouken@0
    21
{
slouken@0
    22
	/* Set the child thread error string */
slouken@0
    23
	SDL_SetError("Thread %s (%d) had a problem: %s",
slouken@0
    24
			(char *)data, SDL_ThreadID(), "nevermind");
slouken@0
    25
	while ( alive ) {
slouken@0
    26
		printf("Thread '%s' is alive!\n", (char *)data);
slouken@0
    27
		SDL_Delay(1*1000);
slouken@0
    28
	}
slouken@0
    29
	printf("Child thread error string: %s\n", SDL_GetError());
slouken@0
    30
	return(0);
slouken@0
    31
}
slouken@0
    32
slouken@0
    33
int main(int argc, char *argv[])
slouken@0
    34
{
slouken@0
    35
	SDL_Thread *thread;
slouken@0
    36
slouken@0
    37
	/* Load the SDL library */
slouken@0
    38
	if ( SDL_Init(0) < 0 ) {
slouken@0
    39
		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
icculus@1151
    40
		return(1);
slouken@0
    41
	}
slouken@0
    42
slouken@0
    43
	/* Set the error value for the main thread */
slouken@0
    44
	SDL_SetError("No worries");
slouken@0
    45
slouken@0
    46
	alive = 1;
slouken@0
    47
	thread = SDL_CreateThread(ThreadFunc, "#1");
slouken@0
    48
	if ( thread == NULL ) {
slouken@0
    49
		fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
icculus@1151
    50
		quit(1);
slouken@0
    51
	}
slouken@0
    52
	SDL_Delay(5*1000);
slouken@0
    53
	printf("Waiting for thread #1\n");
slouken@0
    54
	alive = 0;
slouken@0
    55
	SDL_WaitThread(thread, NULL);
slouken@0
    56
slouken@0
    57
	printf("Main thread error string: %s\n", SDL_GetError());
slouken@0
    58
icculus@1151
    59
	SDL_Quit();
slouken@0
    60
	return(0);
slouken@0
    61
}