Cabbage Logo
Back to Cabbage Site

Strangeness in the output console when the performance ends

Hi, I noticed a strange behaviour in the console output when the performance ends.
For example, if I have the following csd and run it in Cabbage:

<CsoundSynthesizer>
<CsOptions>
-n -d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

instr 1
    ; do nothing
endin

</CsInstruments>
<CsScore>
i1 0 1
</CsScore>
</CsoundSynthesizer>

The output will be:

UnifiedCSD:  C:\Users\Mauro\doNothing.csd
STARTING FILE
Creating options
Creating orchestra
closing tag
Creating score
rtaudio: PortAudio module enabled ...
using callback interface
rtmidi: PortMIDI module enabled
sample rate overrides: esr = 44100.0000, ekr = 1378.1250, ksmps = 32
Elapsed time at end of orchestra compile: real: 0.003s, CPU: 0.003s
sorting score ...
	... done
Elapsed time at end of score sort: real: 0.003s, CPU: 0.003s
displays suppressed
0dBFS level = 1.0
orch now loaded
audio buffered in 4096 sample-frame blocks
SECTION 1:
new alloc for instr 1:
B  0.000 ..  1.000 T  1.000 TT  1.000 M:  0.00000  0.00000
Score finished in csoundPerformKsmps() with 2.
Score finished in csoundPerformKsmps() with 2.
Score finished in csoundPerformKsmps() with 2.
Score finished in csoundPerformKsmps() with 2.
Score finished in csoundPerformKsmps() with 2.
Score finished in csoundPerformKsmps() with 2.
Score finished in csoundPerformKsmps() with 2.
Score finished in csoundPerformKsmps() with 2.
Score finished in csoundPerformKsmps() with 2.
Score finished in csoundPerformKsmps() with 2.
Score finished in csoundPerformKsmps() with 2.
Score finished in csoundPerformKsmps() with 2.

The number of the above “Score finished in csoundPerformKsmps() with 2.” lines is always different at each run. What they mean? Why their number always changes at each execution?
P.S.: I’m on a Windows 10 machine.

I know. It’s kind of annoying. Cabbage keeps polling for messages for a few moments after Csound has stopped. That’s where this comes from. I will see if I can tidy it up.

Thanks. Could this be related to the reason why sometimes Cabbage randomly crashes on my system after you stop and restart a (big) csd file?
When it happens, I wish there could be a logfile or an external console output that could give me an hint on why Cabbage crashed… I tried to launch the Cabbage executable from a command line (in Windows), but it shows nothing after Cabbage crashes.

I wish it was that clear :joy: Random crashes are most likely caused my memory issues between Cabbage and Csound. I had a workaround for a while that seemed to prevent these crashes. I’ll look into putting back in until I find a better solution.

[quote=“rorywalsh, post:4, topic:1202”]
I had a workaround for a while that seemed to prevent these crashes. I’ll look into putting back in until I find a better solution.
[/quote]I would be very glad to try it… :slight_smile:

Try this. Unzip this .exe into the Cabbage root directory. Then try to crash Cabbage again. Best would be if you can consistently crash it! The reason I haven’t included this fail-safe is that is slows down loading instruments. On the other hand, if it stops crashing I guess I should consider packaging it along side the main application.

CsoundTest.zip (24.5 KB)

I tried it but, unfortunately, the random crashes are always there…
I don’t know if this could help you, but I found a little code that ALWAYS crashes Cabbage:

instr 1
  iMakeMeCrash = 1 / 0
endin

I know that a divide by zero is horribly wrong, but, ideally, Cabbage should return a gentle message in the console output like: “YOU FOOL!! HOW YOU DARE DIVIDE BY ZERO??? ARE YOU CRAZY OR WHAT!!!” :smiley: , but the IDE should not crash.

Nice instrument. It highlights one of the most frustrating things about running Csound within a host application: if Csound crashes so will the host. Annoying isn’t it, but I don’t think there is much I can do about it without doing huge reconstructive surgery on the entire source code.

