Skip site navigation (1)Skip section navigation (2)
Date:      Tue,  8 Nov 2005 20:45:05 +0100 (CET)
From:      Jean-Yves Lefort <jylefort@FreeBSD.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Cc:        krion@FreeBSD.org
Subject:   ports/88685: Update port: devel/sdl12 (fix multiple PC joystick support)
Message-ID:  <20051108194505.0030EC159@jsite.lefort.net>
Resent-Message-ID: <200511081950.jA8JoD6K083749@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         88685
>Category:       ports
>Synopsis:       Update port: devel/sdl12 (fix multiple PC joystick support)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Tue Nov 08 19:50:13 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Jean-Yves Lefort
>Release:        FreeBSD 6.0-RELEASE i386
>Organization:
>Environment:
System: FreeBSD jsite.lefort.net 6.0-RELEASE FreeBSD 6.0-RELEASE #0: Tue Nov 8 17:13:42 CET 2005 jylefort@jsite.lefort.net:/usr/obj/usr/src/sys/JSITE i386
>Description:
If more than one joystick (joy(4), not uhid(4)) is present, a bug [1]
in SDL may cause an event flood, hogging the SDL main loop and
freezing SDL applications.

[1] The joystick axes state is stored in global variables rather than
in the joystick structure, and it therefore conflicts with other
joysticks, causing an event flood because the "has axis moved?" tests
always succeed.
>How-To-Repeat:
>Fix:
diff -ruN /usr/ports/devel/sdl12/Makefile sdl12/Makefile
--- /usr/ports/devel/sdl12/Makefile	Wed Oct 19 13:41:19 2005
+++ sdl12/Makefile	Tue Nov  8 20:27:26 2005
@@ -7,6 +7,7 @@
 
 PORTNAME=	sdl
 PORTVERSION=	1.2.9
+PORTREVISION=	1
 PORTEPOCH=	2
 CATEGORIES=	devel
 MASTER_SITES=	http://www.libsdl.org/release/
diff -ruN /usr/ports/devel/sdl12/files/patch-src_joystick_bsd_SDL__sysjoystick.c sdl12/files/patch-src_joystick_bsd_SDL__sysjoystick.c
--- /usr/ports/devel/sdl12/files/patch-src_joystick_bsd_SDL__sysjoystick.c	Thu Jan  1 01:00:00 1970
+++ sdl12/files/patch-src_joystick_bsd_SDL__sysjoystick.c	Tue Nov  8 20:26:52 2005
@@ -0,0 +1,96 @@
+--- src/joystick/bsd/SDL_sysjoystick.c.orig	Fri Nov 12 22:24:46 2004
++++ src/joystick/bsd/SDL_sysjoystick.c	Tue Nov  8 20:19:38 2005
+@@ -122,6 +122,12 @@
+ 	struct	report_desc *repdesc;
+ 	struct	report inreport;
+ 	int	axis_map[JOYAXE_count];	/* map present JOYAXE_* to 0,1,..*/
++	int	x;
++	int	y;
++	int	xmin;
++	int	ymin;
++	int	xmax;
++	int	ymax;
+ };
+ 
+ static char *joynames[MAX_JOYS];
+@@ -255,6 +261,12 @@
+ 	joy->hwdata = hw;
+ 	hw->fd = fd;
+ 	hw->path = strdup(path);
++	hw->x = 0;
++	hw->y = 0;
++	hw->xmin = 0xffff;
++	hw->ymin = 0xffff;
++	hw->xmax = 0;
++	hw->ymax = 0;
+ 	if (! strncmp(path, "/dev/joy", 8)) {
+ 		hw->type = BSDJOY_JOY;
+ 		joy->naxes = 2;
+@@ -372,43 +384,42 @@
+ 
+ #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+ 	struct joystick gameport;
+-	static int x, y, xmin = 0xffff, ymin = 0xffff, xmax = 0, ymax = 0;
+  
+ 	if (joy->hwdata->type == BSDJOY_JOY) {
+ 		if (read(joy->hwdata->fd, &gameport, sizeof gameport) != sizeof gameport)
+ 			return;
+-		if (abs(x - gameport.x) > 8) {
+-			x = gameport.x;
+-			if (x < xmin) {
+-				xmin = x;
++		if (abs(joy->hwdata->x - gameport.x) > 8) {
++			joy->hwdata->x = gameport.x;
++			if (joy->hwdata->x < joy->hwdata->xmin) {
++				joy->hwdata->xmin = joy->hwdata->x;
+ 			}
+-			if (x > xmax) {
+-				xmax = x;
++			if (joy->hwdata->x > joy->hwdata->xmax) {
++				joy->hwdata->xmax = joy->hwdata->x;
+ 			}
+-			if (xmin == xmax) {
+-				xmin--;
+-				xmax++;
++			if (joy->hwdata->xmin == joy->hwdata->xmax) {
++				joy->hwdata->xmin--;
++				joy->hwdata->xmax++;
+ 			}
+-			v = (Sint32)x;
+-			v -= (xmax + xmin + 1)/2;
+-			v *= 32768/((xmax - xmin + 1)/2);
++			v = (Sint32)joy->hwdata->x;
++			v -= (joy->hwdata->xmax + joy->hwdata->xmin + 1)/2;
++			v *= 32768/((joy->hwdata->xmax - joy->hwdata->xmin + 1)/2);
+ 			SDL_PrivateJoystickAxis(joy, 0, v);
+ 		}
+-		if (abs(y - gameport.y) > 8) {
+-			y = gameport.y;
+-			if (y < ymin) {
+-				ymin = y;
++		if (abs(joy->hwdata->y - gameport.y) > 8) {
++			joy->hwdata->y = gameport.y;
++			if (joy->hwdata->y < joy->hwdata->ymin) {
++				joy->hwdata->ymin = joy->hwdata->y;
+ 			}
+-			if (y > ymax) {
+-				ymax = y;
++			if (joy->hwdata->y > joy->hwdata->ymax) {
++				joy->hwdata->ymax = joy->hwdata->y;
+ 			}
+-			if (ymin == ymax) {
+-				ymin--;
+-				ymax++;
++			if (joy->hwdata->ymin == joy->hwdata->ymax) {
++				joy->hwdata->ymin--;
++				joy->hwdata->ymax++;
+ 			}
+-			v = (Sint32)y;
+-			v -= (ymax + ymin + 1)/2;
+-			v *= 32768/((ymax - ymin + 1)/2);
++			v = (Sint32)joy->hwdata->y;
++			v -= (joy->hwdata->ymax + joy->hwdata->ymin + 1)/2;
++			v *= 32768/((joy->hwdata->ymax - joy->hwdata->ymin + 1)/2);
+ 			SDL_PrivateJoystickAxis(joy, 1, v);
+ 		}
+ 		if (gameport.b1 != joy->buttons[0]) {
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051108194505.0030EC159>