[Pharo-dev] Debugging Morphs (was Re: Questions about Athens)

btc at openinworld.com btc at openinworld.com
Fri Nov 1 11:44:01 EDT 2013


kilon alios wrote:
> About the problem to recreate it all it takes is a demo := AthensDemoMorph
> new openInWorld . It opens the morph with the Athens grey box, I save the
> image , close pharo, open pharo which reloads the image automagically and
> BOOM Red Box of Doom :) My other tries also are based on AthensDemoMorph
> since I cant find documentation to do things differently.
>
> So lets get to the questions
>
> 6) Also why there is a Red Box of Doom in the first place ?
>   

See #drawErrorOn: call from...

Morph>>fullDrawOn:
    self visible ifFalse: [^ self].
    (aCanvas isVisible: self fullBounds) ifFalse:[^self]. 
    (self hasProperty: #errorOnDraw) ifTrue:[^self drawErrorOn: aCanvas]. 
    [
      "calls to each Morph's drawing stuff"
    ] on: Error do:
    [:err |
        "Smalltalk at: #morphDebugOnce ifPresent: [ Smalltalk remove: 
#morphDebugOnce. self halt ].
        self setProperty: #errorOnDraw toValue: true.
        self setProperty: #drawError toValue: err freeze.
        ^ self drawErrorOn: aCanvas   
    ]
---------------
In the past I have successfully debugged a morph by adding something 
like the commented line.  Although I can't quite remember if 'self halt' 
is correct.  Perhaps it should be 'err raise'.   Perhaps others with 
more experience of the debugger internals can comment. 

 From a workspace just evaluate 'Smalltalk at: #morphDebugOnce put: 
#anything' before opening the morph. Or if the morph is already open and 
you have a reference theMorph, then you can try 'theMorph setProperty: 
#errorOnDraw toValue: false' to cause the bad morph code to run again.  
You can get a reference to an existing morph by enabling 'Create textual 
references to dropped morphs' from the window menu of a Workspace - then 
from the window menu select 'inspect variables'

Now what would be really interesting is if in place of my commented 
line, the debugging context of the error was serialized using Fuel to a 
variable and then clicking on the red-square-of-death brought up a 
debugger on that.  Something like this...

Morph>>fullDrawOn:
    self visible ifFalse: [^ self].
    (aCanvas isVisible: self fullBounds) ifFalse:[^self]. 
    (self hasProperty: #errorOnDraw) ifTrue:[^self drawErrorOn: aCanvas 
debugOn: (self property: #drawError) ]. 
    [
      "calls to each Morph's drawing stuff"
    ] on: Error do:
    [:err |
        self setProperty: #errorOnDraw toValue: true.
        self setProperty: #drawError toValue: (Fuel 
serializedDebuggingContextOf: err.  "***".
        ^ self drawErrorOn: aCanvas   
    ]
"*** Disclaimer: I haven't used Fuel yet, so I don't have the faintest 
idea what the proper method here should be."

> 7) Why the debugger is not triggered as it should be ?
>   

Because Morph>>fullDrawOn: is called many times a second.  You would end 
up with dozens of debuggers coming up faster than you can respond.

> 8) Is that critical a failure of Morphic ?
>   

Its an error in the drawing code of that particular morph.

cheers -ben






More information about the Pharo-dev mailing list