2016-12-03 87 views
0

因此,我正在使用側滾動器。 每個關卡都有一個帶自定義玩家類的雪碧。 雖然確定精靈由其空閒動畫設置的紋理,但我已在每個Level中應用紋理以供參考。添加紋理會導致崩潰...(未捕獲的異常'NSInvalidArgumentException')

在它似乎做工精細

例如每個級別這是我的主要玩家猴子雪碧2級,因爲它出現在大多數的水平。

enter image description here

然而,在兩個層面上對這個球員雪碧的任何更改將導致遊戲崩潰。 我不得不把它作爲一個無紋理的精靈來做......任何一種改變都會導致遊戲崩潰。例如,如果我添加一個新的紋理,我得到以下錯誤。

E.g.在這裏它必須保持不變,否則我會崩潰。 enter image description here

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid size specified: {6, -2.6005233764648423}' 
*** First throw call stack: 
(
    0 CoreFoundation      0x00000001041a534b __exceptionPreprocess + 171 
    1 libobjc.A.dylib      0x000000010389e21e objc_exception_throw + 48 
    2 CoreFoundation      0x000000010420e265 +[NSException raise:format:] + 197 
    3 SpriteKit       0x0000000104d5060c -[SKSpriteNode initWithTexture:color:size:] + 204 
    4 SideScrolleriOS      0x00000001030248e5 _TFC15SideScrolleriOS8PlatformcfT7textureGSqCSo9SKTexture_5colorCSo7UIColor4sizeVSC6CGSize_S0_ + 661 
    5 SideScrolleriOS      0x00000001030785e6 _TFC15SideScrolleriOS14MovingPlatformcfT7textureGSqCSo9SKTexture_5colorCSo7UIColor4sizeVSC6CGSize_S0_ + 246 
    6 SideScrolleriOS      0x00000001030786e6 _TToFC15SideScrolleriOS14MovingPlatformcfT7textureGSqCSo9SKTexture_5colorCSo7UIColor4sizeVSC6CGSize_S0_ + 86 
    7 SpriteKit       0x0000000104d5157a -[SKSpriteNode initWithColor:size:] + 25 
    8 SideScrolleriOS      0x0000000103026ac4 _TTOFCSo12SKSpriteNodecfT5colorCSo7UIColor4sizeVSC6CGSize_S_ + 36 
    9 SideScrolleriOS      0x000000010301f440 _TFCSo12SKSpriteNodeCfT5colorCSo7UIColor4sizeVSC6CGSize_S_ + 96 
    10 SideScrolleriOS      0x000000010301e9c6 _TFC15SideScrolleriOS8Platform13setUpPlatformfCS_6PlayerT_ + 2166 
    11 SideScrolleriOS      0x0000000103077609 _TFC15SideScrolleriOS14MovingPlatform13setUpPlatformfCS_6PlayerT_ + 73 
    12 SideScrolleriOS      0x00000001030a9b0e _TFC15SideScrolleriOS9GameScene7didMovefT2toCSo6SKView_T_ + 12430 
    13 SideScrolleriOS      0x00000001030b6aaa _TToFC15SideScrolleriOS9GameScene7didMovefT2toCSo6SKView_T_ + 58 
    14 SpriteKit       0x0000000104d12c57 -[SKScene _didMoveToView:] + 198 
    15 SpriteKit       0x0000000104d3152e -[SKView presentScene:transition:] + 364 
    16 SideScrolleriOS      0x000000010309018d _TFC15SideScrolleriOS4Home8loadGamefT_T_ + 13805 
    17 SideScrolleriOS      0x000000010308cb1f _TFC15SideScrolleriOS4Home13pressedSelectfT_T_ + 4159 
    18 SideScrolleriOS      0x0000000103054cff _TFFC15SideScrolleriOS4Home12touchesBeganFTGVs3SetCSo7UITouch_4withGSqCSo7UIEvent__T_U_FTCSo6SKNodeGSpV10ObjectiveC8ObjCBool__T_ + 1375 
    19 SideScrolleriOS      0x0000000103043774 _TTRXFo_oCSo6SKNodedGSpV10ObjectiveC8ObjCBool___XFdCb_dS_dGSpS1____ + 68 
    20 SpriteKit       0x0000000104d4a946 -[SKNode _processSearchTokens:visited:usingBlock:stopPointer:] + 2729 
    21 SpriteKit       0x0000000104d4a083 -[SKNode _processSearchTokens:visited:usingBlock:stopPointer:] + 486 
    22 SpriteKit       0x0000000104d49d3a -[SKNode _enumerateChildNodesWithName:usingBlock:stopPointer:] + 1127 
    23 SpriteKit       0x0000000104d49612 -[SKNode enumerateChildNodesWithName:usingBlock:] + 58 
    24 SideScrolleriOS      0x0000000103054591 _TFC15SideScrolleriOS4Home12touchesBeganfTGVs3SetCSo7UITouch_4withGSqCSo7UIEvent__T_ + 737 
    25 SideScrolleriOS      0x0000000103054e96 _TToFC15SideScrolleriOS4Home12touchesBeganfTGVs3SetCSo7UITouch_4withGSqCSo7UIEvent__T_ + 102 
    26 SpriteKit       0x0000000104d2f6d6 -[SKView touchesBegan:withEvent:] + 1145 
    27 UIKit        0x0000000104feba21 -[UIWindow _sendTouchesForEvent:] + 2043 
    28 UIKit        0x0000000104fed3cf -[UIWindow sendEvent:] + 4011 
    29 UIKit        0x0000000104f9a63f -[UIApplication sendEvent:] + 371 
    30 UIKit        0x000000010578c71d __dispatchPreprocessedEventFromEventQueue + 3248 
    31 UIKit        0x00000001057853c7 __handleEventQueue + 4879 
    32 CoreFoundation      0x000000010414a311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
    33 CoreFoundation      0x000000010412f59c __CFRunLoopDoSources0 + 556 
    34 CoreFoundation      0x000000010412ea86 __CFRunLoopRun + 918 
    35 CoreFoundation      0x000000010412e494 CFRunLoopRunSpecific + 420 
    36 GraphicsServices     0x0000000108cb4a6f GSEventRunModal + 161 
    37 UIKit        0x0000000104f7c964 UIApplicationMain + 159 
    38 SideScrolleriOS      0x0000000103109ecf main + 111 
    39 libdyld.dylib      0x000000010c7c568d start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

我試着通過

  1. 修正錯誤複製我的2級和刪除一切,但猴子雪碧和照相機(和它的孩子),然後從有問題的水平粘貼一切(除了無紋理的精靈和相機)。錯誤仍然發生。

這似乎沒有發生,當我在Xcode 7中開發的東西,但切換到Swift 3和Xcode 8導致了一些奇怪的錯誤。

我試過這兩個問題級別。我無法弄清楚。遊戲構建工作正常,如果我只是讓它保持不變。 我可以在場景編輯器中添加紋理。 但是,構建崩潰。

但是,將sprite紋理化以供編輯參考會有幫助。有人有主意嗎?

+0

您的紋理大小爲6,-2.6 – Knight0fDragon

+0

解決異常時,請注意「reason」後面的部分,如「無效大小指定:{6,-2.6005233764648423}'。你的紋理高度不能是-2。也許在這個類中有一些代碼管理着計算紋理大小錯誤的級別。您還可以設置異常斷點:http:// stackoverflow。COM /問題/ 17802662 /異常斷點功能於Xcode的;並看看是否顯示了問題可能來自哪條線。 –

回答

0

由於某種原因,添加異常斷點並未顯示導致問題的代碼行。

我的代碼中的某些內容正在計算一個負值,就像錯誤所述。 我發現它的方式是試着將資產從「壞的水平」逐漸複製到工作水平。 我這樣做直到東西墜毀。 通過這樣做,我將問題隔離到一種資產類型。

原來我的代碼部分依賴於我的球員質地的大小來計算的東西。雖然這個計算幾乎從來沒有得到一個負數......在這兩個級別上。 所以擺脫玩家紋理作爲臨時修復工作,因爲它通過不被減去而阻止了負數。

相關問題