Csound Csound-dev Csound-tekno Search About

[Cs-dev] deinit callback

Date2005-11-24 19:50
FromErich Koslovsky
Subject[Cs-dev] deinit callback
Hi,
I have got a problem with the deinit function.
After implementing, running csound
executes with a segmentation fault.

Csound tidy up: Segmentation fault

The deinit function should free memory used to store the memory to
draw in a fltk widget. The memory is allocated at the init time with
the new operator. In the init function of the opcode I register the 
callback:

//Register the Deinit Callback
if(p->init!=1)
{
   csound->RegisterDeinitCallback(csound, p, fltimeampWindow_deinit);
   p->init=1;
}

And provide a callback function:

extern "C" int fltimeampWindow_deinit(CSOUND *csound, void *pp)
{
   FLTIMEAMPWINDOW *p = (FLTIMEAMPWINDOW *)pp;

   ADDR_SET_VALUE v = AddrSetValue[(int)*p->ihandle];
   timeamp_window *opgl = (timeamp_window *) v.WidgAddress;
     //delete the drawing buffer
   delete[ ] opgl->pbuffer;

   return OK; }
The ihandle is a unique identifier to the widget and works in the
other opcode functions quite well. I am a bit stucked here - tried to
figure out with gdb where the seg-fault actually happens. But I am
not an expert dealing with gdb but it seams to be related with fltk,
maybe the memory is allready deleted.

Program received signal EXC_BAD_ACCESS, Could not access memory.
[Switching to process 1244 thread 0x28f]
0x00764998 in timeamp_window::draw() ()
(gdb) where
#0  0x00764998 in timeamp_window::draw() ()
#1  0x00615620 in Fl_Gl_Window::flush() ()
#2  0x01341fec in Fl_X::flush() ()
#3  0x0130694c in Fl::flush() ()
#4  0x01306588 in Fl::wait(double) ()
#5  0x02010920 in fltkRun (userdata=0x1360014) at InOut/widgets.cpp:1727
#6  0x900246e8 in _pthread_body ()

Any help would be highly appreciated,
I can also post the full code if desired
Thanks,
   Simon


-------------------------------------------------------
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://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net