[squeak-dev] ActiveEvent/Object>>currentEvent broken by Morphic-mt.1283?

tim Rowledge tim at rowledge.org
Sat Aug 20 01:43:46 UTC 2016


After loading my development scratch code into the rc1 image I got a really weird dNU where an instvar of PaintCanvas is nil a few bytecodes after it is set to definitely-not-nil. The code is pretty simple - 
!PaintCanvas methodsFor: 'event handling' stamp: 'tpr 8/19/2016 18:30'!
selectRectangleStartingAt: aPoint
	"Set selectionRect to a rectangular area starting at the given canvas point."

	| p |
	selectionRect := aPoint extent: 0 at 0.
	showSelection := true.
	World activeHand showTemporaryCursor: nil.
	Cursor crossHair showWhile: [
		[self currentEvent anyButtonPressed] whileTrue: [
			p := self cursorPoint.
			self autoScroll: p.
			self canvasChanged: selectionRect.
			selectionRect := aPoint rect: (self screenToCanvas: p).
			selectionRect := selectionRect intersect: canvasForm boundingBox.
			self canvasChanged: selectionRect.
			World doOneCycle]].
	showSelection := false.
	self changed.
	World displayWorld.

	selectionRect area = 0 ifTrue: [selectionRect := nil].
	^ selectionRect


In PaintCanvas>>selectRectangleStartingAt: we set selectionRect to a rectangle in the first line. On line 8
`self canvasChanged: selectionRect.` 
it appears selectionRect is nil. In the debugger it is indeed nil. I can’t see any path that should make it nil on an initial go-round, so something is wrong in the loop that follows, which spins on `self currentEvent anyButtonPressed`
After sticking some counting code in the loop to see if the problem was happening during the first pass I was startled to see it was more usually occurring after 160-180 loops! And to make life even more interesting with some checking code added before each use of the ‘selectionRect’ ivar it appeared to be getting nilled between the bottom of the loop and the immediately following top. This got me worrying about the vm doing something bad as you might imagine.

However, trying this out in an update #15314 image caused no problems, which at least seems to clear the vm of guilt. After much diffing  of recent updates to Morphic I *think* there must be some interaction between Object>>currentEvent (which uses the ActiveEvent global) and Morphic-mt.1283 changes in HandMorph - purely since they alter the usage of Active Event. The symptom seems to centre around the event not being updated properly.

If I revert the HandMorph>>sendFocusEvent:to:clear: & sendEvent:focus:clear: methods to the versions prior to Morphic-mt.1283 then the PaintCanvas code works as before. The bit that really confuses me is that it seems that more event processing must be going on that invokes PaintCanvas>>mouseDown: *within* the loop above - that’s the only current path I can find to nil the selectionRect ivar. Weird.

There is also some possible confusion in the system between Morph>>cursorPoint, which simply gets the currentHand’s lastEvent cursorPoint, and Object>>currentEvent which gives one either the ActiveEvent global or the currentHand’s lastEvent. Seems to me one or the other is giving wrong info.

tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
CChheecckk yyoouurr dduupplleexx sswwiittcchh..




More information about the Squeak-dev mailing list