Skip to content

Commit 68eec6a

Browse files
committed
Concurrent modification fix
1 parent c89de85 commit 68eec6a

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 24.7.8
22
* Mitigated an issue where visibility could have been wrongly assigned if a view was closed while going to background. (Experimental!)
33
* Mitigated an issue where the user provided URLSessionConfiguration was not applied to direct requests
4+
* Mitigated an issue where a concurrent modification error could have happen when starting multiple stopped views
45

56
## 24.7.7
67
* Changed the visibility tracking segmentation values to binary

CountlyViewTrackingInternal.m

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -545,27 +545,33 @@ - (void)startStoppedViewsInternal
545545
{
546546
// Create an array to store keys for views that need to be removed
547547
NSMutableArray<NSString *> *keysToRemove = [NSMutableArray array];
548-
548+
NSMutableArray<NSString *> *keysToStart = [NSMutableArray array];
549+
550+
// Collect keys without modifying the dictionary
549551
[self.viewDataDictionary enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, CountlyViewData * _Nonnull viewData, BOOL * _Nonnull stop) {
550552
if (viewData.willStartAgain)
551553
{
552-
NSString *viewID = [self startViewInternal:viewData.viewName customSegmentation:viewData.startSegmentation isAutoStoppedView:viewData.isAutoStoppedView];
553-
554-
// Retrieve the newly created viewData for the viewID
555-
CountlyViewData* viewDataNew = self.viewDataDictionary[viewID];
556-
557-
// Copy the segmentation data from the old view to the new view
558-
viewDataNew.segmentation = viewData.segmentation.mutableCopy;
559-
560-
// Add the old view's ID to the array for removal later
554+
[keysToStart addObject:key];
561555
[keysToRemove addObject:viewData.viewID];
562556
}
563557
}];
564558

559+
// Start the collected views after enumeration
560+
for (NSString *key in keysToStart)
561+
{
562+
CountlyViewData *viewData = self.viewDataDictionary[key];
563+
NSString *viewID = [self startViewInternal:viewData.viewName customSegmentation:viewData.startSegmentation isAutoStoppedView:viewData.isAutoStoppedView];
564+
565+
// Retrieve and update the newly created viewData
566+
CountlyViewData *viewDataNew = self.viewDataDictionary[viewID];
567+
viewDataNew.segmentation = viewData.segmentation.mutableCopy;
568+
}
569+
565570
// Remove the entries from the dictionary
566571
[self.viewDataDictionary removeObjectsForKeys:keysToRemove];
567572
}
568573

574+
569575
- (void)stopAllViewsInternal:(NSDictionary *)segmentation
570576
{
571577
// TODO: Should apply all the segmenation operations here at one place instead of doing it for individual view

0 commit comments

Comments
 (0)