SpriteKit崩溃与std :: out_of_range:vector问题

所以我正在试图确定这次事故的原因是什么。 请看这里的崩溃报告: 紧急

这是在日志中产生的:libc ++ abi.dylib:以std :: out_of_range:vectortypes的未捕获exception

基本上,崩溃不会一直发生,似乎在更新的iOS设备上发生。 如果我清理我的构build,我已经注意到它发生的可能性要小得多。 我假设它可能与我的纹理地图集有关系?

有没有人有这个相同的问题,你做了什么来解决? 需要指出正确的方向在这里做了一段时间的尝试和错误,而不是所有的纹理负载,但一直没能find它。

提前致谢!

编辑:

-(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 <= 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 <= 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]; } 

现在这就是我如何加载我所有的纹理。 present_game_view会调用这个启动方法,在这里这里是什么导致崩溃,加载这些纹理。

 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]; 

解决:由于一些成员的帮助,如何debugging这个错误是什么导致了这个问题。 事实certificate,在preload方法之后, circle_explode_textures被分配了,这就解释了为什么有时候它有效,有时不行。 简单的解决方法就是在调用预加载之前移动纹理数组的alloc,以确保它们在预加载完成时可用。

我看到这个错误发生在你试图运行一个+ (SKAction *)animateWithTextures:(NSArray *)textures动作使用一个数组是无或包含SKTexture以外的SKTexture 。 在传递给animation操作的纹理数组上设置日志,看看是否所有项目都被正确添加。 或者也许有些纹理数组在被执行animation之后被初始化/填充。