Calling a timed function from wxDialog derived class, Event crash.[Solved]

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
experimental-design
Earned a small fee
Earned a small fee
Posts: 17
Joined: Mon May 27, 2019 7:37 pm

Calling a timed function from wxDialog derived class, Event crash.[Solved]

Post by experimental-design » Mon Jan 27, 2020 5:31 am

My program crashes after running a process after the second time a button is clicked on.
The backtrace shows that it is related to event processing.

Backtrace:
#0 0x00007ffff576e78c in _XEnq () at /usr/lib/libX11.so.6
#1 0x00007ffff576b448 in () at /usr/lib/libX11.so.6
#2 0x00007ffff576bd8a in _XEventsQueued () at /usr/lib/libX11.so.6
#3 0x00007ffff575d782 in XPending () at /usr/lib/libX11.so.6
#4 0x00007ffff5becd97 in () at /usr/lib/libgdk-x11-2.0.so.0
#5 0x00007ffff58d6a00 in g_main_context_prepare () at /usr/lib/libglib-2.0.so.0
#6 0x00007ffff58d7046 in () at /usr/lib/libglib-2.0.so.0
#7 0x00007ffff58d729a in g_main_context_pending () at /usr/lib/libglib-2.0.so.0
#8 0x00007ffff5f75fea in gtk_events_pending () at /usr/lib/libgtk-x11-2.0.so.0
#9 0x00007ffff7bb0786 in wxApp::DoIdle() () at /usr/lib/libwx_gtk2u_core-3.0.so.0
#10 0x00007ffff7bb08b4 in () at /usr/lib/libwx_gtk2u_core-3.0.so.0
#11 0x00007ffff58d526f in g_main_context_dispatch () at /usr/lib/libglib-2.0.so.0
#12 0x00007ffff58d71b1 in () at /usr/lib/libglib-2.0.so.0
#13 0x00007ffff58d80c3 in g_main_loop_run () at /usr/lib/libglib-2.0.so.0
#14 0x00007ffff5f75df3 in gtk_main () at /usr/lib/libgtk-x11-2.0.so.0
#15 0x00007ffff7bce1b6 in wxGUIEventLoop::DoRun() () at /usr/lib/libwx_gtk2u_core-3.0.so.0
#16 0x00007ffff7762bae in wxEventLoopBase::Run() () at /usr/lib/libwx_baseu-3.0.so.0
#17 0x00007ffff7c378f1 in wxDialog::ShowModal() () at /usr/lib/libwx_gtk2u_core-3.0.so.0
#18 0x0000555555649e56 in CreateStandardReverbZoneDialog::CreateStandardReverbZoneDialog(wxString const&, EffectsManager*)
(this=0x555555effb20, title=..., effects_manager=0x555555c91300)
at /home/pab/CodeProj/cxx_projects/binaural-audio-editor/src/CreateStandardReverbZoneDialog.cpp:298
#19 0x000055555562d923 in MainFrame::OnCreateStandardReverbZone(wxCommandEvent&) (this=0x555555826bf0, event=...)
at /home/pab/CodeProj/cxx_projects/binaural-audio-editor/src/osgViewerWX.cpp:808
#20 0x00007ffff789589e in wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) ()
at /usr/lib/libwx_baseu-3.0.so.0
#21 0x00007ffff78959a4 in wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*) () at /usr/lib/libwx_baseu-3.0.so.0
#22 0x00007ffff7895cde in wxEvtHandler::TryHereOnly(wxEvent&) () at /usr/lib/libwx_baseu-3.0.so.0
#23 0x00007ffff7895d64 in wxEvtHandler::ProcessEventLocally(wxEvent&) () at /usr/lib/libwx_baseu-3.0.so.0
#24 0x00007ffff7895e02 in wxEvtHandler::ProcessEvent(wxEvent&) () at /usr/lib/libwx_baseu-3.0.so.0
#25 0x00007ffff7d9ee6b in wxWindowBase::TryAfter(wxEvent&) () at /usr/lib/libwx_gtk2u_core-3.0.so.0
#26 0x00007ffff7895ba7 in wxEvtHandler::SafelyProcessEvent(wxEvent&) () at /usr/lib/libwx_baseu-3.0.so.0
#27 0x00007ffff7d554ea in wxMenuBase::SendEvent(int, int) () at /usr/lib/libwx_gtk2u_core-3.0.so.0
#28 0x00007ffff7c4e6dc in () at /usr/lib/libwx_gtk2u_core-3.0.so.0
#29 0x00007ffff59c1d5a in g_closure_invoke () at /usr/lib/libgobject-2.0.so.0
#30 0x00007ffff59af88e in () at /usr/lib/libgobject-2.0.so.0
#31 0x00007ffff59b398a in g_signal_emit_valist () at /usr/lib/libgobject-2.0.so.0
#32 0x00007ffff59b47f0 in g_signal_emit () at /usr/lib/libgobject-2.0.so.0
#33 0x00007ffff6091f38 in gtk_widget_activate () at /usr/lib/libgtk-x11-2.0.so.0
#34 0x00007ffff5f8ae71 in gtk_menu_shell_activate_item () at /usr/lib/libgtk-x11-2.0.so.0
#35 0x00007ffff5f8b140 in () at /usr/lib/libgtk-x11-2.0.so.0
#36 0x00007ffff5f787cc in () at /usr/lib/libgtk-x11-2.0.so.0
#37 0x00007ffff59c1d5a in g_closure_invoke () at /usr/lib/libgobject-2.0.so.0
#38 0x00007ffff59aeff8 in () at /usr/lib/libgobject-2.0.so.0
#39 0x00007ffff59b2f1c in g_signal_emit_valist () at /usr/lib/libgobject-2.0.so.0
#40 0x00007ffff59b47f0 in g_signal_emit () at /usr/lib/libgobject-2.0.so.0
#41 0x00007ffff6093235 in () at /usr/lib/libgtk-x11-2.0.so.0
#42 0x00007ffff5f76a0e in gtk_propagate_event () at /usr/lib/libgtk-x11-2.0.so.0
#43 0x00007ffff5f76e43 in gtk_main_do_event () at /usr/lib/libgtk-x11-2.0.so.0
#44 0x00007ffff5befd5e in () at /usr/lib/libgdk-x11-2.0.so.0
#45 0x00007ffff58d539e in g_main_context_dispatch () at /usr/lib/libglib-2.0.so.0
#46 0x00007ffff58d71b1 in () at /usr/lib/libglib-2.0.so.0
#47 0x00007ffff58d80c3 in g_main_loop_run () at /usr/lib/libglib-2.0.so.0
#48 0x00007ffff5f75df3 in gtk_main () at /usr/lib/libgtk-x11-2.0.so.0
#49 0x00007ffff7bce1b6 in wxGUIEventLoop::DoRun() () at /usr/lib/libwx_gtk2u_core-3.0.so.0
#50 0x00007ffff7762bae in wxEventLoopBase::Run() () at /usr/lib/libwx_baseu-3.0.so.0
#51 0x00007ffff7727517 in wxAppConsoleBase::MainLoop() () at /usr/lib/libwx_baseu-3.0.so.0
#52 0x00007ffff77af4c8 in wxEntry(int&, wchar_t**) () at /usr/lib/libwx_baseu-3.0.so.0
#53 0x0000555555629134 in main(int, char**) (argc=1, argv=0x7fffffffe3e8)

