Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "bad_access error" when playing short time at high frequency with fade out #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 34 additions & 29 deletions ObjectAL/ObjectAL/Actions/OALActionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,31 +129,6 @@ - (void) step:(NSTimer*) timer
#pragma unused(timer)
OPTIONALLY_SYNCHRONIZED(self)
{
// Add new actions
for(OALAction* action in actionsToAdd)
{
// But only if they haven't been stopped already
if(action.running)
{
NSUInteger index = [targets indexOfObject:action.target];
if(NSNotFound == index)
{
// Since this target has no running actions yet, add the support
// structure to keep track of it.
index = [targets count];
[targets addObject:action.target];
[targetActions addObject:[NSMutableArray arrayWithCapacity:5]];
}

// Get the list of actions operating on this target and add the new action.
NSMutableArray* actions = [targetActions objectAtIndex:index];
[actions addObject:action];
}
}
// All actions have been added. Clear the "add" list.
[actionsToAdd removeAllObjects];


// Remove stopped actions
for(OALAction* action in actionsToRemove)
{
Expand All @@ -169,18 +144,48 @@ - (void) step:(NSTimer*) timer
[targets removeObjectAtIndex:index];
[targetActions removeObjectAtIndex:index];

// If there are no more actions running, stop the master timer.
// If there are no more actions running, exit this loop.
if([targets count] == 0)
{
[stepTimer invalidate];
stepTimer = nil;
break;
}
}
}
}
[actionsToRemove removeAllObjects];


// Add new actions
for(OALAction* action in actionsToAdd)
{
// But only if they haven't been stopped already
if(action.running)
{
NSUInteger index = [targets indexOfObject:action.target];
if(NSNotFound == index)
{
// Since this target has no running actions yet, add the support
// structure to keep track of it.
index = [targets count];
[targets addObject:action.target];
[targetActions addObject:[NSMutableArray arrayWithCapacity:5]];
}

// Get the list of actions operating on this target and add the new action.
NSMutableArray* actions = [targetActions objectAtIndex:index];
[actions addObject:action];
}
}
// All actions have been added. Clear the "add" list.
[actionsToAdd removeAllObjects];

// If there are no more actions running, stop the master timer.
if([targets count] == 0)
{
[stepTimer invalidate];
stepTimer = nil;
return;
}

// Get the time elapsed and update timestamp.
// If there was a break in timing (lastTimestamp == 0), assume 0 time has elapsed.
uint64_t currentTime = mach_absolute_time();
Expand Down