diff --git a/android/jni/com/mapswithme/maps/DownloaderAdapter.cpp b/android/jni/com/mapswithme/maps/DownloaderAdapter.cpp index 61bc3fbee0..85339803f8 100644 --- a/android/jni/com/mapswithme/maps/DownloaderAdapter.cpp +++ b/android/jni/com/mapswithme/maps/DownloaderAdapter.cpp @@ -97,9 +97,11 @@ void BackgroundDownloaderAdapter::Download(QueuedCountry && queuedCountry) auto urls = MakeUrlList(queuedCountry.GetRelativeUrl()); auto const path = queuedCountry.GetFileDownloadPath(); - queuedCountry.OnStartDownloading(); + // For safety reasons, add to the queue first and notify start downloading then, + // to avoid possible recursion. + m_queue.Append(QueuedCountry(queuedCountry)); - m_queue.Append(std::move(queuedCountry)); + queuedCountry.OnStartDownloading(); DownloadFromLastUrl(countryId, path, std::move(urls)); } diff --git a/storage/background_downloading/downloader_adapter_ios.mm b/storage/background_downloading/downloader_adapter_ios.mm index f49ae157d8..99db928d2a 100644 --- a/storage/background_downloading/downloader_adapter_ios.mm +++ b/storage/background_downloading/downloader_adapter_ios.mm @@ -71,9 +71,13 @@ void BackgroundDownloaderAdapter::Download(QueuedCountry && queuedCountry) auto urls = MakeUrlList(queuedCountry.GetRelativeUrl()); auto const path = queuedCountry.GetFileDownloadPath(); - queuedCountry.OnStartDownloading(); + // The order is important here: add to the queue first, notify start downloading then. + // Infinite recursion possible here, otherwise: + // OnStartDownloading -> NotifyStatusChanged -> processCountryEvent -> configDialog (?!) + // -> downloadNode for the same country if autodownload enabled -> Download. + m_queue.Append(QueuedCountry(queuedCountry)); - m_queue.Append(std::move(queuedCountry)); + queuedCountry.OnStartDownloading(); DownloadFromLastUrl(countryId, path, std::move(urls)); }