[AD] Change for exmouse to detect mouse |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Hi.
Today I upgraded my mouse to one of those wheel thingies, and playing
with it I discovered that exmouse crashes horribly if there's no mouse or
the devices don't have the correct read permissions, due to deferencing
mouse_driver, which is NULL. Proposed fix.
Index: exmouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/examples/exmouse.c,v
retrieving revision 1.4
diff -u -r1.4 exmouse.c
--- exmouse.c 14 May 2002 11:17:14 -0000 1.4
+++ exmouse.c 18 Sep 2002 20:14:49 -0000
@@ -22,7 +22,6 @@
if (allegro_init() != 0)
return 1;
install_keyboard();
- install_mouse();
install_timer();
if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
@@ -33,6 +32,14 @@
text_mode(makecol(255, 255, 255));
clear_to_color(screen, makecol(255, 255, 255));
+ /* Detect mouse presence */
+ if (install_mouse() < 0) {
+ textout_centre(screen, font, "No mouse detected, but you need one!",
+ SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0));
+ readkey();
+ return 0;
+ }
+
textprintf_centre(screen, font, SCREEN_W/2, 8, makecol(0, 0, 0),
"Driver: %s", mouse_driver->name);