How button is initialized:
previewButton = new wxButton(this, wxID_ANY, wxT("Preview"),
wxDefaultPosition, wxSize(70, 30));

previewButton->Bind(wxEVT_BUTTON,&CreateStandardReverbZoneDialog::OnPreview,this);
What button does when clicked:
void CreateStandardReverbZoneDialog::OnPreview(wxCommandEvent& event)
{
//Create temporary reverb effect

//apply effect to track

//play track for a few seconds

long endtime = ::wxGetLocalTime()+10; //10 second limit
while( ::wxGetLocalTime() < endtime )
{
//play track
}

//stop track

//remove effect from sound producer track
}
Full Code: https://github.com/adct-the-experimente ... Dialog.cpp

Does anyone have an idea of what could be causing this or how to fix it? Maybe someone could point me to the right direction on how to solve this?

I also have a separate thread running in the program.
Last edited by experimental-design on Wed Jan 29, 2020 9:03 pm, edited 1 time in total.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2378
Joined: Sun Jan 03, 2010 5:45 pm

Re: Calling a timed function from wxDialog derived class, Event crash.

Post by PB » Mon Jan 27, 2020 6:34 am

For starters, if you remove the code doing things from the button handler, does it still crash? If so, then the issue is within the removed code and not handling the event.

The code in the event handler you posted looks odd though. It appears as if you are blocking the UI for at least 10 seconds with the while loop, which does not make sense. I assume you are not trying to do that from the secondary thread, but perhaps you are doing something there (giving control back to the UI) which leads to some kind of reentrancy?

User avatar
doublemax
Moderator
Moderator
Posts: 14782
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Calling a timed function from wxDialog derived class, Event crash.

Post by doublemax » Mon Jan 27, 2020 7:55 am

Does the crash happen when you click the preview button a second time while the sound is still playing or even if you click it much later?

Code: Select all

while( ::wxGetLocalTime() < endtime )
{
  m_effects_manager_ptr->m_track_manager_ptr->PlayThisTrackFromSoundProducerTrackVector(spt_selection_index);
}
Is this really correct?

I would have expected something like:

Code: Select all

m_effects_manager_ptr->m_track_manager_ptr->PlayThisTrackFromSoundProducerTrackVector(spt_selection_index);
while( ::wxGetLocalTime() < endtime )
{
  ::wxMilliSleep(10);
}
And, as PB already said, tight loops like this that block the GUI should be avoided. But i don't think that's the cause for the crash.

I don't know if it's relevant for the crash, but the correct way to close a modal dialog is by calling EndModal().
Use the source, Luke!

experimental-design
Earned a small fee
Earned a small fee
Posts: 17
Joined: Mon May 27, 2019 7:37 pm

Re: Calling a timed function from wxDialog derived class, Event crash.

Post by experimental-design » Tue Jan 28, 2020 6:46 pm

Thanks for your help. I resolved the issue.

I put the code that plays a track outside of the while loop since it did not need to be there.

Strangely, what seems to have fixed the problem was changing OpenAL Soft specific code to pause audio playback instead of stopping the audio playback when called when preview button is clicked.
It was the code in the handler causing the issue.

Somehow this may have caused problems for wxwidgets events.

The program does not crash anymore from clicking on the preview button more than once.

Post Reply