title: SpriteKit crashing with std::out_of_range: vector issue
body: <p>So I am trying to pin down exactly what is the cause of this crash. Please see the crash report here:<img src="https://i.stack.imgur.com/SJ5K5.png" alt="Crash"></p>
  
  <p>This is what is produced in the log:
  libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: vector</p>
  
  <p>Basically the crash does not happen all the time and seems to happen on more recent iOS devices. If I clean my build I have noticed that the chances of it happening are much less likely. I am assuming it has something to do with maybe my textures atlases?</p>
  
  <p>Has anyone had this same issue and what did you do to solve? Need to be pointed in the right direction here been doing trial and error for awhile not with all my texture loads but have not been able to pinpoint it down.</p>
  
  <p>Thanks in advance!</p>
  
  <p>EDIT:</p>
  
  <pre><code>-(void)load_engine
  {
  //general atlases
  circle_explodes_atlas = [SKTextureAtlas atlasNamed:@"effect_circle_explode"];
  box_explodes_atlas = [SKTextureAtlas atlasNamed:@"box_explodes"];
  fence_atlas = [SKTextureAtlas atlasNamed:@"fence_new"];
  swipe_atlas = [SKTextureAtlas atlasNamed:@"swipe"];
  coin_atlas = [SKTextureAtlas atlasNamed:@"coin"];
  reward2x_atlas = [SKTextureAtlas atlasNamed:@"two_times"];
  reward3x_atlas = [SKTextureAtlas atlasNamed:@"three_times"];
  healthpack_atlas = [SKTextureAtlas atlasNamed:@"healthpack_explodes"];
  effects_atlas = [SKTextureAtlas atlasNamed:@"effect"];
  
  //character atlases
  broccoli_atlas = [SKTextureAtlas atlasNamed:@"broccoli"];
  brussel_atlas = [SKTextureAtlas atlasNamed:@"brussels"];
  corn_atlas = [SKTextureAtlas atlasNamed:@"corn"];
  cucumber_atlas = [SKTextureAtlas atlasNamed:@"cucumber"];
  eggplant_atlas = [SKTextureAtlas atlasNamed:@"eggplant"];
  salad_atlas = [SKTextureAtlas atlasNamed:@"salad"];
  peas_atlas = [SKTextureAtlas atlasNamed:@"peas"];
  gus_atlas = [SKTextureAtlas atlasNamed:@"gus"];
  
  start_atlas = [SKTextureAtlas atlasNamed:@"start"];
  
  
  [SKTextureAtlas preloadTextureAtlases:@[circle_explodes_atlas, box_explodes_atlas, fence_atlas, swipe_atlas, coin_atlas, reward3x_atlas, reward2x_atlas, gus_atlas, broccoli_atlas, brussel_atlas, corn_atlas, cucumber_atlas, eggplant_atlas, salad_atlas, peas_atlas, effects_atlas, start_atlas] withCompletionHandler:^{
      //these are the most used items through out the game so they are used alot. might as well reference them.
  
  
  
      int numImages = (int)circle_explodes_atlas.textureNames.count;
      for (int i=0; i &lt;= numImages/2-1; i++)
      {
          NSString *textureName = [NSString stringWithFormat:@"effect_circle_explode_%d.png", i];
          SKTexture *temp = [circle_explodes_atlas textureNamed:textureName];
          [circle_explode_textures addObject:temp];
      }        
      int numImages2 = (int)coin_atlas.textureNames.count;
      for (int i=0; i &lt;= numImages2/2-1; i++)
      {
          NSString *textureName = [NSString stringWithFormat:@"coin_%d.png", i];
          SKTexture *temp = [coin_atlas textureNamed:textureName];
          [coin_textures addObject:temp];
      }
      //make another loop just to reference the textures for the floors and else etc to preload them as well.
  
      [self load_textures];
  
      [mem_manager load];
  
  
  
  }];
  
  
  }
  -(void)load_textures
  {
  
  logo_texture = [start_atlas textureNamed:@"logo"];
  swipe_text_texture = [start_atlas textureNamed:@"swipe_txt"];
  swipe_base_texture = [start_atlas textureNamed:@"swipe_base"];
  hq_texture = [start_atlas textureNamed:@"chubby_hq"];
  fence_texture = [start_atlas textureNamed:@"fence"];
  peas_fence_texture = [start_atlas textureNamed:@"fence_and_peas"];
  
  floor_texture1 = [SKTexture textureWithImageNamed:@"street_1"];
  floor_texture2 = [SKTexture textureWithImageNamed:@"street_2"];
  floor_texture3 = [SKTexture textureWithImageNamed:@"street_3"];
  floor_texture4 = [SKTexture textureWithImageNamed:@"street_4"];
  pit_texture1 = [SKTexture textureWithImageNamed:@"street_trash_long"];
  pit_texture2 = [SKTexture textureWithImageNamed:@"street_garden_long"];
  bridge_texture = [SKTexture textureWithImageNamed:@"bridge1"];
  
  spikes_texture = [SKTexture textureWithImageNamed:@"cliff_spikes"];
  water_texture = [SKTexture textureWithImageNamed:@"cliff_water"];
  hill_texture = [SKTexture textureWithImageNamed:@"street_hill"];
  
  crate_texture = [start_atlas textureNamed:@"box_crate"];
  box_texture = [start_atlas textureNamed:@"box_junk_float"];
  
  stuff.hidden = NO;
  store.hidden = NO;
  
  scroll_view.userInteractionEnabled = YES;
  
  [self present_game_view];
  
  
  
  }
  </code></pre>
  
  <p>Now that is how I load all my textures accordingly. present_game_view will calls this start method that somewhere in here these are whats causing the crash, loading these textures. </p>
  
  <pre><code>chubby_hq = [[SKSpriteNode alloc] init];
  chubby_hq.texture = [(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController].hq_texture;
  chubby_hq.size = CGSizeMake(264, 204);
  chubby_hq.position = CGPointMake(270, 188);
  chubby_hq.zPosition = 10;
  chubby_hq.name = @"start_scene";
  [camera addChild:chubby_hq];
  
  peas_fence = [[SKSpriteNode alloc] init];
  peas_fence.texture = [(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController].peas_fence_texture;
  peas_fence.size = CGSizeMake(273, 102);
  peas_fence.position = CGPointMake(90, 72);
  peas_fence.zPosition = 10;
  peas_fence.zRotation = 0;
  peas_fence.name = @"start_scene";
  [camera addChild:peas_fence];
  
  fence = [[SKSpriteNode alloc] init];
  fence.texture = [(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController].fence_texture;
  fence.size = CGSizeMake(570, 168);
  fence.position = CGPointMake(285, 110);
  fence.zPosition = 4;
  fence.zRotation = 0;
  fence.name = @"start_scene";
  [camera addChild:fence];
  
  finger_animation = [[SKSpriteNode alloc] init];
  finger_animation.texture = [(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController].swipe_base_texture;
  finger_animation.size = CGSizeMake(106, 320);
  finger_animation.position = CGPointMake(465, 150);
  finger_animation.zPosition = 10;
  finger_animation.zRotation = 0;
  finger_animation.name = @"start_scene";
  [camera addChild:finger_animation];
  [self animate_swipes];
  
  finger_text = [[SKSpriteNode alloc] init];
  finger_text.texture = [(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController].swipe_text_texture;
  finger_text.size = CGSizeMake(125, 73);
  finger_text.position = CGPointMake(475, 145);
  finger_text.zPosition = 10;
  finger_text.zRotation = 0;
  finger_text.name = @"start_scene";
  [camera addChild:finger_text];
  
  logo = [[SKSpriteNode alloc] init];
  logo.texture = [(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController].logo_texture;
  logo.size = CGSizeMake(162, 167);
  logo.position = CGPointMake(90, 250);
  logo.zPosition = 10;
  logo.name = @"start_scene";
  [camera addChild:logo];
  </code></pre>
  
  <p>SOLVE:
  Due to some help from a member on how to debug this error here is what was causing this issue.
  It turns out that <code>circle_explode_textures</code> was being alloced after the preload method and there for that explains why sometimes it work and sometimes not. Simple fix was just to move the alloc for the texture array prior to calling the preload so to ensure they are available for when the preload complete fires.</p>