The simple app I sent should help prevent compile time crashes, but won’t help perf-time errors. Most audio hosts now load plugins in a separate process. I’ll have to do that with Cabbage at some point. I just need to do some reading first as I’ve no idea really how best to do it!

[edit] Maybe we should ask the Csound guys to put in a fail-safe for div by 0 so that it doesn’t bring down hosts?

About the divide by zero error there is a special opcode ‘divz’ that could be used to avoid crashes, at the expense of a little cpu time to make the necessary check.

But in my experimental instrument the problems are not related to a divide by zero error, because the instrument always works well the first time. The problem occurs in the subsequent “Play” after a “Stop”… It’s always like a lottery!

I don’t know how the Csound API works but I suspect that when you click “Stop” in Cabbage, the main Csound instance is not released… If that’s the case, then if you could release it and then recreate the Csound instance at the next “Play”, maybe strange crashes no longer occurs?

That’s exactly what happens. When you hit stop, or recompile, the previous instance is freed and a new one created. There is also a recompile() API command, but that one resulted in even more crashes. The only way to prevent Csound from taking out Cabbage is to put it in its own process.

Of course, your crash might not have anything to do with Csound! If you PM me the instrument I can run it through the debugger here and see what’s up.

Btw, are you the same Mauro who posts to the Csound list? If so, perhaps you want to try building Cabbage yourself?

Hi Rory, yes I’m the same user from the Csound list. :spy: :wink:
Until now I didn’t have yet time to put up a MSVC building system on my Windows machine, but sooner or later I will do it, for Cabbage and Csound too.

Anyway, I managed to isolate the problematic code and then I made the following csd so that you could debug it:

<Cabbage> 
form caption("Start - Play some notes - Stop - Start and... Crash!") size(600, 300), colour(255, 255, 255), pluginID("def1")
keyboard bounds(10, 192, 581, 95) value(30) whitenotecolour(255, 255, 255, 255) 
nslider bounds(484, 14, 105, 27) range(1, 100, 32, 1, 1) velocity(50) text("Max Polyphony") channel("maxPoly") increment(1) value(32) textcolour(144, 144, 144, 255)
label bounds(474, 48, 83, 12) text("Active notes:") colour(243, 3, 3, 0) align("right") fontcolour(144, 144, 144, 255)
label bounds(562, 48, 26, 12) text("0") colour(202, 238, 90, 0) fontcolour(34, 34, 34, 255) identchannel("activeNotes") align("right")
gentable bounds(440, 70, 147, 99) tablenumber(1111) amprange(0, 1, 1111, 0.0100) tablegridcolour(236, 236, 236, 255) tablebackgroundcolour(245, 245, 245, 255) active(1) tablecolour:0(111, 111, 111, 147)
label bounds(440, 172, 147, 13) text("Velocity Curve") fontcolour(43, 43, 43, 255) 
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
sr  = 44100
ksmps = 256
nchnls  = 2
0dbfs   = 1

giVelCurveRes   =           1024
giFT_velCurve   ftgen       1111, 0, giVelCurveRes, -7,              \
                            0, giVelCurveRes * (0.05 - 0),     0,    \
                               giVelCurveRes * (0.5 - 0.05),   0.12, \
                               giVelCurveRes * (0.8 - 0.5),    0.5,  \
                               giVelCurveRes * (1 - 0.8),      1
                               
#define VELCURVE(vel) #
    $vel    tab_i   floor(giVelCurveRes * $vel), giFT_velCurve
#

opcode corda, a, ii
    iFreq, iVel xin
    
                setksmps 8
    
    aNoise      rand    iVel
    iDelayLdur  =       1 / iFreq
    aImpulse    =       aNoise * linseg:a(1, iDelayLdur, 1, 0, 0)
    aOut        delayr  1 / iFreq
    aOut        +=      aImpulse
    aOut        =       (aOut + delay1(aOut)) * 0.5
                delayw  aOut
    
                xout    aOut
endop

