Discussion:
Out of context return of value
isjtar
2010-07-12 23:46:41 UTC
Permalink
hello,

another day another problem, well many of them, but this one I can't
quite figure out, so please bear with me.
i've been writing a few classes to store presets by gui. i already ran
into some issues with asynchronous execution, so i guess that's
probably the problem here too.
basically i push a button to store a preset and i want a popup menu in
the same instance to be updated afterwards. the storing happens in a
different object.

so in the gui code i have this (in init)

storeButton = Button(view, Rect(49,7,38,22))
.states_([
["store", Color.white, Color.red]
])
.action_({ |but|
var newItem;
newItem = settings.store; //calls the method in settings
this.presetUpdate(newItem)
});

//this is a method in the same class
presetUpdate{|item|
item.postln // here comes the code to update the menu menu.add etc
}

//here is the method in settings that (unsurprisingly) stores
store{
var path;
Dialog.savePanel({ |dialogPath|
var file;
path = dialogPath;
file = File(path, "w");
file.write(
FloatArray[
playbackrate,
playbackrateRange,
playbackrateMax,
pan,
panRange,
panMax,

]
);
file.close;
"returning " ++ path.asString;
^path // been googling and i understand that i shouldn't return
from a function instead of a method, but I don't see how as the code
ends prematurely
},{
"cancelled".postln;
});

}

it seems i should use block for this, i just wouldn't know how : )

hope it is clear with the code, thought it more clear not to post the
entire classes.

thanks!

isjtar

ps here's the full error

ERROR: 'IsjGrainSettings-store' Out of context return of value: /Users/
isjtar/Code/SuperCollider/IsjtarClasses/isjGrainData/mada
RECEIVER:
Instance of IsjGrainSettings { (15C61750, gc=68, fmt=00, flg=00,
set=06)
instance variables [37]
arrayA : instance of Array (0x15c60210, size=35, set=6)
arrayB : instance of Array (0x15c62c90, size=35, set=6)
playbackrate : Float 3.025751 00000000 400834BD
playbackrateRange : Float 0.300000 40000000 3FD33333
playbackrateMax : Float 3.669528 80000000 400D5B31
pan : Float 0.231760 E0000000 3FCDAA4C
panRange : Float 1.000000 00000000 3FF00000
panMax : Float 0.231760 E0000000 3FCDAA4C
amp : Float 0.864807 80000000 3FEBAC7F
ampRange : Float 0.100000 A0000000 3FB99999
ampMax : Float 0.937768 80000000 3FEE0232
off : Float 0.032189 40000000 3FA07B0E
offRange : Float 1.000000 00000000 3FF00000
offMax : Float 0.182403 E0000000 3FC758FE
buf : Integer 0
buf2 : Integer 2
blend : Float 0.692418 80000000 3FE6284A
blendMax : Float 1.000000 00000000 3FF00000
sus : Float 0.744700 40000000 3FE7D494
susRange : Float 0.090000 80000000 3FB70A3D
susMax : Float 0.834700 E0000000 3FEAB5DB
atk : Float 0.573026 20000000 3FE2563A
atkRange : Float 0.090000 80000000 3FB70A3D
atkMax : Float 0.663026 C0000000 3FE53781
rel : Float 0.405644 60000000 3FD9F611
relRange : Float 0.090000 80000000 3FB70A3D
relMax : Float 0.495644 A0000000 3FDFB8A0
atkCur : Float 0.296137 00000000 3FD2F3EA
atkCurRange : Float 8.000000 00000000 40200000
atkCurMax : Float 0.296137 00000000 3FD2F3EA
relCur : Float 0.244635 C0000000 3FCF5034
relCurRange : Float 8.000000 00000000 40200000
relCurMax : Float 0.244635 C0000000 3FCF5034
deltaTime : Float 0.113811 60000000 3FBD22BA
deltaTimeRange : Float 0.090000 80000000 3FB70A3D
deltaTimeMax : Float 0.236128 60000000 3FCE3970
verbRoom : Float 50.000000 00000000 40490000
}
CALL STACK:
MethodError:reportError 15C42290
arg this = <instance of OutOfContextReturnError>
Nil:handleError 15AFDC40
arg this = nil
arg error = <instance of OutOfContextReturnError>
Thread:handleError 15C40950
arg this = <instance of Thread>
arg error = <instance of OutOfContextReturnError>
Object:throw 15C3FA90
arg this = <instance of OutOfContextReturnError>
Object:outOfContextReturn 15C421D0
arg this = <instance of IsjGrainSettings>
arg method = IsjGrainSettings:store
arg result = "/Users/isjtar/Code/SuperColl..."
< FunctionDef in Method IsjGrainSettings:store > 15C3F5B0
arg dialogPath = "/Users/isjtar/Code/SuperColl..."
var file = <instance of File>
Meta_CocoaDialog:ok 15C40070
arg this = class CocoaDialog
var res = "/Users/isjtar/Code/SuperColl..."
James Harkins
2010-07-13 01:39:04 UTC
Permalink
Post by isjtar
hello,
another day another problem, well many of them, but this one I can't
quite figure out, so please bear with me.
i've been writing a few classes to store presets by gui. i already ran
into some issues with asynchronous execution, so i guess that's
probably the problem here too.
Yes. By the time the code reaches ^path, 'store' has already finished
running. At that point, you can no longer use ^ to pass values back to
the caller.

Methods return synchronously. Using Dialog or some other asynchronous
action does not prevent the method from returning.

The usual way to handle this is to pass a function to that method as an
argument, the same way Buffer:get or Bus:get work.

b = Buffer.read(s, "sounds/a11wlk01.wav");

b.getn(0, 100, *{ |val| val.debug("buffer data") }*);

So you could do something like this.
hjh
Post by isjtar
storeButton = Button(view, Rect(49,7,38,22))
.states_([
["store", Color.white, Color.red]
])
.action_({ |but|
var newItem;
settings.store *{ |path| **this.presetUpdate(path) }*
});
//this is a method in the same class
presetUpdate{|item|
item.postln // here comes the code to update the menu menu.add etc
}
//here is the method in settings that (unsurprisingly) stores
store{ |func|
var path;
Dialog.savePanel({ |dialogPath|
var file;
path = dialogPath;
file = File(path, "w");
file.write(
FloatArray[
playbackrate,
playbackrateRange,
playbackrateMax,
pan,
panRange,
panMax,
]
);
file.close;
*func.value(path)*
},{
"cancelled".postln;
});
}
--
James Harkins /// dewdrop world
jamshark70-***@public.gmane.org
http://www.dewdrop-world.net

"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal." -- Whitman

blog: http://www.dewdrop-world.net/words
audio clips: http://www.dewdrop-world.net/audio
more audio: http://soundcloud.com/dewdrop_world/tracks
Continue reading on narkive:
Loading...