[Pharo-project] curious announcement interaction with halt
My understanding of Announcements is not so good yet, but here is another opportunity. While I was trying to trace some code execution to troubleshoot a ticket that I logged for Mondrian, I bumped into some behaviour that seems strange, which I would like to understand. At the end I propose a fix. For the short example, execute [MOEasel open] then <Generate View> on the following: ----8<---- view shape rectangle size: 20. view interaction registerForEvent: MOMouseDown forNode: #yourself updateNode: [ :v | "self halt." view forNode: v do: [ view nodes: (1 to: 2) ] ] updateLayout: true. view nodes: (1 to: 4). ----8<---- Click on a node and observe that node successfully has two nodes within it. Now uncomment the "self halt" and <Generate View>, then click on a node. When the pre-debugger for 'halt' appears, click <Proceed>. Surprisingly a MNU now occurs in MOAnnouncement>>registerForEvent:forNode:updateNode:updateLayout due to 'ann viewRenderer' now returning nil. Observe this occurs immediately after the execution of 'updateBlock' which contained the 'self halt' The extended example modifies MOAnnouncement>>registerForEvent:forNode:updateNode:updateLayout as follows... | domainNode btcRenderer1 btcRenderer1test btcRenderer2 btcRenderer2test btcRenderer1test2 | self on: eventClass do: [:ann | "----8<---- begin debug code " btcRenderer1 := ann viewRenderer. btcRenderer1test := (self viewRenderer == ann viewRenderer ). "self halt." btcRenderer2 := ann viewRenderer. btcRenderer2test := (self viewRenderer == ann viewRenderer ). { self viewRenderer. btcRenderer1. btcRenderer2. btcRenderer1test. btcRenderer2test. } inspect. "----8<---- end debug code " ann element removeAllEdges; removeAllNodes. <Generate View> on the same code as the short example with the 'self halt' commented out, then click on a node. An inspector pops up showing array { aMOViewRenderer. aMOViewRenderer. aMOViewRenderer. true. true. } Then uncomment the 'self halt' in the extended example, <Generate View> and click on a node. <Proceed> at the pre-debugger. An inspector pops up now showing array { aMOViewRenderer. aMOViewRenderer. nil. true. false. } 'ann viewRenderer ' has lost its value following the 'self halt.' Proposed fix: It can be seen from the second inspector that 'self viewRenderer' is identical to 'ann viewRenderer' and retains its value across the 'self halt', and so might be used in its place. thanks for you attention, your thoughts would be appreciated. cheers, -ben
Hi Ben, Your mail requires a bit more attention span than I can afford right now, and I do not quite understand what the issue actually is. But, this does not mean it went unnoticed :). Cheers, Doru On 9 Apr 2012, at 16:09, Ben Coman wrote:
My understanding of Announcements is not so good yet, but here is another opportunity. While I was trying to trace some code execution to troubleshoot a ticket that I logged for Mondrian, I bumped into some behaviour that seems strange, which I would like to understand. At the end I propose a fix.
For the short example, execute [MOEasel open] then <Generate View> on the following: ----8<---- view shape rectangle size: 20. view interaction registerForEvent: MOMouseDown forNode: #yourself updateNode: [ :v | "self halt." view forNode: v do: [ view nodes: (1 to: 2) ] ] updateLayout: true. view nodes: (1 to: 4). ----8<----
Click on a node and observe that node successfully has two nodes within it.
Now uncomment the "self halt" and <Generate View>, then click on a node. When the pre-debugger for 'halt' appears, click <Proceed>. Surprisingly a MNU now occurs in MOAnnouncement>>registerForEvent:forNode:updateNode:updateLayout due to 'ann viewRenderer' now returning nil. Observe this occurs immediately after the execution of 'updateBlock' which contained the 'self halt'
The extended example modifies MOAnnouncement>>registerForEvent:forNode:updateNode:updateLayout as follows... | domainNode btcRenderer1 btcRenderer1test btcRenderer2 btcRenderer2test btcRenderer1test2 | self on: eventClass do: [:ann | "----8<---- begin debug code " btcRenderer1 := ann viewRenderer. btcRenderer1test := (self viewRenderer == ann viewRenderer ). "self halt." btcRenderer2 := ann viewRenderer. btcRenderer2test := (self viewRenderer == ann viewRenderer ). { self viewRenderer. btcRenderer1. btcRenderer2. btcRenderer1test. btcRenderer2test. } inspect. "----8<---- end debug code " ann element removeAllEdges; removeAllNodes.
<Generate View> on the same code as the short example with the 'self halt' commented out, then click on a node. An inspector pops up showing array { aMOViewRenderer. aMOViewRenderer. aMOViewRenderer. true. true. }
Then uncomment the 'self halt' in the extended example, <Generate View> and click on a node. <Proceed> at the pre-debugger. An inspector pops up now showing array { aMOViewRenderer. aMOViewRenderer. nil. true. false. } 'ann viewRenderer ' has lost its value following the 'self halt.'
Proposed fix: It can be seen from the second inspector that 'self viewRenderer' is identical to 'ann viewRenderer' and retains its value across the 'self halt', and so might be used in its place. thanks for you attention, your thoughts would be appreciated. cheers, -ben
-- www.tudorgirba.com "No matter how many recipes we know, we still value a chef."
'From Pharo1.3 of 16 June 2011 [Latest update: #13315] on 14 April 2012 at 10:21:48 am'! !MOAnnouncer methodsFor: 'convenient interaction' stamp: 'BenComan 4/14/2012 10:14'! registerForEvent: eventClass forNode: aBlockOrSymbol updateNode: updateBlock updateLayout: aBoolean | domainNode btcRenderer1 btcRenderer2test btcRenderer3test btcRenderer2 btcRenderer1test | self on: eventClass do: [:ann | "Execute the following in Mondrian>Easel... view shape rectangle size: 20. view interaction registerForEvent: MOMouseDown forNode: #yourself updateNode: [ :v | view forNode: v do: [ view nodes: (1 to: 2) ] ] updateLayout: true. view nodes: (1 to: 4). ...for case1 when 'self halt' in the debug code below is commented, the 'inspect' shows Array(a MOViewRenderer a MOViewRenderer a MOViewRenderer true true true) ...for case2 when 'self halt' in the debug code below is uncommented, the 'inspect' shows an Array(a MOViewRenderer a MOViewRenderer nil true true false) " "----8<---- debug code begin " btcRenderer1 := ann viewRenderer. btcRenderer1test := ( btcRenderer1 == self viewRenderer ). self halt. "when this line is uncommented for case2, just click <Proceed> at pre-debugger" btcRenderer2 := ann viewRenderer. btcRenderer2test := ( btcRenderer1 == self viewRenderer ). btcRenderer3test := ( btcRenderer1 == btcRenderer2 ). { self viewRenderer. btcRenderer1. btcRenderer2. btcRenderer1test. btcRenderer2test. btcRenderer3test. } inspect. "----8<---- debug code end" "ann element = the MONode" ann element removeAllEdges; removeAllNodes. domainNode := (aBlockOrSymbol moValue: ann element model). ann element resetMetricCachesResursively; resetElementsToLookupUpToTheRoot. ann viewRenderer forNodes: {domainNode} do: updateBlock. aBoolean ifTrue: [ ann viewRenderer root allNodes do: #resetCache. ann viewRenderer root resetElementsToDisplayCacheRecursively. ann element resetCacheInEdges. ann viewRenderer updateWindow. ann viewRenderer root applyLayout] ifFalse: [ ann viewRenderer updateWindow ] ]. ! ! 'From Pharo1.3 of 16 June 2011 [Latest update: #13315] on 14 April 2012 at 10:22:08 am'! !MOAnnouncer methodsFor: 'accessing' stamp: 'BenComan 4/14/2012 10:22'! viewRenderer: anObject "self halt." "to monitor debug case 2, only uncomment this after the mondrian view has been generated but before clicking on a node - not that this halt is not encountered before the one in MOAnnouncer>>registerForEvent:forNode:updateNode:updateLayout:" viewRenderer := anObject! !
participants (2)
-
Ben Coman -
Tudor Girba