From ead212f31b8f743c6d3ab9de9d1eb9a4f6830996 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 1 Jul 2019 14:38:19 +0200 Subject: [PATCH] Fix lottie caching. --- Telegram/SourceFiles/lottie/lottie_cache.cpp | 14 ++++++++++++++ Telegram/SourceFiles/lottie/lottie_cache.h | 1 + 2 files changed, 15 insertions(+) diff --git a/Telegram/SourceFiles/lottie/lottie_cache.cpp b/Telegram/SourceFiles/lottie/lottie_cache.cpp index 3909d9ea5e..93a4a48fdb 100644 --- a/Telegram/SourceFiles/lottie/lottie_cache.cpp +++ b/Telegram/SourceFiles/lottie/lottie_cache.cpp @@ -517,6 +517,8 @@ bool Cache::renderFrame( _framesReady = 0; _data = QByteArray(); return false; + } else if (index + 1 == _framesReady && _data.size() > _offset) { + _data.resize(_offset); } if (xored) { Xor(_previous, _uncompressed); @@ -576,6 +578,8 @@ void Cache::finalizeEncoding() { if (_data.isEmpty()) { _data.reserve(size); writeHeader(); + } else { + updateFramesReadyCount(); } const auto offset = _data.size(); _data.resize(size); @@ -609,6 +613,16 @@ void Cache::writeHeader() { << qint32(_framesReady); } +void Cache::updateFramesReadyCount() { + Expects(_data.size() >= headerSize()); + + const auto serialized = qint32(_framesReady); + const auto offset = headerSize() - sizeof(qint32); + bytes::copy( + bytes::make_detached_span(_data).subspan(offset), + bytes::object_as_span(&serialized)); +} + void Cache::prepareBuffers() { // 12 bit per pixel in YUV420P. const auto bytesPerLine = _size.width(); diff --git a/Telegram/SourceFiles/lottie/lottie_cache.h b/Telegram/SourceFiles/lottie/lottie_cache.h index 6d1e67b93b..bb8cc2bb2d 100644 --- a/Telegram/SourceFiles/lottie/lottie_cache.h +++ b/Telegram/SourceFiles/lottie/lottie_cache.h @@ -101,6 +101,7 @@ private: void finalizeEncoding(); void writeHeader(); + void updateFramesReadyCount(); [[nodiscard]] bool readHeader(const FrameRequest &request); [[nodiscard]] ReadResult readCompressedFrame();