Csound Csound-dev Csound-tekno Search About

[Csnd-dev] Segmentation violation when subinstr + playing many notes in polyphony

Date2018-10-19 11:33
FromMauro Giubileo
Subject[Csnd-dev] Segmentation violation when subinstr + playing many notes in polyphony

On a Windows machine, the following CSD goes in "segmentation violation" after about 8 seconds, but in Csound 6.10 it works fine. From 6.11 onwards, it crashes.

<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5 -odac
</CsOptions>
<CsInstruments>
; Initialize the global variables.
sr  = 44100
ksmps = 256
nchnls  = 2
0dbfs   = 1

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
    
    ; the following linseg is useless in this example code but, surprisingly,
    ; if you comment it, there will be no more crashes!
    kg          linseg  0, 1, 1
    
    aOut        corda   iFreq, iVel
    
                out    aOut
endin


instr 1
    iFreq       =           p4
    iAmp        =           p5
        
    aOut        subinstr    2, iFreq, iAmp  
    aOut        =           aOut * madsr(0.01, 0, 1, 5)
                outs        aOut, aOut            
endin

</CsInstruments>
<CsScore>
i1 0   1 262 0.25
i1 0.1 1 292 0.25
i1 0.2 1 342 0.25
i1 0.3 1 392 0.25
i1 0.4 1 432 0.25
i1 0.5 1 492 0.25
i1 0.6 1 262 0.25
i1 0.7 1 292 0.25
i1 0.8 1 342 0.25
i1 0.9 1 392 0.25
i1 1.0 1 432 0.25
i1 1.1 1 492 0.25
i1 1.2 1 262 0.25
i1 1.3 1 292 0.25
i1 1.4 1 342 0.25
i1 1.5 1 392 0.25
i1 1.6 1 432 0.25
i1 1.7 1 492 0.25
i1 1.8 1 262 0.25
i1 1.9 1 292 0.25
i1 1.0 1 342 0.25
i1 2.1 1 392 0.25
i1 2.2 1 432 0.25
i1 2.3 1 492 0.25
</CsScore>
</CsoundSynthesizer>

This problem has been driving me crazy for several days... I found that it occurs when you use a subinstr and then, inside the sub-instrument called, you use a native opcode that does a "csound->AuxAlloc(...)" to allocate memory. That function is used in many native opcodes, so this is very problematic. I made an experimental synth that makes extensive use of subinstr and linseg/transeg inside the sub-instrument, so it always crashes when you play many notes in polyphony.

The VS debugger tells me that the crash occurs inside the auxchfree function (from the file "Engine/auxfd.c").

Have there been any changes in the Csound internal memory management functions (at least concerning Windows), from Csound 6.11 onwards?

Regards,
Mauro



Date2018-10-19 12:10
FromJohn ff
SubjectRe: [Csnd-dev] Segmentation violation when subinstr + playing many notes in polyphony
Sounds like a memory issue.

⁣Sent from TypeApp ​

