Error: 'PauseStream-awake'

Hi,

I’m trying to play samples from a dictionary of buffers with this code.

~playbuf = Pbind(\instrument, \playbuf, \speed, 0.9);
(
Pdef(\a, Pseq([
	Pbind(\buf, Prand(~samples[\es][\news],inf), \out, Pseq((..3)), \sampledur, Pfunc{|e| e[\buf].duration}.trace) <> ~playbuf,
	Pbind(\buf, Prand(~samples[\es][\news], 4), \out, (..3), \speed, 0.9) <> ~playbuf,

])).play;
)

Sometimes it works, but more often than not I get this error which I’ve looked up but haven’t found any info, and I don’t have a clue what it means:

ERROR: 'PauseStream-awake' Out of context return of value: a DoesNotUnderstandError
RECEIVER:
Instance of EventStreamPlayer {    (0x56036cc6e6d8, gc=38, fmt=00, flg=00, set=04)
  instance variables [12]
    stream : nil
    originalStream : instance of Routine (0x56036cc682c8, size=28, set=5)
    clock : instance of TempoClock (0x56036a65db68, size=7, set=3)
    nextBeat : nil
    streamHasEnded : true
    isWaiting : false
    era : Integer 0
    rescheduledTime : nil
    event : instance of Event (0x56036da29948, size=5, set=3)
    muteCount : Integer 0
    cleanup : instance of EventStreamCleanup (0x56036d31b7c8, size=1, set=2)
    routine : instance of Routine (0x56036cc2d028, size=28, set=5)
}
CALL STACK:
	MethodError:reportError
		arg this = <instance of OutOfContextReturnError>
	Nil:handleError
		arg this = nil
		arg error = <instance of OutOfContextReturnError>
	Thread:handleError
		arg this = <instance of Thread>
		arg error = <instance of OutOfContextReturnError>
	Object:throw
		arg this = <instance of OutOfContextReturnError>
	Object:outOfContextReturn
		arg this = <instance of EventStreamPlayer>
		arg method = PauseStream:awake
		arg result = <instance of DoesNotUnderstandError>
	PauseStream:awake
		arg this = <instance of EventStreamPlayer>
		arg beats = 664.0
		arg seconds = 664.706888406
		arg inClock = <instance of TempoClock>
^^ The preceding error dump is for ERROR: 'PauseStream-awake' Out of context return of value: a DoesNotUnderstandError
RECEIVER: an EventStreamPlayer

Any hints will be very much appreciated.

I can’t reproduce the error – do you perhaps have some extension installed that overrides core methods?

Now this is interesting… if all else fails, we could try capturing that error and see where the problem begins… change:

	outOfContextReturn { arg method, result;
		OutOfContextReturnError(this, method, result).throw;
	}

to

	outOfContextReturn { arg method, result;
		Library.put(\oocResult, result);
		OutOfContextReturnError(this, method, result).throw;
	}

… and recompile the library. Then, when you see the problem again, Library.at(\oocResult).reportError.

EDIT: Thinking further what could cause this… I suspect that somewhere in your class library, there is a method that returns a DoesNotUnderstandError, which would almost certainly be wrong usage. In general, if you’ve gone down a code path where it makes sense to create an Exception/Error object, then that code path has encountered something wrong. In that case, you don’t want to keep going, or go back to the caller (which expects certain work to have been done). You want to interrupt execution at that point, either dumping the stack trace and halting, or calling an exception handler (try / protect). This is .throw.

	goodUseOfException {
		if(somethingBadHappened) {
			Error("Describe the error").throw;
		}
	}

	badUseOfException {
		if(somethingBadHappened) {
			// no! missing `.throw`
			// and then ^ would be superfluous,
			// because the code path will not return back here after throw
			^Error("Describe the error")
		} {
			^returnSomethingGood
		}
	}

If the problematic method had scheduled something, and this scheduled function tried to return an error, then it would produce an out-of-context return error, with the result being the error object.

So, another thing you could do is to type DoesNotUnderstandError into a code window, hit cmd-or-control-U for “uses of,” and check all of those places to make sure they are properly throwing, and not returning.

The core class library uses DoesNotUnderstandError in only two places: Object:doesNotUnderstand, and SCVIewHolder:doesNotUnderstand. Both of these are correct (.throw). So, if you’re seeing that a DoesNotUnderstandError is being returned, then it has to be an extension (i.e. I can’t see any way in which this is a core SC bug – can’t be).

hjh

1 Like

Thanks @jamshark70 . I’ve been looking into this and haven’t found anything yet. I added the Library.put(...) line in outOfContextReturn in Object.sc but still can’t figure out where the problem is. This is the output from Library.at(\oocResult).reportError:


ERROR: nil
CALL STACK:
	Object:reportError
		arg this = nil
	Interpreter:interpretPrintCmdLine
		arg this = <instance of Interpreter>
		var res = nil
		var func = <instance of Function>
		var code = "Library.at(\oocResult).repor..."
		var doc = <instance of ScelDocument>
		var ideClass = nil
	Process:interpretPrintCmdLine
		arg this = <instance of Main>
-> nil

I uninstalled all my extensions and quarks and still get the error. I ran the code on SCIDE on another computer (Mac Mini, I’m on an Arch Linux) and it worked. This is for a commission and I’ll be deploying it on a Mac, so -for now- I need to put this aside. I’ll eventually get back to try to solve this when I’m done. But I thought I’d post this both to remind me where I was, and in case it’s of interest to others.

I very much appreciate your help.

For whenever you come back to this… I don’t see how it could be nil.

The stack trace from your original post shows:

	Object:outOfContextReturn
		arg this = <instance of EventStreamPlayer>
		arg method = PauseStream:awake
		arg result = <instance of DoesNotUnderstandError>

So, when the problem happens, it is definitely going through the outOfContextReturn method, and it’s receiving, as result, a DoesNotUnderstandError. These are known facts (unless the stack trace is inconsistent). If, at this point, you have added Library.put(\oocResult, result); into this specific method, and we know the code is going through this method, and we know that result is not nil, then \oocResult in the global library cannot be nil.

So maybe something went wrong when adding the line?

One way to check is to sniff the method’s byte codes.

Object.findMethod(\outOfContextReturn).dumpByteCodes;

// original
BYTECODES: (9)
  0   00 01    PushClassX 'OutOfContextReturnError'
  2   60       PushSpecialValue this
  3   8E 00     PushAllButFirstTwoArgs+SendSpecialMsg 'new'
  5   A1 00    SendMsg 'throw'
  7   F0       Drop
  8   F4       ReturnSelf

// modified
BYTECODES: (16)
  0   00 00    PushClassX 'Library'
  2   40       PushLiteral Symbol 'oocResult'
  3   32		 PushTempZeroVar 'result'
  4   C3 03    SendSpecialMsg 'put'
  6   F0       Drop
  7   00 02    PushClassX 'OutOfContextReturnError'
  9   60       PushSpecialValue this
 10   8E 00     PushAllButFirstTwoArgs+SendSpecialMsg 'new'
 12   A1 01    SendMsg 'throw'
 14   F0       Drop
 15   F4       ReturnSelf

Or maybe it would be easier to do it as a method override (to avoid problems with write-protected class library files):

+ Object {
	outOfContextReturn { arg method, result;
		Library.put(\oocResult, result);
		OutOfContextReturnError(this, method, result).throw;
	}
}

… and File > Save as extension. (Make sure to remove it later.)

hjh