所以我想确切地确定这次崩溃的原因是什么。请在此处查看崩溃报告:
这是日志中产生的内容: libc ++ abi.dylib:以std :: out_of_range类型的未捕获异常终止:vector
基本上崩溃不会一直发生,似乎发生在最近的iOS设备上。如果我清理我的构建,我注意到它发生的可能性要小得多。我假设它与我的纹理地图集有关?
有没有人有同样的问题,你做了什么来解决?需要指出正确的方向这里一直在做试验和错误一段时间没有我的所有纹理负载,但无法确定它。
提前致谢!
编辑:
-(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];
SOLVE:
由于成员如何调试此错误的一些帮助,这是导致此问题的原因。
事实证明,circle_explode_textures
是在预加载方法之后分配的,因此解释了为什么有时候它有效,有时却没有。简单的修复只是在调用预加载之前移动纹理数组的alloc,以确保它们在预加载完成时可用。
答案 0 :(得分:8)
当您尝试使用nil或包含+ (SKAction *)animateWithTextures:(NSArray *)textures
以外的对象的数组运行SKTexture
操作时,我发现此错误。在您传递给动画操作的纹理数组上设置日志,以查看是否正确添加了所有项目。或者在运行animate动作之后,可能正在初始化/填充一些纹理数组。