instr 2
    iFreq	    =	    p4
    iVel	    =       p5
	
    $VELCURVE(iVel)
	
    ; the following linseg is not used in this example code but, surprisingly,
    ; if you comment it, there will be no more crashes in the subsequent runs!
    kg          linseg  0, 1, 1
	
    aOut        corda   iFreq, iVel
    
                out    aOut
endin


        massign     0, 1


;instrument will be triggered by keyboard widget

instr 1
    iFreq       =	    p4
    iAmp        =           p5
    iNumKey     =           notnum() - 20
    
    if (iNumKey < 1 || iNumKey > 88) goto skipnote
		
    aOut        subinstr    2, iFreq, iAmp  
    aOut        =           aOut * madsr(0.01, 0, 1, 5)
	        outs        aOut, aOut
			    
    skipnote:
endin


instr Mntr
    kMaxPoly    chnget  "maxPoly"
    
    kActivNotes active  1
    
	if (kActivNotes > kMaxPoly) then
	    turnoff2    1, 1, 0
	endif
                
                chnset  sprintfk("text(\"%d\")", kActivNotes), "activeNotes"
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f 0 z
i "Mntr" 0 z
</CsScore>
</CsoundSynthesizer>

If you run this program in Cabbage it works, but if you play some notes and then you Stop and Play again, it will crash. If you comment the “kg linseg …” line in “instr 2” it doesn’t crash anymore. I found that a way to avoid to make it crash without to comment the “kg linseg…” statement is to not use the ‘subinstr’ and replace it directly with the “instr 2” code, but it’s not a good option for me, being that in my experimental synth I need the subinstr statement.

A strange thing is that I tried to make a CsoundQT version of this code and in that environment it doesn’t crash even if I stop and play it many times! So, I don’t understand if this is a Csound problem or a Cabbage one. :confused:

Nice. You seem to have a good bit of experience with low level programming?

It’s not much of a chore these days. The last time I tried Csound built straight out of the box with VS2107. The Csound project could definitely do with my Windows developers.

I’m going to try it now.

No crashes here on OSX. Will try later on Linux and Windows. Looks like it could be a Windows issue. I find Windows to be the least stable of all Csound platforms.

[quote=“rorywalsh, post:12, topic:1202”]
Nice. You seem to have a good bit of experience with low level programming?
[/quote]Just a little. In the past I contributed to correct some bugs in opensource software (for example, some gui aspects of the XFCE desktop environment, that is what I use with an Xubuntu machine at work), but that was some years ago… Now, the time I can work on my personal projects is very limited. Anyway, if I have the chance, I like to help.

[quote=“rorywalsh, post:13, topic:1202, full:true”]
No crashes here on OSX. Will try later on Linux and Windows. Looks like it could be a Windows issue. I find Windows to be the least stable of all Csound platforms.
[/quote]I just tried in a Windows 7 virtual machine running on Linux that I have at work, and the result is the same: Cabbage crashes after you play some notes and then Stop and Play the instrument again.

I just tried here on Windows 10 and I can’t recreate any crash? Strange. Can you try installing this package and let me know? I have another Windows machine to test it on later too, but so far no problems.

Hi Rory, that link doesn’t work… Maybe is this LINK?

Not sure what happened with my link, but looks like you have the right one. Does it work? I’m just about to test on another Windows machine…

[edit] seems to work fine for me here too?

Hi Rory, I tried Cabbage from that link, but it still crash the second time I stop and play. Please note that to make it crash I have to do the following:

  1. Load the CSD with that code.
  2. Start the instrument.
  3. Make sure you are playing at least 15 notes in polyphony (check the number after the “Active notes” label) and then press Stop.
  4. Press Play => CRASH!

Moreover, with the last Cabbage from that link, when I start the csd, inside the title window, instead of the text I set in the “form caption(…)” statement, there will be a “CabbageEffectNam” text.

Thanks I’ll try your method of crashing it. I don’t think I pushed it that hard. I’ll sort the plug-in name issue. The current tip is a week in progress.

I’m downloading Visual Studio Community 2017… Are there instructions on how to build Cabbage with it? What else I have to download? Juce?