musikinformatik / SuperDirt

Tidal Audio Engine
GNU General Public License v2.0
524 stars 76 forks source link

startup code works with 1.7.2, fails with 1.7.3 #266

Closed ahihi closed 2 years ago

ahihi commented 2 years ago

i'm using supercollider 3.12.2 on macos 10.14. the following is a simplified version of my startup code:

(
s = Server.local;
s.options.sampleRate_(44100);
s.options.memSize = 1024 * 1024;
s.options.numBuffers = 1024 * 256;
s.options.numWireBufs = 128;
s.options.maxNodes = 1024 * 32;
s.latency_(0.205);
s.newBusAllocators;

~makeDirt = {
    var dirt;
    dirt = SuperDirt(2, s);
    dirt.loadSoundFiles;
    dirt.loadSoundFiles(Platform.userHomeDir +/+ "SyncBig/sc/dirt/samples/*");
    [1, dirt].postln;
    dirt;
};

s.waitForBoot {
    ~dirt = ~makeDirt.();
    [2, ~dirt].postln;

    s.sync;

    ~dirt.start(outBusses: 0 ! 12);
};
)

this works fine with SuperDirt 1.7.2, but fails with 1.7.3:

compiling class library...
    Found 855 primitives.
    Compiling directory '/Applications/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary'
AVDCreateGPUAccelerator: Error loading GPU renderer
    Compiling directory '/Users/ahihi/Library/Application Support/SuperCollider/Extensions'
    Compiling directory '/Users/ahihi/Library/Application Support/SuperCollider/downloaded-quarks/Vowel'
    Compiling directory '/Users/ahihi/Library/Application Support/SuperCollider/downloaded-quarks/Dirt-Samples'
    Compiling directory '/Users/ahihi/Library/Application Support/SuperCollider/downloaded-quarks/SuperDirt'
    numentries = 1369963 / 24021700 = 0.057
    6725 method selectors, 3572 classes
    method table size 23519544 bytes, big table size 192173600
    Number of Symbols 17061
    Byte Code Size 527730
    compiled 649 files in 2.22 seconds

Info: 3 methods are currently overwritten by extensions. To see which, execute:
MethodOverride.printAll

compile done
localhost : setting clientID to 0.
internal : setting clientID to 0.
Emacs: Initializing lisp interface.
Class tree inited in 0.03 seconds

*** Welcome to SuperCollider 3.12.2. *** For help type C-c C-y.
Emacs: Index help topics in 1.08 seconds
Emacs: Built symbol table in 0.0421 seconds
server 'localhost' unresponsive, rebooting ...
'/quit' message sent to server 'localhost'.
-> localhost
Booting server 'localhost' on address 127.0.0.1:57110.
VSTPlugin 0.4.2
Found 0 LADSPA plugins
Number of Devices: 13
   0 : "Scarlett 6i6 USB"
   1 : "BlackHole 32ch"
   2 : "Digital-out (HDMI)"
   3 : "Digital-out (HDMI)"
   4 : "Digital-out (HDMI)"
   5 : "Digital-out (HDMI)"
   6 : "Line-in (Blue Rear)"
   7 : "SPDIF-in (White Rear)"
   8 : "Speaker (Unknown)"
   9 : "Headphones (Green Front)"
   10 : "Line-out (Green Rear)"
   11 : "SPDIF-out (White Rear)"
   12 : "Scarlett+BlackHole"

"Scarlett 6i6 USB" Input Device
   Streams: 1
      0  channels 6

"Scarlett 6i6 USB" Output Device
   Streams: 1
      0  channels 12

