failing MOUSE EVENTS suggest the end...

BlitzMax Forums/BlitzMax Programming/failing MOUSE EVENTS suggest the end...

Taron(Posted 2008) [#1]
Funky problem in the code that causes all events to fail except timerticks.

MOUSE EVENTS get totally skipped under certain circumstances. Can Event cases hang?

There is a decent chance the somehow one of the other EVENTS basically won't let go anymore. In my case the TIMERTICK appears to be the only event being triggered anymore.

Here's the pseudo for it:
========================================
----------------
checking = 0
----------------
Myhook
- events
- mouse up
checking=0

- mouse down
checking=1

- mouse move
- windowsize
- ...
- timertick
redraw()
-----------------

REDRAW
if checking then do stuff
========================================

This is the coarsest version of the pseudo, but it at least explains what happens. a variable (checking) is controlling whether something happens or not during timerticks. Mouse down sets it, mouse up clears it.

Tracked down the cause, but still can't explain it... could a math operation overrun datatype boundaries? Let's say you have a float which reads a memory address accessed by bytes (yes, you've guessed it! Sound!), but a math operation as simple as X:+(A-B)*C accumulates in it. How could this lead to a totally bizarre hang that doesn't crash, but simply stops all events from being triggered EXCEPT the timer, which then still runs through the program, perfectly executing it?!

For now it's merely a curiosity (after my initial nervous breakdown!). Thanks for any thoughts on it, though...


tonyg(Posted 2008) [#2]
You might want to post a runnable example which shows the problem.


plash(Posted 2008) [#3]
How are you checking for mouse events? Your using a canvas, yes?




plash(Posted 2008) [#4]
Oh ya.. and you should check/post snippets where you are (if you are) changing the checking variable anywhere else then mouseup and mousedown.


Volker(Posted 2008) [#5]
"Therefore, hook functions should generally return the data parameter when finished. "
I once got in problems without doing that.
Do all your hook functions do that (at least return Null)?


Taron(Posted 2008) [#6]
Errrrr....I've tracked down exactly where the problem somehow gets created, which is in my filter routine. I yet don't know how or why, but when a multiplier goes negative it does something that appearantly corrupts the system somehow. I put a check there and that seems to have solved it... (blush) ...but I still don't get it.

Well, thanks, Tony! I was just about to prepare the source for sharing it here, hehe, which made me have yet another look at the whole flow. I've worked on that section for quite a bit and found there to be a relation, but that it was virtually just one stupid little thing that set something so inexplicable in motion is rather...uhm... revelating.

Well, so it's my ignorance and stupidity that is suggesting the end, LOL!
Now I've used up a perfectly dramatic post subject to get some attention for nothin'... there goes the CRY WOLF thingy, while it's still a mystery what happens there?! I mean, it ain't crashing, it just hangs, but nowhere near where someone would've guessed!?

I beg for your forgiveness...


plash(Posted 2008) [#7]
Maybe when you release your code someone will stumble onto it :)


Taron(Posted 2008) [#8]
OH CRAP, hahaha... 5 minutes altering the post to be more accurate and all the friendly responses!

YEAH, I think it's related to the hook, which somehow allows for such things to happen. Otherwise I'm sure the things would've just stalled altogether. Fascinating indeed!

Well, when I'm done, I will share the fruit of it with all of you and I'm just perfectly sure you'll have a riot! It's too much fun and good for everyone, I think. A free mono synth of a different kind, but for the controlfreak! 8)

Anyway, THANKS all of you! I'm sure it's a bad way of introducing myself, but I sure as hell appreciate your wonderful response! I will try my best not to abuse it anymore... but you may be able to tell that I was rather desperate! How can 2 days go by with me going crazy and when I'm about to post it I just find a solution..... another mystery!?

Again, I apologize, but it's still an interesting problem!


Taron(Posted 2008) [#9]
By the way, yes, I'm using a canvas! But the problem originated deep within the redraw code...

Here's my hook routine(SIMPLIFIED)...(with some added prints for "debugging" quickly)


Function MyHook:Object(iId:Int,tData:Object,tContext:Object)
	Local Event:TEvent=TEvent(tData)
	Local i:Int = 0
	'Print " ----------------FIRST HOOK CALL "
	If event=Null Return Null
	Select Event.ID
		Case EVENT_MOUSEUP
			Print "mouse UP >>>>>>>"
			marker_value_dragging = 0
			screwed = 0
		Case EVENT_MOUSEDOWN
			Print "mouse DOWN < < < <"
			If event.y > 60
				If Event.data = 1 Then dragging= 1
				mx = Event.x
			Else If event.y > 40
				If Event.data = 2 Then marker_value_dragging = 1
			Else If event.y>20
				If Event.data = 2 Then marker_value_dragging = 1
			Else
				If Event.data = 2 Then marker_value_dragging = 1
			EndIf
		Case EVENT_MOUSEMOVE
			centerx = Event.x
			centery = Event.y
			centerxr = start+Event.x/msclx
			centeryr = Event.y/mscly
			If dragging
				moffx:+(mx-Event.x)/msclx
				moffy:-(my-Event.y)
			EndIf
			If marker_value_dragging
				marker_value:+(my-Event.y)/(mscly*10000)
			EndIf
			mx = Event.x
			my = Event.y
		Case EVENT_MOUSEUP
			dragging = 0
		Case EVENT_WINDOWSIZE
			Redraw()
		Case EVENT_WINDOWMOVE 
			Redraw()
		Case EVENT_AppResume
			Redraw()
		Case EVENT_TIMERTICK
			If marker_value_dragging Then Print "TimerTick...value dragging"+screwed
			Redraw()
	EndSelect
	Return tData
End Function

AddHook EmitEventHook , MyHook



BUT The real problem happened in a bit of accumulative math called from within the Redraw segment. The problem looks like this:

Local AnyArray:Short[100]

Local DOOM_WHEN_TINY_BIT_NEGATIVE = 0.0001e-044 'MUHAHahahrrrrr..shite!
Local parameter:Float = 0.60
Local accum_A:Float = 0
Local accum_B:Float = 0
Local data:Float = 0
Local dataPtr:Short Ptr = Short Ptr(AnyArray)
For Local i:Int = 0 To 99
   data = Sin(i) ' some irrelevant nonsense 
   accum_B:+ (data-accum_A)*parameter 
   accum_B:- accum_B*DOOM_WHEN_NEGATIVE
   accum_A:+ accum_B
   Print "accum_A:"+accum_A
Next


This will not crash here, but some circumstances will make it produce the funky event hang-up... well... mysterious to me!