[Stk] Segfault in SineWave.h

Janosch.rux janosch.rux at web.de
Wed Jan 12 08:55:10 PST 2011


He knows that he doesn't have to take that personally ;)

I clean the code up according to your suggestions, I don't know why I
wrote that in a own thread. *sigh*

So, it works now, but the segfault came from a -malign-double directive
which I took from the original Makefile
but actually the code didn't need.

Thanks for your help guys.

Regards

Janosch




On 11.01.2011 23:33, Stephen Sinclair wrote:
> Ah yes, your problem is in the 'fuckit' variable, which is causing the
> computer to feel insulted and sulk at you. ;)
>
> No just kidding.
>
> Your problem is likely that you are spawning a thread which just opens
> an RtAudio stream and then waits in a while(1){} loop, eating up the
> CPU for no reason.  You actually don't really need to create your own
> thread here.  You should just call openStream, startStream, and then
> your tick() function will automatically get called by the operating
> system's audio API.  In cases where a thread is needed for this
> (depends on which audio system / operating system), RtAudio will
> create it for you.
>
> As for why it's crashing, I'm looking for other places in the program
> that access the "struct args_struct" pointed to by 'fuckit', but I
> don't see any, so I don't see any conflicts.
>
> I do notice that you've commented out the definition of "struct
> args_struct", so it is possible that you've defined it a bit
> differently somewhere in a header file?  If that's the case it might
> just be that your object files have gotten out of date and some other
> bits of your program are trying to access a slight different layout of
> "args_struct"; if so, you just need to "rm *.o" and recompile
> everything.  Just a guess though.
>
> If not, you'll have to come up with a more "minimal" example of a
> crashing program that you can post to the list if you want help.  We
> can't help you if we can't duplicate the problem.
>
> Steve
>
> On Mon, Jan 10, 2011 at 9:39 AM, Janosch.rux <janosch.rux at web.de> wrote:
>   
>> Thats the whole main.cpp:
>>
>>     http://pastebin.com/aeGsNz06
>>
>> Regards
>>
>> On 10.01.2011 01:15, Tristan Matthews wrote:
>>
>> 2011/1/7 Janosch.rux <janosch.rux at web.de>
>>     
>>> I tried to extract the relevant parts. The whole code is a hand tracking
>>> example for the kinect device. In my opinion this is really messy but
>>> actually I don't know how I could solve this in a more elegant way.
>>>
>>> Thanks for your reply
>>>
>>> Janosch Rux
>>>
>>> See also: http://pastebin.com/7smzrQ02
>>>
>>> ###### Definition of args_struct
>>>
>>> struct args_struct {
>>>         stk::SineWave *sine;
>>>         XnVPointDrawer *point;
>>> };
>>>
>>>
>>> #######Call in main.cpp:
>>>
>>>         args_stk.point = g_pDrawer;
>>>
>>>         //sound init get pointer to drawer
>>>         status = pthread_create(&sig, NULL, audio, (void *)&args_stk);
>>>         if(status != 0) {
>>>                 printf("Can't create thread\n");
>>>                 exit(EXIT_FAILURE);
>>>         }
>>>
>>>         pthread_detach(sig);
>>>       
>>
>> Could you show the rest of main.cpp? It's possible that args_stk is going
>> out of scope.
>>
>> -t
>>
>>     
>>> ######## the thread function to init the stk
>>>
>>> void *audio(void *arg) {
>>>
>>>   RtAudio dac;
>>>  struct args_struct *fuckit = (args_struct *) arg;
>>>   fuckit->sine = new SineWave;
>>>
>>>   // Figure out how many bytes in an StkFloat and setup the RtAudio
>>> stream.
>>>   RtAudio::StreamParameters parameters;
>>>   parameters.deviceId = dac.getDefaultOutputDevice();
>>>   parameters.nChannels = 1;
>>>   RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 :
>>> RTAUDIO_FLOAT32;
>>>   unsigned int bufferFrames = RT_BUFFER_SIZE;
>>>
>>>
>>>   try {
>>>     dac.openStream( &parameters, NULL, format, (unsigned
>>> int)Stk::sampleRate(), &bufferFrames, &tick, (void *)fuckit);
>>>   }
>>>   catch ( RtError &error ) {
>>>     error.printMessage();
>>>     exit(EXIT_FAILURE);
>>>   }
>>>
>>>   fuckit->sine->setFrequency(440.0);
>>>
>>>   try {
>>>     dac.startStream();
>>>   }
>>>   catch ( RtError &error ) {
>>>     error.printMessage();
>>>     exit(EXIT_FAILURE);
>>>   }
>>>
>>>         while(1) {}
>>>
>>>         return 0;
>>> }
>>>
>>> ###### the tick() function
>>>
>>> int tick( void *outputBuffer, void *inputBuffer, unsigned int
>>> nBufferFrames,
>>>  double streamTime, RtAudioStreamStatus status, void *dataPointer )
>>> {
>>>
>>> struct args_struct *fuckit = (args_struct *)dataPointer;
>>> register StkFloat *samples = (StkFloat *) outputBuffer;
>>> fuckit->sine->setFrequency(fuckit->point->get_stk_freq());
>>>
>>> //printf("Freq: %i\n", fuckit->point->get_stk_freq());
>>>
>>>   for ( unsigned int i=0; i<nBufferFrames; i++ ) {
>>>                 *samples++ = fuckit->sine->tick();
>>>         }
>>>
>>>   return 0;
>>> }
>>>
>>>
>>> On 07.01.2011 20:47, Tristan Matthews wrote:
>>>
>>> 2011/1/7 Janosch.rux <janosch.rux at web.de>
>>>       
>>>> Hi,
>>>>
>>>> I use stk with callbacks to enhance another piece of software. Stk is
>>>> encapsulated in its own thread. If the tick function calls the sine->tick()
>>>> as in the example (https://ccrma.stanford.edu/software/stk/crealtime.html)
>>>> on the web page I get a segfault on line 116 in SineWave.h.
>>>>
>>>> Im not quite sure whether this is a bug or mistake on my side.
>>>>         
>>> Could you provide your code (or at least the relevant part)? Without
>>> seeing it, we can only hazard a guess as to what is going wrong.
>>>
>>> -t
>>>
>>>       
>>>> Thanks for any suggestions.
>>>>
>>>> Regards
>>>>
>>>> Janosch Rux
>>>>
>>>> _______________________________________________
>>>> Stk mailing list
>>>> Stk at ccrma.stanford.edu
>>>> http://ccrma-mail.stanford.edu/mailman/listinfo/stk
>>>>
>>>>         
>>>
>>>
>>> --
>>> Tristan Matthews
>>> email: tristan at sat.qc.ca
>>> web: http://tristanswork.blogspot.com
>>>
>>>
>>> _______________________________________________
>>> Stk mailing list
>>> Stk at ccrma.stanford.edu
>>> http://ccrma-mail.stanford.edu/mailman/listinfo/stk
>>>
>>>       
>>
>>
>> --
>> Tristan Matthews
>> email: tristan at sat.qc.ca
>> web: http://tristanswork.blogspot.com
>>
>>
>> _______________________________________________
>> Stk mailing list
>> Stk at ccrma.stanford.edu
>> http://ccrma-mail.stanford.edu/mailman/listinfo/stk
>>
>>
>>     
> _______________________________________________
> Stk mailing list
> Stk at ccrma.stanford.edu
> http://ccrma-mail.stanford.edu/mailman/listinfo/stk
>   



More information about the Stk mailing list