On Oct 19, 2018, 11:34, at 11:34, Mauro Giubileo  wrote:
>On a Windows machine, the following CSD goes in "segmentation
>violation"
>after about 8 seconds, but in Csound 6.10 it works fine. From 6.11
>onwards, it crashes. 
>
>
>
>-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
>-odac
>
>
>; Initialize the global variables. 
>sr  = 44100
>ksmps = 256
>nchnls  = 2
>0dbfs   = 1
>
>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
>
>    ; the following linseg is useless in this example code but,
>surprisingly,
>    ; if you comment it, there will be no more crashes!
>    kg          linseg  0, 1, 1
>
>    aOut        corda   iFreq, iVel
>
>                out    aOut
>endin
>
>instr 1
>    iFreq       =           p4
>    iAmp        =           p5
>
>    aOut        subinstr    2, iFreq, iAmp  
>    aOut        =           aOut * madsr(0.01, 0, 1, 5)
>                outs        aOut, aOut            
>endin
>
>
>
>i1 0   1 262 0.25
>i1 0.1 1 292 0.25
>i1 0.2 1 342 0.25
>i1 0.3 1 392 0.25
>i1 0.4 1 432 0.25
>i1 0.5 1 492 0.25
>i1 0.6 1 262 0.25
>i1 0.7 1 292 0.25
>i1 0.8 1 342 0.25
>i1 0.9 1 392 0.25
>i1 1.0 1 432 0.25
>i1 1.1 1 492 0.25
>i1 1.2 1 262 0.25
>i1 1.3 1 292 0.25
>i1 1.4 1 342 0.25
>i1 1.5 1 392 0.25
>i1 1.6 1 432 0.25
>i1 1.7 1 492 0.25
>i1 1.8 1 262 0.25
>i1 1.9 1 292 0.25
>i1 1.0 1 342 0.25
>i1 2.1 1 392 0.25
>i1 2.2 1 432 0.25
>i1 2.3 1 492 0.25
>
> 
>
>This problem has been driving me crazy for several days... I found that
>it occurs when you use a subinstr and then, inside the sub-instrument
>called, you use a native opcode that does a "csound->AuxAlloc(...)" to
>allocate memory. That function is used in many native opcodes, so this
>is very problematic. I made an experimental synth that makes extensive
>use of subinstr and linseg/transeg inside the sub-instrument, so it
>always crashes when you play many notes in polyphony. 
>
>The VS debugger tells me that the crash occurs inside the auxchfree
>function (from the file "Engine/auxfd.c"). 
>
>Have there been any changes in the Csound internal memory management
>functions (at least concerning Windows), from Csound 6.11 onwards?
>
>Regards,

Date2018-10-19 12:11
FromJohn ff
SubjectRe: [Csnd-dev] Segmentation violation when subinstr + playing many notes in polyphony
And as far as I recall no changes to the aux system

⁣Sent from TypeApp ​

On Oct 19, 2018, 11:34, at 11:34, Mauro Giubileo  wrote:
>On a Windows machine, the following CSD goes in "segmentation
>violation"
>after about 8 seconds, but in Csound 6.10 it works fine. From 6.11
>onwards, it crashes. 
>
>
>
>-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
>-odac
>
>
>; Initialize the global variables. 
>sr  = 44100
>ksmps = 256
>nchnls  = 2
>0dbfs   = 1
>
>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
>
>    ; the following linseg is useless in this example code but,
>surprisingly,
>    ; if you comment it, there will be no more crashes!
>    kg          linseg  0, 1, 1
>
>    aOut        corda   iFreq, iVel
>
>                out    aOut
>endin
>
>instr 1
>    iFreq       =           p4
>    iAmp        =           p5
>
>    aOut        subinstr    2, iFreq, iAmp  
>    aOut        =           aOut * madsr(0.01, 0, 1, 5)
>                outs        aOut, aOut            
>endin
>
>
>
>i1 0   1 262 0.25
>i1 0.1 1 292 0.25
>i1 0.2 1 342 0.25
>i1 0.3 1 392 0.25
>i1 0.4 1 432 0.25
>i1 0.5 1 492 0.25
>i1 0.6 1 262 0.25
>i1 0.7 1 292 0.25
>i1 0.8 1 342 0.25
>i1 0.9 1 392 0.25
>i1 1.0 1 432 0.25
>i1 1.1 1 492 0.25
>i1 1.2 1 262 0.25
>i1 1.3 1 292 0.25
>i1 1.4 1 342 0.25
>i1 1.5 1 392 0.25
>i1 1.6 1 432 0.25
>i1 1.7 1 492 0.25
>i1 1.8 1 262 0.25
>i1 1.9 1 292 0.25
>i1 1.0 1 342 0.25
>i1 2.1 1 392 0.25
>i1 2.2 1 432 0.25
>i1 2.3 1 492 0.25
>
> 
>
>This problem has been driving me crazy for several days... I found that
>it occurs when you use a subinstr and then, inside the sub-instrument
>called, you use a native opcode that does a "csound->AuxAlloc(...)" to
>allocate memory. That function is used in many native opcodes, so this
>is very problematic. I made an experimental synth that makes extensive
>use of subinstr and linseg/transeg inside the sub-instrument, so it
>always crashes when you play many notes in polyphony. 
>
>The VS debugger tells me that the crash occurs inside the auxchfree
>function (from the file "Engine/auxfd.c"). 
>
>Have there been any changes in the Csound internal memory management
>functions (at least concerning Windows), from Csound 6.11 onwards?
>
>Regards,

Date2018-10-19 12:30
FromMauro Giubileo
SubjectRe: [Csnd-dev] Segmentation violation when subinstr + playing many notes in polyphony

Being that the problem occurs only in sub-instruments, if there were no relevant changes to the auxfd.c functions, I think we should check the file "Engine/insert.c" too, in the functions related to the "subinstr" call. From github I see there are many changes there from January 2018 (the 6.10 version that works was from January 2018)...

Regards,
Mauro

Il 2018-10-19 13:11 John ff ha scritto:

And as far as I recall no changes to the aux system

⁣Sent from TypeApp ​

On Oct 19, 2018, 11:34, at 11:34, Mauro Giubileo <mgiubileo@computeraltafed.it> wrote:
On a Windows machine, the following CSD goes in "segmentation
violation"
after about 8 seconds, but in Csound 6.10 it works fine. From 6.11
onwards, it crashes.

<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
-odac
</CsOptions>
<CsInstruments>
; Initialize the global variables.
sr  = 44100
ksmps = 256
nchnls  = 2
0dbfs   = 1

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

   ; the following linseg is useless in this example code but,
surprisingly,
   ; if you comment it, there will be no more crashes!
   kg          linseg  0, 1, 1

   aOut        corda   iFreq, iVel

               out    aOut
endin

instr 1
   iFreq       =           p4
   iAmp        =           p5

   aOut        subinstr    2, iFreq, iAmp
   aOut        =           aOut * madsr(0.01, 0, 1, 5)
               outs        aOut, aOut
endin

</CsInstruments>
<CsScore>
i1 0   1 262 0.25
i1 0.1 1 292 0.25
i1 0.2 1 342 0.25
i1 0.3 1 392 0.25
i1 0.4 1 432 0.25
i1 0.5 1 492 0.25
i1 0.6 1 262 0.25
i1 0.7 1 292 0.25
i1 0.8 1 342 0.25
i1 0.9 1 392 0.25
i1 1.0 1 432 0.25
i1 1.1 1 492 0.25
i1 1.2 1 262 0.25
i1 1.3 1 292 0.25
i1 1.4 1 342 0.25
i1 1.5 1 392 0.25
i1 1.6 1 432 0.25
i1 1.7 1 492 0.25
i1 1.8 1 262 0.25
i1 1.9 1 292 0.25
i1 1.0 1 342 0.25
i1 2.1 1 392 0.25
i1 2.2 1 432 0.25
i1 2.3 1 492 0.25
</CsScore>
</CsoundSynthesizer>

This problem has been driving me crazy for several days... I found that
it occurs when you use a subinstr and then, inside the sub-instrument
called, you use a native opcode that does a "csound->AuxAlloc(...)" to
allocate memory. That function is used in many native opcodes, so this
is very problematic. I made an experimental synth that makes extensive
use of subinstr and linseg/transeg inside the sub-instrument, so it
always crashes when you play many notes in polyphony.

The VS debugger tells me that the crash occurs inside the auxchfree
function (from the file "Engine/auxfd.c").

Have there been any changes in the Csound internal memory management
functions (at least concerning Windows), from Csound 6.11 onwards?

Regards,
Mauro