[brl.polledinput] Fixed mouse state handling

BlitzMax Forums/BlitzMax Module Tweaks/[brl.polledinput] Fixed mouse state handling

plash(Posted 2010) [#1]
The left/right scroll buttons or toggles on mice (mine happen to be incorporated into the scroll wheel) will cause an unhandled "Attempt to index array beyond array length" exception in brl.polledinput (which is rather misleading, since the event data is actually negative).

I've only tested this fix on Linux, but it should cover any other odd cases as well.
Event data observed: -9 for right-scroll initial, -2 for repeat, and -8 for left-scroll initial, -1 for repeat.

Replace the following cases in the Hook function at line 53 in brl.mod/polledinput.mod/polledinput.bmx:
	Case EVENT_MOUSEDOWN
		If ev.data > -1 And ev.data < 4 And Not mouseStates[ev.data]
			mouseStates[ev.data]=1
			mouseHits[ev.data]:+1
		EndIf
	Case EVENT_MOUSEUP
		If ev.data > -1 And ev.data < 4
			mouseStates[ev.data]=0
		End If


This might call for more range checking on other events, but so far this is the only application-crashing issue I've had to deal with in brl.polledinput.

Last edited 2010