2014-01-18 81 views
0

所以我试图确定这崩溃的原因究竟是什么。请在这里看到的崩溃报告:CrashSpriteKit崩溃与std :: out_of_range:矢量问题

这就是在日志中产生: 的libC++ abi.dylib:矢量

基本上崩溃不会:与类型为std未捕获的异常:: out_of_range终止一直发生,似乎发生在更新的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]; 

解决方法: 由于从成员一些帮助就如何调试这里这个错误是什么造成了这个问题。 事实证明circle_explode_textures在预加载方法之后被分配,因此这解释了为什么它有时可以工作,有时不能。简单的修复就是在调用预加载之前移动纹理数组的alloc,以确保预加载完成时它们可用。

+0

没有任何代码,这是无法回答。尝试首先分别缩小问题的范围,尽量使其具有可重现性。减少正在运行的代码数量,直到问题消失,以便循环访问可能导致崩溃的代码部分。 – LearnCocos2D

+0

@ LearnCocos2D我已经精确地指出了它崩溃的位置,但奇怪的是,它可能会在此的不同部分崩溃,但是如果程序确实超过了我的“启动屏幕”的最后分配,它就会运行。一般你知道这是什么原因?我是否认为它与纹理图集有关? – Krzemienski

+0

崩溃是在动画动作 – LearnCocos2D

回答

8

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

+0

谢谢,我将以这种方式进行调试,希望我能弄明白。 – Krzemienski

+0

我想出了这个问题,使用你的提示,我在纹理数组周围设置了一些日志,并意识到我在调用预加载的方法之后分配我的数组。这解释了为什么它有时会起作用,因为有时数组会被分配,有时该方法会先完成,数组将会为空,并因此导致超出范围的错误!非常感谢。 – Krzemienski

+0

你救了我!这是animateWithTextures哈哈 – msqar