diff --git a/src/viewer/scrollview.cpp b/src/viewer/scrollview.cpp index a9d887b3c9..55f30381a3 100644 --- a/src/viewer/scrollview.cpp +++ b/src/viewer/scrollview.cpp @@ -33,6 +33,7 @@ #include #include #include +#include // for std::unique_ptr #include // for std::mutex #include #include // for std::thread @@ -97,7 +98,7 @@ void ScrollView::MessageReceiver() { // the events accordingly. while (true) { // The new event we create. - auto *cur = new SVEvent; + std::unique_ptr cur(new SVEvent); // The ID of the corresponding window. int window_id; @@ -143,11 +144,12 @@ void ScrollView::MessageReceiver() { // In case of an SVET_EXIT event, quit the whole application. if (ev_type == SVET_EXIT) { - ScrollView::Exit(); + SendRawMessage("svmain:exit()"); + break; } // Place two copies of it in the table for the window. - cur->window->SetEvent(cur); + cur->window->SetEvent(cur.get()); // Check if any of the threads currently waiting want it. std::pair awaiting_list(cur->window, cur->type); @@ -156,17 +158,14 @@ void ScrollView::MessageReceiver() { SVET_ANY); waiting_for_events_mu->lock(); if (waiting_for_events.count(awaiting_list) > 0) { - waiting_for_events[awaiting_list].second = cur; + waiting_for_events[awaiting_list].second = cur.get(); waiting_for_events[awaiting_list].first->Signal(); } else if (waiting_for_events.count(awaiting_list_any) > 0) { - waiting_for_events[awaiting_list_any].second = cur; + waiting_for_events[awaiting_list_any].second = cur.get(); waiting_for_events[awaiting_list_any].first->Signal(); } else if (waiting_for_events.count(awaiting_list_any_window) > 0) { - waiting_for_events[awaiting_list_any_window].second = cur; + waiting_for_events[awaiting_list_any_window].second = cur.get(); waiting_for_events[awaiting_list_any_window].first->Signal(); - } else { - // No one wanted it, so delete it. - delete cur; } waiting_for_events_mu->unlock(); // Signal the corresponding semaphore twice (for both copies). @@ -175,8 +174,6 @@ void ScrollView::MessageReceiver() { sv->Signal(); sv->Signal(); } - } else { - delete cur; // Applied to no window. } svmap_mu->unlock();