2014-01-18 131 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