2014-08-31 56 views
0

我遵循Harry的cocos3d教程。cocos2d2.x上的cocos3d 3.1。重命名圖層導致崩潰

新建一個HelloWorld模板項目命名形狀:

它運行完美。

然後我重命名shapesLayer:重構 - >將其重命名爲MainLayer。

應用崩潰:

cocos2d: cocos2d-iphone v2.1 
cocos2d: compiled with Profiling Support: NO 
cocos2d: OS version: 7.1 (0x07010000) 
cocos2d: GL_VENDOR: Apple Computer, Inc. 
cocos2d: GL_RENDERER: Apple Software Renderer 
cocos2d: GL_VERSION: OpenGL ES 2.0 APPLE-9.4.3 
cocos2d: GL_MAX_TEXTURE_SIZE: 4096 
cocos2d: GL_MAX_TEXTURE_UNITS: 8 
cocos2d: GL_MAX_SAMPLES: 4 
cocos2d: GL supports PVRTC: YES 
cocos2d: GL supports BGRA8888 textures: YES 
cocos2d: GL supports NPOT textures: YES 
cocos2d: GL supports discard_framebuffer: YES 
cocos2d: GL supports shareable VAO: NO 
2014-08-31 11:25:11.966 shapes[9466:60b] cocos2d: viewDidLoad 
2014-08-31 11:25:11.967 shapes[9466:60b] cocos2d: animation started with frame interval: 60.00 
2014-08-31 11:25:11.969 shapes[9466:60b] cocos2d: surface size: 640x960 
[***ERROR***] MainLayer on (null) could not determine the appropriate class to instantiate to automatically populate the cc3Scene property. 
2014-08-31 11:25:11.970 shapes[9466:60b] *** Assertion failure in -[MainLayer cc3SceneClass], /Users/yetao/Documents/shapes/cocos3d/cocos3d/cocos3d/Scenes/CC3Layer.m:106 
2014-08-31 11:25:11.973 shapes[9466:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'See previous logged error.' 
*** First throw call stack: 
(
    0 CoreFoundation      0x0298f1e4 __exceptionPreprocess + 180 
    1 libobjc.A.dylib      0x0270e8e5 objc_exception_throw + 44 
    2 CoreFoundation      0x0298f048 +[NSException raise:format:arguments:] + 136 
    3 Foundation       0x006ea4de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116 
    4 shapes        0x0005f565 -[CC3Layer cc3SceneClass] + 949 
    5 shapes        0x0005eff0 -[CC3Layer cc3Scene] + 80 
    6 shapes        0x00060ab3 -[CC3Layer updateViewport] + 611 
    7 shapes        0x00060718 -[CC3Layer contentSizeChanged] + 88 
    8 shapes        0x0005e50d -[CCLayer(CC3) setContentSize:] + 269 
    9 shapes        0x001ddeac -[CCLayer init] + 252 
    10 shapes        0x0005f6c6 -[CC3Layer init] + 86 
    11 shapes        0x0005e3e5 +[CCLayer(CC3) layer] + 69 
    12 shapes        0x0000412a -[AppDelegate application:didFinishLaunchingWithOptions:] + 586 
    13 UIKit        0x017ee14f -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309 
    14 UIKit        0x017eeaa1 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1810 
    15 UIKit        0x017f3667 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824 
    16 UIKit        0x01807f92 -[UIApplication handleEvent:withNewEvent:] + 3517 
    17 UIKit        0x01808555 -[UIApplication sendEvent:] + 85 
    18 UIKit        0x017f5250 _UIApplicationHandleEvent + 683 
    19 GraphicsServices     0x03ebcf02 _PurpleEventCallback + 776 
    20 GraphicsServices     0x03ebca0d PurpleEventCallback + 46 
    21 CoreFoundation      0x0290aca5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53 
    22 CoreFoundation      0x0290a9db __CFRunLoopDoSource1 + 523 
    23 CoreFoundation      0x0293568c __CFRunLoopRun + 2156 
    24 CoreFoundation      0x029349d3 CFRunLoopRunSpecific + 467 
    25 CoreFoundation      0x029347eb CFRunLoopRunInMode + 123 
    26 UIKit        0x017f2d9c -[UIApplication _run] + 840 
    27 UIKit        0x017f4f9b UIApplicationMain + 1225 
    28 shapes        0x00003d2c main + 92 
    29 shapes        0x00002cd5 start + 53 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) instantiate to automatically populate the cc3Scene property 

我調試到它:

CC3Layer* cc3Layer = [MainLayer layer]; 

它只是崩潰......

我其重命名爲shapesLayer。它可以工作。

那麼,我該如何做重命名的事情,爲什麼它崩潰?

回答

0

我無語約CC3Layer.m:

他們需要共享一個相同的前綴。

MainLayer-> MainScene。 shapesLayer-> shapesScecne。

-(Class) cc3SceneClass { 
    Class sceneClass = nil; 
    NSString* baseName = nil; 
    NSString* layerClassName = NSStringFromClass(self.class); 

    // If layer class name ends in "Layer", strip it and try some combinations 
    if ([layerClassName hasSuffix: @"Layer"]) { 
     baseName = [layerClassName substringToIndex: (layerClassName.length - @"Layer".length)]; 

     // Try HelloLayer -> HelloScene 
     sceneClass = NSClassFromString([NSString stringWithFormat: @"%@Scene", baseName]); 
     if (sceneClass && [sceneClass isSubclassOfClass: CC3Scene.class]) return sceneClass; 

     // Try HelloLayer -> Hello 
     sceneClass = NSClassFromString(baseName); 
     if (sceneClass && [sceneClass isSubclassOfClass: CC3Scene.class]) return sceneClass; 
    } 

    // Try Hello -> HelloScene (including HelloLayer -> HelloLayerScene) 
    sceneClass = NSClassFromString([NSString stringWithFormat: @"%@Scene", layerClassName]); 
    if (sceneClass && [sceneClass isSubclassOfClass: CC3Scene.class]) return sceneClass; 

    CC3Assert(NO, @"%@ could not determine the appropriate class to instantiate to automatically populate the cc3Scene property.", self); 
    return nil; 
} 

問題解決。

對於其他場景,我只是將它加入在openlayer部分

+0

我不知道你所說的是「無語」這個意思。 :^)你自定義的'CC3Layer'和'CC3Scene'子類不需要***共享一個名稱前綴。但是當他們這樣做的時候,這個附加功能允許你避免分別實例化它們並將它們連接在一起(即「它不是一個bug,它是一個特性!」; ^))。 – 2014-09-02 19:05:44

+0

如果你不想使用這個特性,那麼你可以簡單地恢復實例化你自己的'CC3Layer'和'CC3Scene'子類的實例,並設置'myLayer.cc3Scene = myScene'。或者覆蓋'CC3Layer'子類中的'cc3Scene'或'cc3SceneClass'屬性方法來自動實例化並附加你想要的任何'CC3Scene'子類。有關詳細信息,請參閱'CC3Layer cc3SceneClass'屬性的註釋。 – 2014-09-02 19:07:25

+0

是的。我正在那樣做。 THX〜 – user1990402 2014-09-17 11:11:49