From: Good Guy Date: Mon, 11 Apr 2016 22:30:06 +0000 (-0600) Subject: change thread join strategy, fix a few leaks, fix a few bugs X-Git-Url: https://git.cinelerra-gg.org/git/?a=commitdiff_plain;h=3ec3a9cc6afc6561311686b3ec597ee3c1d80d6f;p=goodguy%2Fhistory.git change thread join strategy, fix a few leaks, fix a few bugs --- diff --git a/cinelerra-5.1/cinelerra/androidcontrol.C b/cinelerra-5.1/cinelerra/androidcontrol.C index 784dea23..79008ac8 100644 --- a/cinelerra-5.1/cinelerra/androidcontrol.C +++ b/cinelerra-5.1/cinelerra/androidcontrol.C @@ -143,7 +143,7 @@ AndroidControl::~AndroidControl() if( Thread::running() ) { done = 1; Thread::cancel(); - Thread::join(); } + Thread::join(); } diff --git a/cinelerra-5.1/cinelerra/assetedit.C b/cinelerra-5.1/cinelerra/assetedit.C index eb76149b..dbdabf36 100644 --- a/cinelerra-5.1/cinelerra/assetedit.C +++ b/cinelerra-5.1/cinelerra/assetedit.C @@ -1036,8 +1036,8 @@ void DetailAssetThread::stop() dwindow->lock_window("DetailAssetThread::stop"); dwindow->set_done(1); dwindow->unlock_window(); - Thread::join(); } + Thread::join(); } void DetailAssetWindow::create_objects() diff --git a/cinelerra-5.1/cinelerra/awindow.C b/cinelerra-5.1/cinelerra/awindow.C index be3cf27c..f6a87ed8 100644 --- a/cinelerra-5.1/cinelerra/awindow.C +++ b/cinelerra-5.1/cinelerra/awindow.C @@ -45,8 +45,8 @@ AWindow::~AWindow() gui->lock_window("AWindow::~AWindow"); gui->set_done(0); gui->unlock_window(); - Thread::join(); } + Thread::join(); delete asset_remove; delete asset_edit; delete label_edit; diff --git a/cinelerra-5.1/cinelerra/brender.C b/cinelerra-5.1/cinelerra/brender.C index 35144b26..3a1e3f82 100644 --- a/cinelerra-5.1/cinelerra/brender.C +++ b/cinelerra-5.1/cinelerra/brender.C @@ -93,9 +93,9 @@ TRACE("BRender::~BRender 5\n"); { kill(master_pid, SIGKILL); TRACE("BRender::~BRender 6\n"); - Thread::join(); TRACE("BRender::~BRender 7\n"); } + Thread::join(); TRACE("BRender::~BRender 8\n"); delete map_lock; diff --git a/cinelerra-5.1/cinelerra/channeledit.C b/cinelerra-5.1/cinelerra/channeledit.C index 91b7c11b..6e02639e 100644 --- a/cinelerra-5.1/cinelerra/channeledit.C +++ b/cinelerra-5.1/cinelerra/channeledit.C @@ -765,8 +765,8 @@ void ScanThread::stop() if( !interrupt ) { // Cancel previous job interrupt = 1; - Thread::join(); } + Thread::join(); if( progress ) { progress->stop_progress(); delete progress; progress = 0; diff --git a/cinelerra-5.1/cinelerra/channelinfo.C b/cinelerra-5.1/cinelerra/channelinfo.C index 140f3d30..71469330 100644 --- a/cinelerra-5.1/cinelerra/channelinfo.C +++ b/cinelerra-5.1/cinelerra/channelinfo.C @@ -70,8 +70,8 @@ void ChanSearch::stop() if( gui ) gui->set_done(1); window_lock->unlock(); Thread::cancel(); - Thread::join(); } + Thread::join(); } void ChanSearch::run() @@ -560,8 +560,8 @@ void ChannelProgress::stop() if( Thread::running() ) { done = 1; Thread::cancel(); - Thread::join(); } + Thread::join(); } void ChannelProgress::run() @@ -1050,8 +1050,8 @@ void ChannelThread::stop() if( Thread::running() ) { done = 1; Thread::cancel(); - Thread::join(); } + Thread::join(); } ChannelThread::ChannelThread(ChannelInfoGUI *gui) @@ -1655,8 +1655,8 @@ void ChannelInfo::stop() if( gui ) gui->stop(1); window_lock->unlock(); Thread::cancel(); - Thread::join(); } + Thread::join(); } void ChannelInfo::run() diff --git a/cinelerra-5.1/cinelerra/commercials.C b/cinelerra-5.1/cinelerra/commercials.C index a08ec029..2485f263 100644 --- a/cinelerra-5.1/cinelerra/commercials.C +++ b/cinelerra-5.1/cinelerra/commercials.C @@ -787,8 +787,8 @@ stop() if( running() ) { if( gui ) gui->set_done(1); cancel(); - join(); } + join(); } void ScanStatus:: @@ -856,8 +856,8 @@ stop() done = 1; input_lock->unlock(); cancel(); - join(); } + join(); if( commercials && !commercials->remove_user() ) commercials = 0; } diff --git a/cinelerra-5.1/cinelerra/cwindow.C b/cinelerra-5.1/cinelerra/cwindow.C index cc5a2707..c5009a08 100644 --- a/cinelerra-5.1/cinelerra/cwindow.C +++ b/cinelerra-5.1/cinelerra/cwindow.C @@ -65,8 +65,8 @@ CWindow::~CWindow() { if(gui && running()) { gui->set_done(0); - join(); } + join(); delete gui; gui = 0; delete playback_engine; delete playback_cursor; diff --git a/cinelerra-5.1/cinelerra/dbwindow.C b/cinelerra-5.1/cinelerra/dbwindow.C index c19b581e..48768cd4 100644 --- a/cinelerra-5.1/cinelerra/dbwindow.C +++ b/cinelerra-5.1/cinelerra/dbwindow.C @@ -87,8 +87,8 @@ stop() if( gui ) gui->set_done(1); window_lock->unlock(); Thread::cancel(); - Thread::join(); } + Thread::join(); } void DbWindow:: diff --git a/cinelerra-5.1/cinelerra/device1394input.C b/cinelerra-5.1/cinelerra/device1394input.C index 57d4e468..2fa7c6f0 100644 --- a/cinelerra-5.1/cinelerra/device1394input.C +++ b/cinelerra-5.1/cinelerra/device1394input.C @@ -67,8 +67,8 @@ Device1394Input::~Device1394Input() { done = 1; Thread::cancel(); - Thread::join(); } + Thread::join(); if(buffer) { diff --git a/cinelerra-5.1/cinelerra/device1394output.C b/cinelerra-5.1/cinelerra/device1394output.C index f021a165..6aa493e2 100644 --- a/cinelerra-5.1/cinelerra/device1394output.C +++ b/cinelerra-5.1/cinelerra/device1394output.C @@ -79,8 +79,8 @@ Device1394Output::~Device1394Output() done = 1; start_lock->unlock(); Thread::cancel(); - Thread::join(); } + Thread::join(); if(buffer) { diff --git a/cinelerra-5.1/cinelerra/devicev4l2base.C b/cinelerra-5.1/cinelerra/devicev4l2base.C index efc3c061..31a009b3 100644 --- a/cinelerra-5.1/cinelerra/devicev4l2base.C +++ b/cinelerra-5.1/cinelerra/devicev4l2base.C @@ -165,8 +165,8 @@ DeviceV4L2Put::~DeviceV4L2Put() done = 1; buffer_lock->unlock(); Thread::cancel(); - Thread::join(); } + Thread::join(); delete buffer_lock; delete putq; } @@ -709,8 +709,8 @@ void DeviceV4L2Base::close_dev() { done = 1; Thread::cancel(); - Thread::join(); } + Thread::join(); if(put_thread) { delete put_thread; diff --git a/cinelerra-5.1/cinelerra/dv1394input.C b/cinelerra-5.1/cinelerra/dv1394input.C index ebd18cf1..f8dd1f3a 100644 --- a/cinelerra-5.1/cinelerra/dv1394input.C +++ b/cinelerra-5.1/cinelerra/dv1394input.C @@ -38,8 +38,8 @@ DV1394Input::~DV1394Input() { done = 1; Thread::cancel(); - Thread::join(); } + Thread::join(); if(fd > 0) close(fd); } diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C index ccf80afc..51565786 100644 --- a/cinelerra-5.1/cinelerra/ffmpeg.C +++ b/cinelerra-5.1/cinelerra/ffmpeg.C @@ -1992,8 +1992,8 @@ void FFMPEG::stop_muxer() if( running() ) { done = 1; mux_lock->unlock(); - join(); } + join(); } void FFMPEG::flow_off() diff --git a/cinelerra-5.1/cinelerra/fileffmpeg.C b/cinelerra-5.1/cinelerra/fileffmpeg.C index ab856af0..660f750e 100644 --- a/cinelerra-5.1/cinelerra/fileffmpeg.C +++ b/cinelerra-5.1/cinelerra/fileffmpeg.C @@ -668,10 +668,12 @@ int FileFFMPEG::get_index(IndexFile *index_file, MainProgressBar *progress_bar) if( ff->scan(index_state, &scan_position, &canceled) || canceled ) { index_state->reset_index(); index_state->reset_markers(); - return 1; + canceled = 1; } delete scan_progress; + if( canceled ) return 1; + index_state->marker_status = MARKERS_READY; return index_state->create_index(index_path, asset); } diff --git a/cinelerra-5.1/cinelerra/filethread.C b/cinelerra-5.1/cinelerra/filethread.C index c5b28785..f8744545 100644 --- a/cinelerra-5.1/cinelerra/filethread.C +++ b/cinelerra-5.1/cinelerra/filethread.C @@ -501,8 +501,8 @@ int FileThread::stop_reading() { done = 1; read_wait_lock->unlock(); - Thread::join(); } + Thread::join(); return 0; } diff --git a/cinelerra-5.1/cinelerra/formattools.C b/cinelerra-5.1/cinelerra/formattools.C index d3685e02..28f4b556 100644 --- a/cinelerra-5.1/cinelerra/formattools.C +++ b/cinelerra-5.1/cinelerra/formattools.C @@ -493,14 +493,14 @@ void FormatTools::update(Asset *asset, int *strategy) void FormatTools::close_format_windows() { // This is done in ~file - if(aparams_thread && aparams_thread->running()) - { - aparams_thread->file->close_window(); + if( aparams_thread ) { + if( aparams_thread->running() ) + aparams_thread->file->close_window(); aparams_thread->join(); } - if(vparams_thread && vparams_thread->running()) - { - vparams_thread->file->close_window(); + if( vparams_thread ) { + if( vparams_thread->running() ) + vparams_thread->file->close_window(); vparams_thread->join(); } } diff --git a/cinelerra-5.1/cinelerra/gwindow.C b/cinelerra-5.1/cinelerra/gwindow.C index 679dacad..bfa490d3 100644 --- a/cinelerra-5.1/cinelerra/gwindow.C +++ b/cinelerra-5.1/cinelerra/gwindow.C @@ -34,8 +34,8 @@ GWindow::~GWindow() { if(gui && running()) { gui->set_done(0); - join(); } + join(); delete gui; gui = 0; } diff --git a/cinelerra-5.1/cinelerra/iec61883input.C b/cinelerra-5.1/cinelerra/iec61883input.C index cbdfe103..8b41c92b 100644 --- a/cinelerra-5.1/cinelerra/iec61883input.C +++ b/cinelerra-5.1/cinelerra/iec61883input.C @@ -67,8 +67,8 @@ IEC61883Input::~IEC61883Input() if(Thread::running()) { done = 1; - Thread::join(); } + Thread::join(); if(buffer) { diff --git a/cinelerra-5.1/cinelerra/iec61883output.C b/cinelerra-5.1/cinelerra/iec61883output.C index a2fe2e1a..8997266f 100644 --- a/cinelerra-5.1/cinelerra/iec61883output.C +++ b/cinelerra-5.1/cinelerra/iec61883output.C @@ -74,8 +74,8 @@ IEC61883Output::~IEC61883Output() done = 1; start_lock->unlock(); Thread::cancel(); - Thread::join(); } + Thread::join(); if(buffer) { diff --git a/cinelerra-5.1/cinelerra/levelwindow.C b/cinelerra-5.1/cinelerra/levelwindow.C index f6a4de01..11a74d7a 100644 --- a/cinelerra-5.1/cinelerra/levelwindow.C +++ b/cinelerra-5.1/cinelerra/levelwindow.C @@ -35,8 +35,8 @@ LevelWindow::~LevelWindow() { if(gui && running()) { gui->set_done(0); - join(); } + join(); delete gui; gui = 0; } diff --git a/cinelerra-5.1/cinelerra/mainundo.C b/cinelerra-5.1/cinelerra/mainundo.C index e688a06e..668a301a 100644 --- a/cinelerra-5.1/cinelerra/mainundo.C +++ b/cinelerra-5.1/cinelerra/mainundo.C @@ -305,6 +305,7 @@ int MainUndo::load_from_undo(FileXML *file, uint32_t load_flags) mwindow->mainindexes->add_next_asset(0, nested_edl); } mwindow->mainindexes->start_build(); + mwindow->update_plugin_guis(1); return 0; } diff --git a/cinelerra-5.1/cinelerra/mwindow.C b/cinelerra-5.1/cinelerra/mwindow.C index d9e916ef..f53dc4d6 100644 --- a/cinelerra-5.1/cinelerra/mwindow.C +++ b/cinelerra-5.1/cinelerra/mwindow.C @@ -3197,6 +3197,7 @@ int MWindow::run_script(FileXML *script) int MWindow::interrupt_indexes() { + mainprogress->cancelled = 1; mainindexes->interrupt_build(); return 0; } diff --git a/cinelerra-5.1/cinelerra/pluginfclient.C b/cinelerra-5.1/cinelerra/pluginfclient.C index 2a222cbe..1bea7dd0 100644 --- a/cinelerra-5.1/cinelerra/pluginfclient.C +++ b/cinelerra-5.1/cinelerra/pluginfclient.C @@ -521,6 +521,7 @@ PluginFClient::PluginFClient(PluginClient *plugin, const char *name) PluginFClient::~PluginFClient() { + delete ffilt; } bool PluginFClient::is_audio(AVFilter *fp) diff --git a/cinelerra-5.1/cinelerra/recordgui.C b/cinelerra-5.1/cinelerra/recordgui.C index be290b3e..64e2984f 100644 --- a/cinelerra-5.1/cinelerra/recordgui.C +++ b/cinelerra-5.1/cinelerra/recordgui.C @@ -1044,8 +1044,8 @@ EndRecordThread::~EndRecordThread() window->lock_window("EndRecordThread::~EndRecordThread"); window->set_done(1); window->unlock_window(); - Thread::join(); } + Thread::join(); } void EndRecordThread::start(int is_ok) @@ -1081,8 +1081,8 @@ RecordStartoverThread::~RecordStartoverThread() window->lock_window("RecordStartoverThread::~RecordStartoverThread"); window->set_done(1); window->unlock_window(); - Thread::join(); } + Thread::join(); } void RecordStartoverThread::run() @@ -1382,8 +1382,8 @@ RecordStatusThread::~RecordStatusThread() { done = 1; input_lock->unlock(); - Thread::join(); } + Thread::join(); } void RecordStatusThread::reset_video() @@ -1537,8 +1537,8 @@ RecordGUIFlash:: done = 1; flash_lock->unlock(); Thread::cancel(); - Thread::join(); } + Thread::join(); delete flash_lock; } diff --git a/cinelerra-5.1/cinelerra/remotecontrol.C b/cinelerra-5.1/cinelerra/remotecontrol.C index 5cd0f7eb..23dc4c45 100644 --- a/cinelerra-5.1/cinelerra/remotecontrol.C +++ b/cinelerra-5.1/cinelerra/remotecontrol.C @@ -41,8 +41,8 @@ RemoteControl::~RemoteControl() { if( Thread::running() ) { remote_window->close(1); - Thread::join(); } + Thread::join(); delete gui; delete remote_window; delete active_lock; diff --git a/cinelerra-5.1/cinelerra/resourcethread.C b/cinelerra-5.1/cinelerra/resourcethread.C index c14bf27b..6aa27b99 100644 --- a/cinelerra-5.1/cinelerra/resourcethread.C +++ b/cinelerra-5.1/cinelerra/resourcethread.C @@ -338,8 +338,8 @@ void ResourceThread::stop() done = 1; interrupted = 1; draw_lock->unlock(); - join(); } + join(); } diff --git a/cinelerra-5.1/cinelerra/setformat.C b/cinelerra-5.1/cinelerra/setformat.C index 17550381..ef0d3000 100644 --- a/cinelerra-5.1/cinelerra/setformat.C +++ b/cinelerra-5.1/cinelerra/setformat.C @@ -94,8 +94,8 @@ SetFormatThread::~SetFormatThread() if( running() ) { window->set_done(1); cancel(); - join(); } + join(); delete window_lock; } diff --git a/cinelerra-5.1/cinelerra/swindow.C b/cinelerra-5.1/cinelerra/swindow.C index 65799c4b..bacf80d7 100644 --- a/cinelerra-5.1/cinelerra/swindow.C +++ b/cinelerra-5.1/cinelerra/swindow.C @@ -342,8 +342,9 @@ int SWindowGUI::load_selection(int pos, int row) script_entry->set_text_row(0); } script_text_no = row; - char line[BCTEXTLEN], *bp = line, *cp = rp; - while( *cp && *cp!='\n' ) *bp++ = *cp++; + char line[BCTEXTLEN], *bp = line; + char *ep = bp+sizeof(line)-1, *cp = rp; + while( bp < ep && *cp && *cp!='\n' ) *bp++ = *cp++; *bp = 0; bp = texts->text; int char1 = rp-bp, char2 = cp-bp; script_entry->set_selection(char1, char2, char2); @@ -602,15 +603,15 @@ int ScriptLines::break_lines() memmove(cp,sp,dp+1-sp); used -= n; dp -= n; ep -= n; } - // constrain line_limit - if( (n=(ep-cp)/2) < limit2 || n > line_limit ) + // target about half remaining line, constrain line_limit + if( (n=(ep-1-cp)/2) < limit2 || n > line_limit ) n = line_limit; - // search for last punct, last space + // search for last punct, last space before line_limit for( bp=cp, pp=sp=0; --n>=0 && cp= limit4 ) @@ -731,10 +732,10 @@ int SWindowGUI::load_script_line(FILE *fp) for(;;) { // load non-blank lines //int len = strlen(line); - //if( cp[len-1] == '\n' ) cp[len-1] = 0; + //if( line[len-1] == '\n' ) line[len-1] = ' '; entry->append(line); char *cp = fgets(line,sizeof(line),fp); - if( !cp ) return 1; + if( !cp ) break; ++script_line_no; while( *cp && isspace(*cp) ) ++cp; if( !*cp ) break; @@ -852,8 +853,8 @@ void SWindow::stop() if( gui ) gui->stop(1); window_lock->unlock(); Thread::cancel(); - Thread::join(); } + Thread::join(); } void SWindow::run() diff --git a/cinelerra-5.1/cinelerra/tracking.C b/cinelerra-5.1/cinelerra/tracking.C index 1ca59993..b2094970 100644 --- a/cinelerra-5.1/cinelerra/tracking.C +++ b/cinelerra-5.1/cinelerra/tracking.C @@ -64,9 +64,8 @@ Tracking::~Tracking() state = DONE; // Not working in NPTL for some reason // Thread::cancel(); - Thread::join(); } - + Thread::join(); delete startup_lock; } diff --git a/cinelerra-5.1/cinelerra/vdevicebuz.C b/cinelerra-5.1/cinelerra/vdevicebuz.C index e3c46812..1213f554 100644 --- a/cinelerra-5.1/cinelerra/vdevicebuz.C +++ b/cinelerra-5.1/cinelerra/vdevicebuz.C @@ -79,8 +79,8 @@ VDeviceBUZInput::~VDeviceBUZInput() { done = 1; Thread::cancel(); - Thread::join(); } + Thread::join(); if(buffer) { diff --git a/cinelerra-5.1/cinelerra/videowindow.C b/cinelerra-5.1/cinelerra/videowindow.C index 76179b3b..ac640a20 100644 --- a/cinelerra-5.1/cinelerra/videowindow.C +++ b/cinelerra-5.1/cinelerra/videowindow.C @@ -45,8 +45,8 @@ VideoWindow::~VideoWindow() { if(gui && running()) { gui->set_done(0); - join(); } + join(); delete gui; gui = 0; } diff --git a/cinelerra-5.1/guicast/bcclipboard.C b/cinelerra-5.1/guicast/bcclipboard.C index 70437218..c91c51fe 100644 --- a/cinelerra-5.1/guicast/bcclipboard.C +++ b/cinelerra-5.1/guicast/bcclipboard.C @@ -90,7 +90,7 @@ int BC_Clipboard::stop_clipboard() #endif // Must use a different display handle to send events. Display *display = BC_WindowBase::init_display(display_name); - XEvent event; + XEvent event; memset(&event, 0, sizeof(event)); XClientMessageEvent *ptr = (XClientMessageEvent*)&event; event.type = ClientMessage; @@ -175,7 +175,7 @@ void BC_Clipboard::handle_selectionrequest(XSelectionRequestEvent *request) else if (request->target == targets_atom) success = handle_request_targets(request); - XEvent reply; + XEvent reply; memset(&reply, 0, sizeof(reply)); // 'None' tells the client that the request was denied reply.xselection.property = success ? request->property : None; reply.xselection.type = SelectionNotify; diff --git a/cinelerra-5.1/guicast/bcdragwindow.C b/cinelerra-5.1/guicast/bcdragwindow.C index 16a38c4f..b7ec98e2 100644 --- a/cinelerra-5.1/guicast/bcdragwindow.C +++ b/cinelerra-5.1/guicast/bcdragwindow.C @@ -46,6 +46,7 @@ BC_DragWindow::BC_DragWindow(BC_WindowBase *parent_window, pixmap) { temp_frame = 0; + drag_pixmap = 0; // init_x = icon_x; // init_y = icon_y; init_x = parent_window->get_abs_cursor_x(0) + DRAG_OFFSET_X; @@ -90,6 +91,7 @@ BC_DragWindow::BC_DragWindow(BC_WindowBase *parent_window, BC_DragWindow::~BC_DragWindow() { + delete drag_pixmap; } int BC_DragWindow::get_init_x(BC_WindowBase *parent_window, int icon_x) @@ -202,11 +204,11 @@ BC_Pixmap *BC_DragWindow::prepare_frame(VFrame *frame, BC_WindowBase *parent_win 0, frame->get_w(), temp_frame->get_w()); } temp_frame->get_rows()[(temp_frame->get_h() / 2)][(temp_frame->get_w() / 2) * 4 + 3] = 0; - my_pixmap = new BC_Pixmap(parent_window, + drag_pixmap = new BC_Pixmap(parent_window, temp_frame, PIXMAP_ALPHA); - return (my_pixmap); + return drag_pixmap; } diff --git a/cinelerra-5.1/guicast/bcdragwindow.h b/cinelerra-5.1/guicast/bcdragwindow.h index 2d9288fc..c3b7c6e6 100644 --- a/cinelerra-5.1/guicast/bcdragwindow.h +++ b/cinelerra-5.1/guicast/bcdragwindow.h @@ -48,7 +48,7 @@ private: int icon_offset_x, icon_offset_y; int do_animation; VFrame *temp_frame; - BC_Pixmap *my_pixmap; + BC_Pixmap *drag_pixmap; }; #endif diff --git a/cinelerra-5.1/guicast/bclistbox.C b/cinelerra-5.1/guicast/bclistbox.C index b48847ba..c78af1a6 100644 --- a/cinelerra-5.1/guicast/bclistbox.C +++ b/cinelerra-5.1/guicast/bclistbox.C @@ -389,13 +389,9 @@ BC_ListBox::BC_ListBox(int x, popup_w = w; popup_h = h; - for(int i = 0; i < 3; i++) - { - button_images[i] = 0; - column_bg[i] = 0; - } - for(int i = 0; i < 5; i++) - toggle_images[i] = 0; + for(int i = 0; i < 3; i++) column_bg[i] = 0; + for(int i = 0; i < 4; i++) button_images[i] = 0; + for(int i = 0; i < 5; i++) toggle_images[i] = 0; column_sort_up = 0; column_sort_dn = 0; @@ -447,13 +443,9 @@ BC_ListBox::~BC_ListBox() if(bg_pixmap) delete bg_pixmap; if(xscrollbar) delete xscrollbar; if(yscrollbar) delete yscrollbar; - for(int i = 0; i < 3; i++) - { - if(button_images[i]) delete button_images[i]; - if(column_bg[i]) delete column_bg[i]; - } - for(int i = 0; i < 5; i++) - if(toggle_images[i]) delete toggle_images[i]; + for(int i = 0; i < 3; i++) delete column_bg[i]; + for(int i = 0; i < 4; i++) delete button_images[i]; + for(int i = 0; i < 5; i++) delete toggle_images[i]; if(column_sort_up) delete column_sort_up; if(column_sort_dn) delete column_sort_dn; @@ -550,7 +542,7 @@ int BC_ListBox::initialize() { if(use_button) { - for( volatile int i = 0; i < 4; ++i ) // volatile due to cplr bug + for( int i = 0; i < 4; ++i ) { button_images[i] = new BC_Pixmap(parent_window, BC_WindowBase::get_resources()->listbox_button[i], diff --git a/cinelerra-5.1/guicast/bclistbox.h b/cinelerra-5.1/guicast/bclistbox.h index 8100adfd..73c5ddb3 100644 --- a/cinelerra-5.1/guicast/bclistbox.h +++ b/cinelerra-5.1/guicast/bclistbox.h @@ -534,7 +534,7 @@ private: // Popup button - BC_Pixmap *button_images[3]; + BC_Pixmap *button_images[4]; // Expander BC_Pixmap *toggle_images[5]; // Background for drawing on diff --git a/cinelerra-5.1/guicast/bcprogressbox.C b/cinelerra-5.1/guicast/bcprogressbox.C index 69cc52b1..ac49c98a 100644 --- a/cinelerra-5.1/guicast/bcprogressbox.C +++ b/cinelerra-5.1/guicast/bcprogressbox.C @@ -97,8 +97,8 @@ int BC_ProgressBox::stop_progress() { if( Thread::running() ) { pwindow->set_done(0); - Thread::join(); } + Thread::join(); return 0; } diff --git a/cinelerra-5.1/guicast/bcsynchronous.C b/cinelerra-5.1/guicast/bcsynchronous.C index 35d4a1c1..54f5eec2 100644 --- a/cinelerra-5.1/guicast/bcsynchronous.C +++ b/cinelerra-5.1/guicast/bcsynchronous.C @@ -119,8 +119,8 @@ BC_Synchronous::~BC_Synchronous() { if( running() ) { quit(); - join(); } + join(); commands.remove_all_objects(); delete lock_sync; delete next_command; diff --git a/cinelerra-5.1/guicast/bcwindowbase.C b/cinelerra-5.1/guicast/bcwindowbase.C index 389670c3..67226174 100644 --- a/cinelerra-5.1/guicast/bcwindowbase.C +++ b/cinelerra-5.1/guicast/bcwindowbase.C @@ -101,15 +101,20 @@ BC_WindowBase::~BC_WindowBase() #endif #ifdef HAVE_LIBXXF86VM - if(window_type == VIDMODE_SCALED_WINDOW && vm_switched) - { - restore_vm(); - } + if(window_type == VIDMODE_SCALED_WINDOW && vm_switched) { + restore_vm(); + } #endif + is_deleting = 1; hide_tooltip(); if(window_type != MAIN_WINDOW) { +// stop event input + XSelectInput(top_level->display, this->win, 0); + motion_events = resize_events = translation_events = 0; + top_level->dequeue_events(win); + if(top_level->active_menubar == this) top_level->active_menubar = 0; if(top_level->active_popup_menu == this) top_level->active_popup_menu = 0; if(top_level->active_subwindow == this) top_level->active_subwindow = 0; @@ -118,10 +123,10 @@ BC_WindowBase::~BC_WindowBase() } if(icon_window) delete icon_window; - if(window_type == POPUP_WINDOW) parent_window->remove_popup(this); + if(window_type == POPUP_WINDOW) + parent_window->remove_popup(this); // Delete the subwindows - is_deleting = 1; if(subwindows) { while(subwindows->total) @@ -338,6 +343,7 @@ int BC_WindowBase::initialize() glx_win = 0; #endif + win = 0; return 0; } @@ -1962,12 +1968,9 @@ Atom BC_WindowBase::create_xatom(const char *atom_name) int BC_WindowBase::get_atoms() { - SetDoneXAtom = create_xatom("BC_REPEAT_EVENT"); - RepeaterXAtom = create_xatom("BC_CLOSE_EVENT"); - DelWinXAtom = create_xatom("WM_DELETE_WINDOW"); - ProtoXAtom = create_xatom("WM_PROTOCOLS"); SetDoneXAtom = XInternAtom(display, "BC_REPEAT_EVENT", False); RepeaterXAtom = XInternAtom(display, "BC_CLOSE_EVENT", False); + DestroyAtom = XInternAtom(display, "BC_DESTROY_WINDOW", False); DelWinXAtom = XInternAtom(display, "WM_DELETE_WINDOW", False); if( (ProtoXAtom = XInternAtom(display, "WM_PROTOCOLS", False)) != 0 ) XChangeProperty(display, win, ProtoXAtom, XA_ATOM, 32, @@ -4351,6 +4354,20 @@ void BC_WindowBase::put_event(XEvent *event) event_condition->unlock(); } +void BC_WindowBase::dequeue_events(Window win) +{ + event_lock->lock("BC_WindowBase::dequeue_events"); + + int out = 0, total = common_events.size(); + for( int in=0; inxany.window == win ) continue; + common_events[out++] = common_events[in]; + } + common_events.total = out; + + event_lock->unlock(); +} + #endif // SINGLE_THREAD int BC_WindowBase::get_id() diff --git a/cinelerra-5.1/guicast/bcwindowbase.h b/cinelerra-5.1/guicast/bcwindowbase.h index af271e49..4d0e4567 100644 --- a/cinelerra-5.1/guicast/bcwindowbase.h +++ b/cinelerra-5.1/guicast/bcwindowbase.h @@ -581,6 +581,8 @@ private: int get_event_count(); // Put event in common events. void put_event(XEvent *event); +// remove events queued for win + void dequeue_events(Window win); // Recursive event dispatchers int dispatch_resize_event(int w, int h); @@ -785,6 +787,7 @@ private: // Depth given by the X Server int default_depth; Atom DelWinXAtom; + Atom DestroyAtom; Atom ProtoXAtom; Atom RepeaterXAtom; Atom SetDoneXAtom; diff --git a/cinelerra-5.1/guicast/bcwindowevents.C b/cinelerra-5.1/guicast/bcwindowevents.C index 3d4dd5b4..2660c949 100644 --- a/cinelerra-5.1/guicast/bcwindowevents.C +++ b/cinelerra-5.1/guicast/bcwindowevents.C @@ -46,19 +46,16 @@ BC_WindowEvents::BC_WindowEvents(BC_Display *display) BC_WindowEvents::~BC_WindowEvents() { -// First set done, then send dummy event through XSendEvent to unlock the loop in ::run() +// no more external events, send one last event into X to flush out all of the +// pending events so that no straglers or shm leaks are possible. //printf("BC_WindowEvents::~BC_WindowEvents %d %s\n", __LINE__, window->title); - done = 1; - XEvent event; + XSelectInput(window->display, window->win, 0); + XEvent event; memset(&event,0,sizeof(event)); XClientMessageEvent *ptr = (XClientMessageEvent*)&event; event.type = ClientMessage; - ptr->message_type = XInternAtom(window->display, "DUMMY_XATOM", False); + ptr->message_type = window->DestroyAtom; ptr->format = 32; - XSendEvent(window->display, - window->win, - 0, - 0, - &event); + XSendEvent(window->display, window->win, 0, 0, &event); window->flush(); Thread::join(); //printf("BC_WindowEvents::~BC_WindowEvents %d %s\n", __LINE__, window->title); @@ -80,8 +77,6 @@ void BC_WindowEvents::run() int x_fd = ConnectionNumber(window->display); #endif - - while(!done) { @@ -90,7 +85,6 @@ void BC_WindowEvents::run() #ifdef SINGLE_THREAD event = new XEvent; XNextEvent(display->display, event); - display->put_event(event); #else // This came from a linuxquestions post. // We can get a file descriptor for the X display & use select instead of XNextEvent. @@ -107,20 +101,33 @@ void BC_WindowEvents::run() { event = new XEvent; XNextEvent(window->display, event); +#endif if( event->type == BC_WindowBase::shm_completion_event ) { - window->top_level->active_bitmaps.reque(event); + window->active_bitmaps.reque(event); delete event; continue; } + if( event->type == ClientMessage ) { + XClientMessageEvent *ptr = (XClientMessageEvent*)event; + if( ptr->message_type == window->DestroyAtom ) { + delete event; + done = 1; + break; + } + } +#ifndef SINGLE_THREAD // HACK: delay is required to get the close event - usleep(1); + yield(); //if(window && event) //printf("BC_WindowEvents::run %d %s %d\n", __LINE__, window->title, event->type); window->put_event(event); } XUnlockDisplay(window->display); //printf("BC_WindowEvents::run %d %s\n", __LINE__, window->title); +#else + display->put_event(event); #endif + } } diff --git a/cinelerra-5.1/guicast/rotateframe.C b/cinelerra-5.1/guicast/rotateframe.C index 2a2029ed..31ab44a1 100644 --- a/cinelerra-5.1/guicast/rotateframe.C +++ b/cinelerra-5.1/guicast/rotateframe.C @@ -408,8 +408,8 @@ RotateEngine::~RotateEngine() { done = 1; input_lock->unlock(); - join(); } + join(); delete input_lock; delete output_lock; } diff --git a/cinelerra-5.1/guicast/vicon.C b/cinelerra-5.1/guicast/vicon.C index 906fb6e9..deb3c57f 100644 --- a/cinelerra-5.1/guicast/vicon.C +++ b/cinelerra-5.1/guicast/vicon.C @@ -87,8 +87,8 @@ VIconThread:: draw_lock->unlock(); if( Thread::running() ) { Thread::cancel(); - Thread::join(); } + Thread::join(); t_heap.remove_all_objects(); delete timer; delete draw_lock;