From 0291888c01353d4a31561fca99de4778963adb8d Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 29 Jul 2016 17:33:49 +0100 Subject: [PATCH 1/3] A couple of rare crashes fixed. --- Telegram/SourceFiles/mainwidget.cpp | 5 ++++- Telegram/SourceFiles/media/view/media_clip_controller.cpp | 2 +- Telegram/SourceFiles/media/view/media_clip_playback.cpp | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index cdf9f42a2..c99aec5e1 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -3742,7 +3742,10 @@ int32 MainWidget::dlgsWidth() const { MainWidget::~MainWidget() { if (App::main() == this) _history->showHistory(0, 0); - delete _hider; + if (HistoryHider *hider = _hider) { + _hider = nullptr; + delete hider; + } MTP::clearGlobalHandlers(); if (App::wnd()) App::wnd()->noMain(this); diff --git a/Telegram/SourceFiles/media/view/media_clip_controller.cpp b/Telegram/SourceFiles/media/view/media_clip_controller.cpp index 904b5bae1..18c43dbae 100644 --- a/Telegram/SourceFiles/media/view/media_clip_controller.cpp +++ b/Telegram/SourceFiles/media/view/media_clip_controller.cpp @@ -59,8 +59,8 @@ void Controller::onSeekProgress(float64 progress) { auto positionMs = snap(static_cast(progress * _lastDurationMs), 0LL, _lastDurationMs); if (_seekPositionMs != positionMs) { _seekPositionMs = positionMs; - emit seekProgress(positionMs); refreshTimeTexts(); + emit seekProgress(positionMs); // This may destroy Controller. } } diff --git a/Telegram/SourceFiles/media/view/media_clip_playback.cpp b/Telegram/SourceFiles/media/view/media_clip_playback.cpp index 1fccb7278..2b1f82148 100644 --- a/Telegram/SourceFiles/media/view/media_clip_playback.cpp +++ b/Telegram/SourceFiles/media/view/media_clip_playback.cpp @@ -122,8 +122,8 @@ void Playback::mouseMoveEvent(QMouseEvent *e) { void Playback::mousePressEvent(QMouseEvent *e) { _mouseDown = true; _downProgress = snap(e->pos().x() / float64(width()), 0., 1.); - emit seekProgress(_downProgress); update(); + emit seekProgress(_downProgress); // This may destroy Playback. } void Playback::mouseReleaseEvent(QMouseEvent *e) { From d31701e906fbf1609fe9b2eb494c500423c93291 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 30 Jul 2016 11:03:44 +0100 Subject: [PATCH 2/3] Fixed client side waveform counter infinite loop. Backported Qt 5.6.1 crash fix in cocoa integration to Qt patch. --- Telegram/Patches/qtbase_5_6_0.diff | 28 +++++++++++++++++++ Telegram/SourceFiles/media/media_audio.cpp | 2 +- .../SourceFiles/media/media_clip_ffmpeg.cpp | 2 +- .../media/media_clip_implementation.h | 2 +- .../SourceFiles/media/media_clip_qtgif.cpp | 2 +- .../SourceFiles/media/media_clip_reader.cpp | 4 +-- 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/Telegram/Patches/qtbase_5_6_0.diff b/Telegram/Patches/qtbase_5_6_0.diff index dd4c477bf..e1e270564 100644 --- a/Telegram/Patches/qtbase_5_6_0.diff +++ b/Telegram/Patches/qtbase_5_6_0.diff @@ -11300,6 +11300,34 @@ index ca92103..225d85f 100644 QPainter p(&m_qImage); p.setCompositionMode(QPainter::CompositionMode_Source); const QVector rects = region.rects(); +diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm +index 6bec6b1..f14d6ee 100644 +--- a/src/plugins/platforms/cocoa/qcocoaintegration.mm ++++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm +@@ -422,14 +422,20 @@ void QCocoaIntegration::updateScreens() + } + siblings << screen; + } ++ ++ ++// Patch: backport crash fix from Qt 5.6.1 ++ // Set virtual siblings list. All screens in mScreens are siblings, because we ignored the ++ // mirrors. Note that some of the screens we update the siblings list for here may be deleted ++ // below, but update anyway to keep the to-be-deleted screens out of the siblings list. ++ foreach (QCocoaScreen* screen, mScreens) ++ screen->setVirtualSiblings(siblings); ++ + // Now the leftovers in remainingScreens are no longer current, so we can delete them. + foreach (QCocoaScreen* screen, remainingScreens) { + mScreens.removeOne(screen); + destroyScreen(screen); + } +- // All screens in mScreens are siblings, because we ignored the mirrors. +- foreach (QCocoaScreen* screen, mScreens) +- screen->setVirtualSiblings(siblings); + } + + QCocoaScreen *QCocoaIntegration::screenAtIndex(int index) diff --git a/src/plugins/platforms/cocoa/qcocoakeymapper.mm b/src/plugins/platforms/cocoa/qcocoakeymapper.mm index c2d206f..0f9b512 100644 --- a/src/plugins/platforms/cocoa/qcocoakeymapper.mm diff --git a/Telegram/SourceFiles/media/media_audio.cpp b/Telegram/SourceFiles/media/media_audio.cpp index 32f2f79b9..f16d9de2a 100644 --- a/Telegram/SourceFiles/media/media_audio.cpp +++ b/Telegram/SourceFiles/media/media_audio.cpp @@ -1984,7 +1984,7 @@ public: int64 samples = 0; auto res = readMore(buffer, samples); - if (res == ReadResult::Error) { + if (res == ReadResult::Error || res == ReadResult::EndOfFile) { break; } if (buffer.isEmpty()) { diff --git a/Telegram/SourceFiles/media/media_clip_ffmpeg.cpp b/Telegram/SourceFiles/media/media_clip_ffmpeg.cpp index acf016310..5fd4f0bae 100644 --- a/Telegram/SourceFiles/media/media_clip_ffmpeg.cpp +++ b/Telegram/SourceFiles/media/media_clip_ffmpeg.cpp @@ -52,7 +52,7 @@ ReaderImplementation::ReadResult FFMpegReaderImplementation::readNextFrame() { if (res == AVERROR_EOF) { clearPacketQueue(); if (_mode == Mode::Normal) { - return ReadResult::Eof; + return ReadResult::EndOfFile; } if ((res = avformat_seek_file(_fmtContext, _streamId, std::numeric_limits::min(), 0, std::numeric_limits::max(), 0)) < 0) { diff --git a/Telegram/SourceFiles/media/media_clip_implementation.h b/Telegram/SourceFiles/media/media_clip_implementation.h index 54bf98944..303c8ee2a 100644 --- a/Telegram/SourceFiles/media/media_clip_implementation.h +++ b/Telegram/SourceFiles/media/media_clip_implementation.h @@ -41,7 +41,7 @@ public: enum class ReadResult { Success, Error, - Eof, + EndOfFile, }; // Read frames till current frame will have presentation time > frameMs, systemMs = getms(). virtual ReadResult readFramesTill(int64 frameMs, uint64 systemMs) = 0; diff --git a/Telegram/SourceFiles/media/media_clip_qtgif.cpp b/Telegram/SourceFiles/media/media_clip_qtgif.cpp index 18f0462b5..b5209d0cc 100644 --- a/Telegram/SourceFiles/media/media_clip_qtgif.cpp +++ b/Telegram/SourceFiles/media/media_clip_qtgif.cpp @@ -55,7 +55,7 @@ ReaderImplementation::ReadResult QtGifReaderImplementation::readNextFrame() { if (_reader) _frameDelay = _reader->nextImageDelay(); if (_framesLeft < 1) { if (_mode == Mode::Normal) { - return ReadResult::Eof; + return ReadResult::EndOfFile; } else if (!jumpToStart()) { return ReadResult::Error; } diff --git a/Telegram/SourceFiles/media/media_clip_reader.cpp b/Telegram/SourceFiles/media/media_clip_reader.cpp index 043d149e3..f310dd1b9 100644 --- a/Telegram/SourceFiles/media/media_clip_reader.cpp +++ b/Telegram/SourceFiles/media/media_clip_reader.cpp @@ -346,7 +346,7 @@ public: } if (frame() && frame()->original.isNull()) { auto readResult = _implementation->readFramesTill(-1, ms); - if (readResult == internal::ReaderImplementation::ReadResult::Eof && _seekPositionMs > 0) { + if (readResult == internal::ReaderImplementation::ReadResult::EndOfFile && _seekPositionMs > 0) { // If seek was done to the end: try to read the first frame, // get the frame size and return a black frame with that size. @@ -414,7 +414,7 @@ public: ProcessResult finishProcess(uint64 ms) { auto frameMs = _seekPositionMs + ms - _animationStarted; auto readResult = _implementation->readFramesTill(frameMs, ms); - if (readResult == internal::ReaderImplementation::ReadResult::Eof) { + if (readResult == internal::ReaderImplementation::ReadResult::EndOfFile) { stop(); _state = State::Finished; return ProcessResult::Finished; From c34181ef3e7a8234db90d1afc322a2c6f766c7f0 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 31 Jul 2016 10:29:15 +0100 Subject: [PATCH 3/3] Edit messages to yourself for any amount of time. Active inline keyboard button rendering rounding radius fixed. --- Telegram/SourceFiles/app.cpp | 2 +- Telegram/SourceFiles/history.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 7b67ab797..f3d177592 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -2109,7 +2109,7 @@ namespace { ::cornersMaskSmall[i] = new QImage(mask[i].convertToFormat(QImage::Format_ARGB32_Premultiplied)); ::cornersMaskSmall[i]->setDevicePixelRatio(cRetinaFactor()); } - prepareCorners(WhiteCorners, st::buttonRadius, st::white); + prepareCorners(WhiteCorners, st::dateRadius, st::white); prepareCorners(StickerCorners, st::dateRadius, st::msgServiceBg); prepareCorners(StickerSelectedCorners, st::dateRadius, st::msgServiceSelectBg); prepareCorners(SelectedOverlaySmallCorners, st::buttonRadius, st::msgSelectOverlay); diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index d94e11200..8bf762fea 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -2833,7 +2833,9 @@ void HistoryItem::setId(MsgId newId) { } bool HistoryItem::canEdit(const QDateTime &cur) const { - if (id < 0 || date.secsTo(cur) >= Global::EditTimeLimit()) return false; + auto messageToMyself = (peerToUser(_history->peer->id) == MTP::authedId()); + auto messageTooOld = messageToMyself ? false : (date.secsTo(cur) >= Global::EditTimeLimit()); + if (id < 0 || messageTooOld) return false; if (auto msg = toHistoryMessage()) { if (msg->Has() || msg->Has()) return false; @@ -2854,7 +2856,7 @@ bool HistoryItem::canEdit(const QDateTime &cur) const { auto channel = _history->peer->asChannel(); return (channel->amCreator() || (channel->amEditor() && out())); } - return out() || (peerToUser(_history->peer->id) == MTP::authedId()); + return out() || messageToMyself; } return false; }