From 8782bdd6ba5fee42e4db22b36506b1e18193df6c Mon Sep 17 00:00:00 2001 From: Tom Poole Date: Mon, 23 Apr 2018 11:48:03 +0100 Subject: [PATCH] Fixed a bug handling queued analytics events after a failed server connection attempt --- .../juce_ThreadedAnalyticsDestination.cpp | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/modules/juce_analytics/destinations/juce_ThreadedAnalyticsDestination.cpp b/modules/juce_analytics/destinations/juce_ThreadedAnalyticsDestination.cpp index 14027d3501..74032e049c 100644 --- a/modules/juce_analytics/destinations/juce_ThreadedAnalyticsDestination.cpp +++ b/modules/juce_analytics/destinations/juce_ThreadedAnalyticsDestination.cpp @@ -89,20 +89,24 @@ void ThreadedAnalyticsDestination::EventDispatcher::run() while (! threadShouldExit()) { - auto eventsToSendCapacity = maxBatchSize - eventsToSend.size(); - - if (eventsToSendCapacity > 0) { - const ScopedLock lock (queueAccess); - - const auto numEventsInQueue = (int) eventQueue.size(); + const auto numEventsInBatch = eventsToSend.size(); + const auto freeBatchCapacity = maxBatchSize - numEventsInBatch; - if (numEventsInQueue > 0) + if (freeBatchCapacity > 0) { - const auto numEventsToAdd = jmin (eventsToSendCapacity, numEventsInQueue); + const auto numNewEvents = (int) eventQueue.size() - numEventsInBatch; + + if (numNewEvents > 0) + { + const ScopedLock lock (queueAccess); + + const auto numEventsToAdd = jmin (numNewEvents, freeBatchCapacity); + const auto newBatchSize = numEventsInBatch + numEventsToAdd; - for (size_t i = 0; i < (size_t) numEventsToAdd; ++i) - eventsToSend.add (eventQueue[i]); + for (size_t i = numEventsInBatch; i < (size_t) newBatchSize; ++i) + eventsToSend.add (eventQueue[i]); + } } }