(svn r14641) -Change [Allegro]: when making a debug build revert Allegro's hooks on SIGSEGV/SIGABRT so one can actually use gdb.
authorrubidium
Sat, 29 Nov 2008 01:28:13 +0000
changeset 10390 0c2cc4c7b91f
parent 10389 05465e8a465c
child 10391 8c1d42c0818d
(svn r14641) -Change [Allegro]: when making a debug build revert Allegro's hooks on SIGSEGV/SIGABRT so one can actually use gdb.
-Change: make it more clear that Allegro's failing to find a driver.
src/video/allegro_v.cpp
src/video/sdl_v.cpp
--- a/src/video/allegro_v.cpp	Fri Nov 28 18:47:49 2008 +0000
+++ b/src/video/allegro_v.cpp	Sat Nov 29 01:28:13 2008 +0000
@@ -20,6 +20,12 @@
 #include "allegro_v.h"
 #include <allegro.h>
 
+#ifdef _DEBUG
+/* Allegro replaces SEGV/ABRT signals meaning that the debugger will never
+ * be triggered, so rereplace the signals and make the debugger userful. */
+#include <signal.h>
+#endif
+
 static FVideoDriver_Allegro iFVideoDriver_Allegro;
 
 static BITMAP *_allegro_screen;
@@ -154,6 +160,9 @@
 
 static void GetAvailableVideoMode(int *w, int *h)
 {
+	/* No video modes, so just try it and see where it ends */
+	if (_num_resolutions == 0) return;
+
 	/* is the wanted mode among the available modes? */
 	for (int i = 0; i != _num_resolutions; i++) {
 		if (*w == _resolutions[i].width && *h == _resolutions[i].height) return;
@@ -179,21 +188,23 @@
 	if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals");
 	set_color_depth(bpp);
 
-#if defined(DOS)
-	/* Force DOS builds to ALWAYS use full screen as
-	 * it can't do windowed. */
-	_fullscreen = true;
-#endif
+	GetAvailableVideoMode(&w, &h);
+	if (set_gfx_mode(_fullscreen ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, w, h, 0, 0) != 0) {
+		DEBUG(driver, 0, "Allegro: Couldn't allocate a window to draw on");
+		return false;
+	}
 
-	GetVideoModes();
-	GetAvailableVideoMode(&w, &h);
-	if (set_gfx_mode(_fullscreen ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, w, h, 0, 0) != 0) return false;
+	/* The size of the screen might be bigger than the part we can actually draw on!
+	 * So calculate the size based on the top, bottom, left and right */
+	_allegro_screen = create_bitmap_ex(bpp, screen->cr - screen->cl, screen->cb - screen->ct);
+	_screen.width = _allegro_screen->w;
+	_screen.height = _allegro_screen->h;
+	_screen.pitch = ((byte*)screen->line[1] - (byte*)screen->line[0]) / (bpp / 8);
 
-	_allegro_screen = create_bitmap(w, h);
-	_screen.width = w;
-	_screen.height = h;
-	_screen.pitch = ((byte*)screen->line[1] - (byte*)screen->line[0]) / (bitmap_color_depth(screen) / 8);
+	/* Initialise the screen so we don't blit garbage to the screen */
+	memset(_allegro_screen->line[0], 0, _screen.height * _screen.pitch);
 
+	/* Set the mouse at the place where we expect it */
 	poll_mouse();
 	_cursor.pos.x = mouse_x;
 	_cursor.pos.y = mouse_y;
@@ -393,6 +404,20 @@
 	install_mouse();
 	install_keyboard();
 
+#if defined _DEBUG
+/* Allegro replaces SEGV/ABRT signals meaning that the debugger will never
+ * be triggered, so rereplace the signals and make the debugger userful. */
+	signal(SIGABRT, NULL);
+	signal(SIGSEGV, NULL);
+#endif
+
+#if defined(DOS)
+	/* Force DOS builds to ALWAYS use full screen as
+	 * it can't do windowed. */
+	_fullscreen = true;
+#endif
+
+	GetVideoModes();
 	CreateMainSurface(_cur_resolution.width, _cur_resolution.height);
 	MarkWholeScreenDirty();
 	set_close_button_callback(HandleExitGameRequest);
--- a/src/video/sdl_v.cpp	Fri Nov 28 18:47:49 2008 +0000
+++ b/src/video/sdl_v.cpp	Sat Nov 29 01:28:13 2008 +0000
@@ -156,7 +156,7 @@
 	uint delta;
 
 	// all modes available?
-	if (_all_modes) return;
+	if (_all_modes || _num_resolutions == 0) return;
 
 	// is the wanted mode among the available modes?
 	for (i = 0; i != _num_resolutions; i++) {
@@ -213,8 +213,10 @@
 
 	// DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK
 	newscreen = SDL_CALL SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE | SDL_HWPALETTE | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE));
-	if (newscreen == NULL)
+	if (newscreen == NULL) {
+		DEBUG(driver, 0, "SDL: Couldn't allocate a window to draw on");
 		return false;
+	}
 
 	_screen.width = newscreen->w;
 	_screen.height = newscreen->h;