SC_AudioDriver: sample rate = 44100.000000, driver's block size = 512
SuperCollider 3 server ready.
Requested notification messages from server 'localhost'
localhost: server process's maxLogins (1) matches with my options.
localhost: keeping clientID (0) as confirmed by server process.
Shared memory server interface initialized
loading synthdefs in /Users/ahihi/Library/Application Support/SuperCollider/downloaded-quarks/SuperDirt/classes/../synths/core-modules.scd
---- core synth defs loaded ----
loading synthdefs in /Users/ahihi/Library/Application Support/SuperCollider/downloaded-quarks/SuperDirt/classes/../synths/core-synths-global.scd
loading synthdefs in /Users/ahihi/Library/Application Support/SuperCollider/downloaded-quarks/SuperDirt/classes/../synths/core-synths.scd
loading synthdefs in /Users/ahihi/Library/Application Support/SuperCollider/downloaded-quarks/SuperDirt/classes/../synths/default-synths.scd
loading synthdefs in /Users/ahihi/Library/Application Support/SuperCollider/downloaded-quarks/SuperDirt/classes/../synths/try-load-extra-synths.scd
loading synthdefs in /Users/ahihi/Library/Application Support/SuperCollider/downloaded-quarks/SuperDirt/classes/../synths/tutorial-synths.scd
loading synthdefs in /Users/ahihi/Library/Application Support/SuperCollider/downloaded-quarks/SuperDirt/classes/../synths/zzzzz-core-modules-that-come-last.scd

217 existing sample banks:
808 (6) 808bd (25) 808cy (25) 808hc (5) 808ht (5) 808lc (5) 808lt (5) 808mc (5) 808mt (5) 808oh (5) 808sd (25) 909 (1) ab (12) ade (10) ades2 (9) ades3 (7) ades4 (6) alex (2) alphabet (26) amencutup (32) armora (7) arp (2) arpy (11) auto (11) baa (7) baa2 (7) bass (4) bass0 (3) bass1 (30) bass2 (5) bass3 (11) bassdm (24) bassfoo (3) battles (2) bd (24) bend (4) bev (2) bin (2) birds (10) birds3 (19) bleep (13) blip (2) blue (2) bottle (13) breaks125 (2) breaks152 (1) breaks157 (1) breaks165 (1) breath (1) bubble (8) can (14) casio (3) cb (1) cc (6) chin (4) circus (3) clak (2) click (4) clubkick (5) co (4) coins (1) control (2) cosmicg (15) cp (2) cr (6) crow (4) d (4) db (13) diphone (38) diphone2 (12) dist (16) dork2 (4) dorkbot (2) dr (42) dr2 (6) dr55 (4) dr_few (8) drum (6) drumtraks (13) e (8) east (9) electro1 (13) em2 (6) erk (1) f (1) feel (7) feelfx (8) fest (1) fire (1) flick (17) fm (17) foo (27) future (17) gab (10) gabba (4) gabbaloud (4) gabbalouder (4) glasstap (3) glitch (8) glitch2 (8) gretsch (24) gtr (3) h (7) hand (17) hardcore (12) hardkick (6) haw (6) hc (6) hh (13) hh27 (13) hit (6) hmm (1) ho (6) hoover (6) house (8) ht (16) if (5) ifdrums (3) incoming (8) industrial (32) insect (3) invaders (18) jazz (8) jungbass (20) jungle (13) juno (12) jvbass (13) kicklinn (1) koy (2) kurt (7) latibro (8) led (1) less (4) lighter (33) linnhats (6) lt (16) made (7) made2 (1) mash (2) mash2 (4) metal (10) miniyeah (4) monsterb (6) moog (7) mouth (15) mp3 (4) msg (9) mt (16) mute (28) newnotes (15) noise (1) noise2 (8) notes (15) numbers (9) oc (4) odx (15) off (1) outdoor (6) pad (3) padlong (1) pebbles (1) perc (6) peri (15) pluck (17) popkick (10) print (11) proc (2) procshort (8) psr (30) rave (8) rave2 (4) ravemono (2) realclaps (4) reverbkick (1) rm (2) rs (1) sax (22) sd (2) seawolf (3) sequential (8) sf (18) sheffield (1) short (5) sid (12) sine (6) sitar (8) sn (52) space (18) speakspell (12) speech (7) speechless (10) speedupdown (9) stab (23) stomp (10) subroc3d (11) sugar (2) sundance (6) tabla (26) tabla2 (46) tablex (3) tacscan (22) tech (13) techno (7) tink (5) tok (4) toys (13) trump (11) ul (10) ulgab (5) uxay (3) v (6) voodoo (5) wind (10) wobble (1) world (3) xmas (1) yeah (31) 
... file reading complete. Required 444 MB of memory.

16 existing sample banks:
em (1) flbass (9) haly (1) henki (1) kapysym (41) lelclap (14) 
WARNING: File reading failed for path: '/Users/ahihi/SyncBig/sc/dirt/samples/nab/narayanbreikki-129.wav'

