From e492b1e93ddcebb72fc80066afd2294a2802fe22 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 14 Feb 2016 18:58:39 +0300 Subject: [PATCH] some crashes fixed --- Telegram/SourceFiles/app.cpp | 2 +- Telegram/SourceFiles/application.cpp | 38 ++++++++++++++----------- Telegram/SourceFiles/application.h | 2 +- Telegram/SourceFiles/dialogswidget.cpp | 11 ++++--- Telegram/SourceFiles/gui/animation.cpp | 6 ++-- Telegram/SourceFiles/historywidget.cpp | 6 ++-- Telegram/SourceFiles/mainwidget.cpp | 2 +- Telegram/SourceFiles/overviewwidget.cpp | 9 +++--- Telegram/SourceFiles/structs.cpp | 4 ++- 9 files changed, 47 insertions(+), 33 deletions(-) diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index d36731ff7..9002e8aed 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -2469,7 +2469,7 @@ namespace App { QString phoneFromSharedContact(int32 userId) { SharedContactItems::const_iterator i = ::sharedContactItems.constFind(userId); - if (i != ::sharedContactItems.cend()) { + if (i != ::sharedContactItems.cend() && !i->isEmpty()) { HistoryMedia *media = i->cbegin().key()->getMedia(); if (media && media->type() == MediaTypeContact) { return static_cast(media)->phone(); diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index 41d26b0a7..1f8c6a8b5 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -689,6 +689,8 @@ namespace Sandbox { } AppClass::AppClass() : QObject() +, _lastActionTime(0) +, _window(0) , _uploader(0) , _translator(0) { AppObject = this; @@ -749,20 +751,21 @@ AppClass::AppClass() : QObject() application()->installNativeEventFilter(psNativeEventFilter()); - Sandbox::connect(SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(onAppStateChanged(Qt::ApplicationState))); + cChangeTimeFormat(QLocale::system().timeFormat(QLocale::ShortFormat)); connect(&_mtpUnpauseTimer, SIGNAL(timeout()), this, SLOT(doMtpUnpause())); connect(&killDownloadSessionsTimer, SIGNAL(timeout()), this, SLOT(killDownloadSessions())); - cChangeTimeFormat(QLocale::system().timeFormat(QLocale::ShortFormat)); - DEBUG_LOG(("Application Info: starting app..")); QMimeDatabase().mimeTypeForName(qsl("text/plain")); // create mime database - _window.createWinId(); - _window.init(); + _window = new Window(); + _window->createWinId(); + _window->init(); + + Sandbox::connect(SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(onAppStateChanged(Qt::ApplicationState))); DEBUG_LOG(("Application Info: window created..")); @@ -785,18 +788,18 @@ AppClass::AppClass() : QObject() DEBUG_LOG(("Application Info: showing.")); if (state == Local::ReadMapPassNeeded) { - _window.setupPasscode(false); + _window->setupPasscode(false); } else { if (MTP::authedId()) { - _window.setupMain(false); + _window->setupMain(false); } else { - _window.setupIntro(false); + _window->setupIntro(false); } } - _window.firstShow(); + _window->firstShow(); if (cStartToSettings()) { - _window.showSettings(); + _window->showSettings(); } QNetworkProxyFactory::setUseSystemConfiguration(true); @@ -805,7 +808,7 @@ AppClass::AppClass() : QObject() checkMapVersion(); } - _window.updateIsActive(cOnlineFocusTimeout()); + _window->updateIsActive(cOnlineFocusTimeout()); } void AppClass::regPhotoUpdate(const PeerId &peer, const FullMsgId &msgId) { @@ -922,7 +925,7 @@ void AppClass::checkLocalTime() { void AppClass::onAppStateChanged(Qt::ApplicationState state) { checkLocalTime(); - _window.updateIsActive((state == Qt::ApplicationActive) ? cOnlineFocusTimeout() : cOfflineBlurTimeout()); + _window->updateIsActive((state == Qt::ApplicationActive) ? cOnlineFocusTimeout() : cOfflineBlurTimeout()); } void AppClass::killDownloadSessions() { @@ -1058,7 +1061,7 @@ void AppClass::checkMapVersion() { } if (!versionFeatures.isEmpty()) { versionFeatures = lng_new_version_wrap(lt_version, QString::fromStdWString(AppVersionStr), lt_changes, versionFeatures, lt_link, qsl("https://desktop.telegram.org/#changelog")); - _window.serviceNotification(versionFeatures); + _window->serviceNotification(versionFeatures); } } } @@ -1068,7 +1071,10 @@ void AppClass::checkMapVersion() { } AppClass::~AppClass() { - _window.setParent(0); + if (Window *w = _window) { + _window = 0; + delete w; + } anim::stopManager(); stopWebLoadManager(); @@ -1097,9 +1103,9 @@ AppClass *AppClass::app() { } Window *AppClass::wnd() { - return AppObject ? &AppObject->_window : 0; + return AppObject ? AppObject->_window : 0; } MainWidget *AppClass::main() { - return AppObject ? AppObject->_window.mainWidget() : 0; + return (AppObject && AppObject->_window) ? AppObject->_window->mainWidget() : 0; } diff --git a/Telegram/SourceFiles/application.h b/Telegram/SourceFiles/application.h index c5a11080f..d823ab1f2 100644 --- a/Telegram/SourceFiles/application.h +++ b/Telegram/SourceFiles/application.h @@ -208,7 +208,7 @@ private: uint64 _lastActionTime; - Window _window; + Window *_window; FileUploader *_uploader; Translator *_translator; diff --git a/Telegram/SourceFiles/dialogswidget.cpp b/Telegram/SourceFiles/dialogswidget.cpp index ca7b364e0..e7a700bd3 100644 --- a/Telegram/SourceFiles/dialogswidget.cpp +++ b/Telegram/SourceFiles/dialogswidget.cpp @@ -1040,13 +1040,16 @@ bool DialogsInner::searchReceived(const QVector &messages, DialogsSe _lastSearchDate = lastDateFound; } } - if (type == DialogsSearchFromStart || type == DialogsSearchFromOffset) { - _lastSearchPeer = item->history()->peer; + if (item) { + if (type == DialogsSearchFromStart || type == DialogsSearchFromOffset) { + _lastSearchPeer = item->history()->peer; + } } + MsgId msgId = item ? item->id : idFromMessage(*i); if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) { - _lastSearchMigratedId = item->id; + _lastSearchMigratedId = msgId; } else { - _lastSearchId = item->id; + _lastSearchId = msgId; } } if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) { diff --git a/Telegram/SourceFiles/gui/animation.cpp b/Telegram/SourceFiles/gui/animation.cpp index 98d756bb0..c5c1e02c4 100644 --- a/Telegram/SourceFiles/gui/animation.cpp +++ b/Telegram/SourceFiles/gui/animation.cpp @@ -142,7 +142,7 @@ void AnimationManager::stop(Animation *obj) { if (_iterating) { _stopping.insert(obj, NullType()); if (!_starting.isEmpty()) { - _starting.insert(obj, NullType()); + _starting.remove(obj); } } else { AnimatingObjects::iterator i = _objects.find(obj); @@ -159,7 +159,9 @@ void AnimationManager::timeout() { _iterating = true; uint64 ms = getms(); for (AnimatingObjects::const_iterator i = _objects.begin(), e = _objects.end(); i != e; ++i) { - i.key()->step(ms, true); + if (!_stopping.contains(i.key())) { + i.key()->step(ms, true); + } } _iterating = false; diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 05c757ee7..b4103258c 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -680,8 +680,6 @@ void HistoryInner::itemRemoved(HistoryItem *item) { _widget->updateTopBarSelection(); } - if (_dragAction == NoDrag) return; - if (_dragItem == item) { dragActionCancel(); } @@ -733,8 +731,9 @@ void HistoryInner::dragActionFinish(const QPoint &screenPos, Qt::MouseButton but if (needClick) { DEBUG_LOG(("Clicked link: %1 (%2) %3").arg(needClick->text()).arg(needClick->readable()).arg(needClick->encoded())); - needClick->onClick(button); dragActionCancel(); + + needClick->onClick(button); // this possibly can delete this object return; } if (_dragAction == PrepareSelect && !_dragWasInactive && !_selected.isEmpty() && _selected.cbegin().value() == FullSelection) { @@ -777,6 +776,7 @@ void HistoryInner::dragActionFinish(const QPoint &screenPos, Qt::MouseButton but } } _dragAction = NoDrag; + _dragItem = 0; _dragSelType = TextSelectLetters; _widget->noSelectingScroll(); _widget->updateTopBarSelection(); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 779a93bac..76efb6a1c 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1185,7 +1185,7 @@ void MainWidget::checkedHistory(PeerData *peer, const MTPmessages_Messages &resu History *h = App::history(peer->id); if (!h->lastMsg) { HistoryItem *item = h->addNewMessage((*v)[0], NewMessageLast); - if (collapsed && !collapsed->isEmpty() && collapsed->at(0).type() == mtpc_messageGroup && h->isChannel()) { + if (item && collapsed && !collapsed->isEmpty() && collapsed->at(0).type() == mtpc_messageGroup && h->isChannel()) { if (collapsed->at(0).c_messageGroup().vmax_id.v > item->id) { if (h->asChannelHistory()->onlyImportant()) { h->asChannelHistory()->clearOther(); diff --git a/Telegram/SourceFiles/overviewwidget.cpp b/Telegram/SourceFiles/overviewwidget.cpp index 0c9c0698b..797c76bea 100644 --- a/Telegram/SourceFiles/overviewwidget.cpp +++ b/Telegram/SourceFiles/overviewwidget.cpp @@ -265,12 +265,13 @@ void OverviewInner::searchReceived(SearchRequestType type, const MTPmessages_Mes } for (QVector::const_iterator i = messages->cbegin(), e = messages->cend(); i != e; ++i) { HistoryItem *item = App::histories().addNewMessage(*i, NewMessageExisting); + MsgId msgId = item ? item->id : idFromMessage(*i); if (migratedSearch) { - _searchResults.push_front(-item->id); - _lastSearchMigratedId = item->id; + if (item) _searchResults.push_front(-item->id); + _lastSearchMigratedId = msgId; } else { - _searchResults.push_front(item->id); - _lastSearchId = item->id; + if (item) _searchResults.push_front(item->id); + _lastSearchId = msgId; } } mediaOverviewUpdated(); diff --git a/Telegram/SourceFiles/structs.cpp b/Telegram/SourceFiles/structs.cpp index 274b34f29..db43d2337 100644 --- a/Telegram/SourceFiles/structs.cpp +++ b/Telegram/SourceFiles/structs.cpp @@ -189,7 +189,9 @@ void UserData::setPhoto(const MTPUserProfilePhoto &p) { // see Local::readPeer a photoId = newPhotoId; photo = newPhoto; photoLoc = newPhotoLoc; - emit App::main()->peerPhotoChanged(this); + if (App::main()) { + emit App::main()->peerPhotoChanged(this); + } } }