Skip to content

Commit

Permalink
Avoid retaining a UITouch pointer that may have been deallocated (#22)
Browse files Browse the repository at this point in the history
Resolves #22.
  • Loading branch information
toddreed committed May 28, 2021
1 parent dd2b729 commit 525ce7b
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions Pod/Source/TRTouchposeApplication.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,33 @@ - (instancetype)initWithFrame:(CGRect)frame touchViewFactory:(id<TRTouchposeTouc

- (void)removeTouchesActiveTouches:(NSSet *)activeTouches
{
CFIndex count = CFDictionaryGetCount(_touchDictionary);
const CFIndex count = CFDictionaryGetCount(_touchDictionary);
if (count > 0)
{
void const * keys[count];
void const * values[count];
CFDictionaryGetKeysAndValues(_touchDictionary, keys, values);
void const *keys[count];
void const *values[count];
bool active[count]; // active[i] will be set to true if key[i] exists in activeTouches

for (CFIndex i = 0; i < count; ++i)
active[i] = false;

CFDictionaryGetKeysAndValues(_touchDictionary, keys, values);

for (UITouch *touch in activeTouches)
{
UITouch *touch = (__bridge UITouch *)keys[i];
for (CFIndex i = 0; i < count; ++i)
{
if (keys[i] == (__bridge const void *)touch)
active[i] = true;
}
}

if (activeTouches == nil || ![activeTouches containsObject:touch])
for (CFIndex i = 0; i < count; ++i)
{
if (!active[i])
{
UIView *view = (__bridge UIView *)values[i];
CFDictionaryRemoveValue(_touchDictionary, (__bridge const void *)(touch));
CFDictionaryRemoveValue(_touchDictionary, keys[i]);
[view removeFromSuperview];
}
}
Expand Down

0 comments on commit 525ce7b

Please sign in to comment.