nab (128) ride (15) sncl (232) sw (50) thesupremekaiya (8) turkuloop (1) tvo (164) uela (1) volcakicks (22) weirdbox (4) 
... file reading complete. Required 194 MB of memory.

[ 1, a SuperDirt ]
[ 2, nil ]
WARNING: keyword arg 'outBusses' not found in call to Object:doesNotUnderstand
ERROR: Message 'start' not understood.
RECEIVER:
   nil
ARGS:
PATH: /Users/ahihi/SyncBig/pulu/uforave/dirttest.scd

PROTECTED CALL STACK:
    Meta_MethodError:new    0x118f9eec0
        arg this = DoesNotUnderstandError
        arg what = nil
        arg receiver = nil
    Meta_DoesNotUnderstandError:new 0x118fa1200
        arg this = DoesNotUnderstandError
        arg receiver = nil
        arg selector = start
        arg args = [  ]
    Object:doesNotUnderstand    0x11859c840
        arg this = nil
        arg selector = start
        arg args = nil
    Routine:prStart 0x1199a8000
        arg this = a Routine
        arg inval = 11.015196905

CALL STACK:
    DoesNotUnderstandError:reportError
        arg this = <instance of DoesNotUnderstandError>
    < closed FunctionDef >
        arg error = <instance of DoesNotUnderstandError>
    Integer:forBy
        arg this = 0
        arg endval = 0
        arg stepval = 2
        arg function = <instance of Function>
        var i = 0
        var j = 0
    SequenceableCollection:pairsDo
        arg this = [*2]
        arg function = <instance of Function>
    Scheduler:seconds_
        arg this = <instance of Scheduler>
        arg newSeconds = 17.298521093
    Meta_AppClock:tick
        arg this = <instance of Meta_AppClock>
        var saveClock = <instance of Meta_SystemClock>
    Process:tick
        arg this = <instance of Main>
^^ ERROR: Message 'start' not understood.
RECEIVER: nil

i'm very confused by the debug print output

[ 1, a SuperDirt ]
[ 2, nil ]

which suggests that i have a valid SuperDirt object up until the ~makeDirt function returns, but the return value then somehow becomes nil?

i notice that if i remove the second loadSoundFiles call, the code again works correctly and i get the expected debug output

[ 1, a SuperDirt ]
[ 2, a SuperDirt ]

any idea what's going on?

ahihi commented 2 years ago

ok, i got a little suspicious about the single broken WAV i have in my library, pointed out in the message:

WARNING: File reading failed for path: '/Users/ahihi/SyncBig/sc/dirt/samples/nab/narayanbreikki-129.wav'

i removed it, and sure enough, the code now works as expected... i still don't understand why or how it fails completely on what should be just a warning though. maybe memory corruption?

in case anyone wants to experiment with this, the broken file is available here: https://owo.uwu.fi/narayanbreikki-129.wav

telephon commented 2 years ago

The error message is really strange indeed, I also don't understand how ~dirt could become nil as a buffer loading fails. I wonder if it would be better to really throw errors when something like file reading goes wrong, instead of just warning. @yaxu what do you think?

ahihi commented 2 years ago

i am trying to add some of my own WAV metadata parsing to latest develop and seeing this weird behavior again - SuperDirt object looks fine inside the function that sets it up, but becomes nil when returned to the caller. im at a complete loss on how to debug this..

telephon commented 2 years ago

SuperDirt object looks fine inside the function that sets it up, but becomes nil when returned to the caller.

You mean after your set up, ~dirt == nil?

ahihi commented 2 years ago

yes, very similar situation to the original post. in fact i noticed i had a new invalid wav file in my library and that was again causing the problem.

so i looked into the error handling a bit and after a lot of confusing experimentation i noticed that this line in readWithInfo probably should be prefixed with a ^? it seems the intention is to return nil on failure, but the current code returns a Buffer with nil members which has just been freed. this sus buffer passes the notNil check and i guess something breaks down the line.

i added that ^ and now the ~dirt returned by my function looks fine even with the invalid file causing a read fail warning! (i prefer this behavior over throwing)

also, this try seems wrong (no catch function, tryed function takes an error arg?) but im not sure whether it affects any of the above.

anyway, yay progress! :) i can test a bit more and make a PR later this week.