Dependent items clearing done better

Fixed crash on launch if audio playback could not be started
This commit is contained in:
John Preston 2016-03-25 23:46:35 +03:00
parent 40ab82e4bd
commit 29c6b8e2d2
3 changed files with 14 additions and 11 deletions

View File

@ -67,7 +67,8 @@ namespace {
SharedContactItems sharedContactItems; SharedContactItems sharedContactItems;
GifItems gifItems; GifItems gifItems;
typedef QMap<HistoryItem*, OrderedSet<HistoryItem*> > DependentItems; typedef OrderedSet<HistoryItem*> DependentItemsSet;
typedef QMap<HistoryItem*, DependentItemsSet> DependentItems;
DependentItems dependentItems; DependentItems dependentItems;
Histories histories; Histories histories;
@ -1803,10 +1804,13 @@ namespace App {
historyItemDetached(item); historyItemDetached(item);
auto j = ::dependentItems.find(item); auto j = ::dependentItems.find(item);
if (j != ::dependentItems.cend()) { if (j != ::dependentItems.cend()) {
for_const (HistoryItem *dependent, j.value()) { DependentItemsSet items;
std::swap(items, j.value());
::dependentItems.erase(j);
for_const (HistoryItem *dependent, items) {
dependent->dependencyItemRemoved(item); dependent->dependencyItemRemoved(item);
} }
::dependentItems.erase(j);
} }
if (App::main() && !App::quitting()) { if (App::main() && !App::quitting()) {
App::main()->itemRemoved(item); App::main()->itemRemoved(item);
@ -1903,7 +1907,7 @@ namespace App {
} }
void historyUnregDependency(HistoryItem *dependent, HistoryItem *dependency) { void historyUnregDependency(HistoryItem *dependent, HistoryItem *dependency) {
DependentItems::iterator i = ::dependentItems.find(dependency); auto i = ::dependentItems.find(dependency);
if (i != ::dependentItems.cend()) { if (i != ::dependentItems.cend()) {
i.value().remove(dependent); i.value().remove(dependent);
if (i.value().isEmpty()) { if (i.value().isEmpty()) {

View File

@ -227,12 +227,15 @@ void audioPlayNotify() {
emit audioPlayer()->faderOnTimer(); emit audioPlayer()->faderOnTimer();
} }
// can be called at any moment when audio error
void audioFinish() { void audioFinish() {
if (player) { if (player) {
deleteAndMark(player); delete player;
player = nullptr;
} }
if (capture) { if (capture) {
deleteAndMark(capture); delete capture;
capture = nullptr;
} }
alSourceStop(notifySource); alSourceStop(notifySource);

View File

@ -6096,11 +6096,7 @@ void HistoryMessageReply::resize(int width) const {
void HistoryMessageReply::itemRemoved(HistoryMessage *holder, HistoryItem *removed) { void HistoryMessageReply::itemRemoved(HistoryMessage *holder, HistoryItem *removed) {
if (replyToMsg == removed) { if (replyToMsg == removed) {
delete _replyToVia; clearData(holder);
_replyToVia = nullptr;
replyToMsg = nullptr;
replyToMsgId = 0;
holder->setPendingInitDimensions(); holder->setPendingInitDimensions();
} }
} }