Mantis - tweak
Viewing Issue Advanced Details
49 major always 07-29-04 23:40 07-30-04 04:04
sriggins  
andreas  
normal  
resolved  
no change required  
none    
none  
0000049: Adding scripts via a class method fails
We were making a convenience method for bug 47 and ran into another bug. In the class, we call self new demoBug

the buttons are made, but the scripts are never wired up properly
CObject subclass: #ClassToTrigger
    instanceVariableNames: '<?xml version="1.0"?><fields></fields>'
    classVariableNames: ''
    poolDictionaries: ''
    category: 'scriptBug20040729'!
!ClassToTrigger commentStamp: 'Rik 7/29/2004 13:53' prior: 0!
ClassToTrigger demoBug!


!ClassToTrigger methodsFor: 'script' stamp: 'Rik 7/29/2004 13:59'!
onBoo
self halt.
    Transcript show: 'Boo'; crFlush! !


!ClassToTrigger methodsFor: 'demoBug' stamp: 'swr 7/29/2004 12:32'!
demoBug

    | pushButton |

    "This looks like we cannot have more than one handler of a script"
    "Both of these buttons should trigger the onBoo method but they do not"

    pushButton := CPushButton open.
    pushButton label: 'First trigger'.
    pushButton origin: 100@100. />     self runScript: #onBoo when: {pushButton. #fire}.

    pushButton := CPushButton open.
    pushButton label: 'Second trigger'.
    pushButton origin:
200@100. />     self runScript: #onBoo when: {pushButton. #fire}.

! !


"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

ClassToTrigger class
    instanceVariableNames: ''!


!ClassToTrigger class methodsFor: 'instance creation' stamp: 'Rik 7/29/2004 14:14'!
demoBug
    | ctt |
    ctt _ self new.
    ctt demoBug

"
If you copy these two lines into a workspace
and DoIt, the buttons open and the second one triggers the bug.
    ctt _ self new.
    ctt demoBug

But for reasons as yet unknown, diong the following in a tweak workspace does NTO work:
    ClassToTrigger demoBug
The buttons open, but neither triggers.


"! !

Notes
(0000036)
andreas   
07-30-04 04:04   
The object gets garbage collected before the scripts can ever be triggered. The signaler of an event (in this case the pushButton) does NOT hold strongly onto the owner of a script (ClassToTrigger) so that it can be individually GCed.

Change the example below into:

ClassToTrigger class>>demoBug
  | ctt |
  ctt := self new.
  ctt demoBug.
  ^ctt

and then from a workspace use

  foo := ClassToTrigger demoBug.

to see that everything works precisely the way it worked before (the workspace will hold onto the foo binding which prevents GCing it here).