Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat in my code is causing this error (NSMutableArray is to small for the object being called)?
    primarykey
    data
    text
    <p>I am assuming that somewhere in my code the objects in the array are being removed faster than they are created. I have been looking for the problem for over an hour so please help!</p> <p>Here is the error:<code>*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 7 beyond bounds [0 .. 6]'</code> Thanks in advance and here is my code:</p> <pre><code>- (void)onTimer { UIImageView *imgView = [[UIImageView alloc] init]; imgView.image = particleImg; imgView.frame = CGRectMake(kViewDimensions/2, kViewDimensions/2, startSize.width, startSize.height); [self addSubview:imgView]; [particlesArray addObject:imgView]; [imgView release]; moveTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(moveObjs) userInfo:nil repeats:YES]; } - (void)moveObjs { for (int i = 0; i &lt; [particlesArray count]; i++) { animID = @"MoveId"; UIImageView *imgV = [particlesArray objectAtIndex:i]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; CGPoint randPoint = CGPointMake(arc4random()%kMaxRandX, arc4random()%kMaxRandY); imgV.center = CGPointMake(randPoint.x, randPoint.y); [UIView commitAnimations]; animValue = i; num = [NSNumber numberWithInt:animValue]; [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(animationEnded) userInfo:num repeats:NO]; NSLog(@"\n %d",animValue); } } - (void)animationEnded { int av = [num intValue]; UIImageView *iv = [particlesArray objectAtIndex:av]; if ([animID isEqualToString:@"MoveId"]) { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.1]; iv.alpha = 0.0f; [UIView commitAnimations]; [particlesArray removeObjectAtIndex:av]; } else { [iv removeFromSuperview]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload