From jylefort@brutele.be  Tue Nov  8 19:45:09 2005
Return-Path: <jylefort@brutele.be>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 2BA4D16A41F;
	Tue,  8 Nov 2005 19:45:09 +0000 (GMT)
	(envelope-from jylefort@brutele.be)
Received: from 212.68.244.220.brutele.be (212.68.244.220.brutele.be [212.68.244.220])
	by mx1.FreeBSD.org (Postfix) with ESMTP id E7B9943D46;
	Tue,  8 Nov 2005 19:45:07 +0000 (GMT)
	(envelope-from jylefort@brutele.be)
Received: from jsite.lefort.net (jsite.lefort.net [192.168.1.2])
	by gateway.lefort.net (Postfix) with ESMTP id 1342A54CF;
	Tue,  8 Nov 2005 20:45:06 +0100 (CET)
Received: by jsite.lefort.net (Postfix, from userid 1000)
	id 0030EC159; Tue,  8 Nov 2005 20:45:05 +0100 (CET)
Message-Id: <20051108194505.0030EC159@jsite.lefort.net>
Date: Tue,  8 Nov 2005 20:45:05 +0100 (CET)
From: Jean-Yves Lefort <jylefort@FreeBSD.org>
Reply-To: Jean-Yves Lefort <jylefort@FreeBSD.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc: krion@FreeBSD.org
Subject: Update port: devel/sdl12 (fix multiple PC joystick support)
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         88685
>Category:       ports
>Synopsis:       Update port: devel/sdl12 (fix multiple PC joystick support)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    krion
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Tue Nov 08 19:50:13 GMT 2005
>Closed-Date:    Wed Nov 09 21:22:03 GMT 2005
>Last-Modified:  Wed Nov 09 21:22:03 GMT 2005
>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:
Responsible-Changed-From-To: freebsd-ports-bugs->krion 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Tue Nov 8 19:51:20 GMT 2005 
Responsible-Changed-Why:  
Over to maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=88685 
State-Changed-From-To: open->closed 
State-Changed-By: krion 
State-Changed-When: Wed Nov 9 21:22:02 GMT 2005 
State-Changed-Why:  
Committed. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=88685 
>Unformatted:
