Csound Csound-dev Csound-tekno Search About

[Cs-dev] Spot the problem....

Date2006-02-06 19:55
FromRory Walsh
Subject[Cs-dev] Spot the problem....
Can anyone see why this code will cause a crash if I try to call the 
Button1Click method a second time after letting csound perform the .csd 
file once through? I wait several seconds and then I try it again but I 
get a crash?

These are the variables I declare in my header file:

    char **cmdl;
    CSOUND* instance;
    int result;

And here is the bones of my .cpp file. I hope it's not something too 
obvious!

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
   : TForm(Owner)
{
cmdl = (char **) malloc(sizeof(char*)*(2));
instance = csoundCreate(0);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  cmdl[0] = "csound";
  cmdl[1] = "E:/MinCsound/basic.csd";
  result = csoundCompile(instance, 2, cmdl);
  csoundCreateThread((uintptr_t(*)(void *))csThread, (void *)instance);
}

//---------------------------------------------------------------------------
uintptr_t csThread(void *clientData)
{
CSOUND *p = (CSOUND *) clientData;
     if(!Form1->result)
       {
 
if((csoundPerformKsmps(p)!=0)&&(csoundPerformKsmps(p)!=1))ShowMessage("Runtime 
Error 107");
       else{
             while(csoundPerformKsmps(p)==0)
               {
               }
             }
      csoundReset(p);
     }
}
//--------------------------------------------------------------------------

Cheers,
Rory.





-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2006-02-06 20:11
FromIstvan Varga
SubjectRe: [Cs-dev] Spot the problem....
AttachmentsNone  

Date2006-02-06 20:28
FromRory Walsh
SubjectRe: [Cs-dev] Spot the problem....
I'll check it out. It's most likely what you suggested about the thread 
  not being fully stopped. I'll take a look at csoundJoinThread() and 
try that. Cheers,
Rory.

Istvan Varga wrote:
> On Monday 06 February 2006 20:55, Rory Walsh wrote:
> 
> 
>>Can anyone see why this code will cause a crash if I try to call the 
>>Button1Click method a second time after letting csound perform the .csd 
>>file once through? I wait several seconds and then I try it again but I 
>>get a crash?
> 
> 
> Are you sure that the thread has really stopped by the time you
> call Button1Click() again (you can call csoundJoinThread() to wait
> on the thread until it exits; this also cleans up any resources
> associated with the thread by the OS) ?
> Is it possible that the Csound instance was destroyed, or cmdl
> was freed somehow before creating the thread the second time ?
> 
> 
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
> 



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2006-02-06 20:56
FromRory Walsh
SubjectRe: [Cs-dev] Spot the problem....
So I tried the csoundJoinThread() but that doesn't seem to work, in the 
header file it says pass the thread routine, in my case csThread, but 
when I do this it does not wait until the thread has finished. I have 
tried calling csoundJoinThread whilst the thread was performing and it 
still didn't wait. Perhaps I am not passing the correct parameter?

Istvan Varga wrote:
> On Monday 06 February 2006 20:55, Rory Walsh wrote:
> 
> 
>>Can anyone see why this code will cause a crash if I try to call the 
>>Button1Click method a second time after letting csound perform the .csd 
>>file once through? I wait several seconds and then I try it again but I 
>>get a crash?
> 
> 
> Are you sure that the thread has really stopped by the time you
> call Button1Click() again (you can call csoundJoinThread() to wait
> on the thread until it exits; this also cleans up any resources
> associated with the thread by the OS) ?
> Is it possible that the Csound instance was destroyed, or cmdl
> was freed somehow before creating the thread the second time ?
> 



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2006-02-06 21:11
FromRory Walsh
SubjectRe: [Cs-dev] Spot the problem....
I did another few tests and it seems that the thread is finishing ok, 
which makes me wonder about your other suggestion, that the csound 
instance may have been destroyed by the time I call the thread again. I 
can't really see how. Could there a problem with my locally declared 
CSOUND* p somehow? Finally, perhaps there is something more sinister 
involved, perhaps my thread isn't behaving as it should. Thanks for the 
help, I'll stick at it..

Rory.


Istvan Varga wrote:
> On Monday 06 February 2006 20:55, Rory Walsh wrote:
> 
> 
>>Can anyone see why this code will cause a crash if I try to call the 
>>Button1Click method a second time after letting csound perform the .csd 
>>file once through? I wait several seconds and then I try it again but I 
>>get a crash?
> 
> 
> Are you sure that the thread has really stopped by the time you
> call Button1Click() again (you can call csoundJoinThread() to wait
> on the thread until it exits; this also cleans up any resources
> associated with the thread by the OS) ?
> Is it possible that the Csound instance was destroyed, or cmdl
> was freed somehow before creating the thread the second time ?
> 
> 
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
> 



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2006-02-06 21:16
FromIstvan Varga
SubjectRe: [Cs-dev] Spot the problem....
AttachmentsNone  

Date2006-02-06 21:22
FromIstvan Varga
SubjectRe: [Cs-dev] Spot the problem....
AttachmentsNone  

Date2006-02-06 21:41
FromRory Walsh
SubjectRe: [Cs-dev] Spot the problem....
Thanks, so it seems my tests weren't so accurate! from your previous 
post about csoundJoinThread() I see my thread is indeed stalling 
somewhere as csoundJoinThread() waits indefinitely; but it does not seem 
to be at any of the csoundAPI functions. I placed a messageBox() in the 
last line of the thread which executes every time. Can I terminate the 
thread myself, although I guess this would only cause further problems 
down the line.

Rory.

Istvan Varga wrote:
> On Monday 06 February 2006 22:11, Rory Walsh wrote:
> 
> 
>>I did another few tests and it seems that the thread is finishing ok, 
>>which makes me wonder about your other suggestion, that the csound 
>>instance may have been destroyed by the time I call the thread again. I 
>>can't really see how.
> 
> 
> Well, this was just one random guess. From the code posted, it is not
> obvious why it crashes.
> 
> While it is probably not related to your problem, but if you use
> a double precision Csound library (such as the one included with
> the Win32 .exe installer), make sure to define the macro USE_DOUBLE
> before including Csound API headers.
> 
> 
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
> 



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net