cocos2d-x v3.0:使用Label类崩溃

时间:2014-05-11 15:03:36

标签: android c++ cocos2d-x

我的cocos2d-x项目是用v3.0 beta制作的。 我升级到v3.0rc2。 我使用eclipse开发android项目。 我使用genymotion模拟器。

我遇到了Label类问题。 继承我的代码来设置Label。

auto label = Label::createWithTTF("hogehoge", "fonts/Perfect Dark Zone.ttf", 40);
label->setPosition(Point(visibleSize.width/2, visibleSize.height/2));
this->addChild(label, HelloWorld::kText1, HelloWorld::kZOrderText);
日食中的继承人错误。

    05-11 14:46:32.446: D/cocos2d-x debug info(1442): {
    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   gl.supports_vertex_array_object: false
    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   gl.supports_BGRA8888: false
    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   gl.supports_ATITC: false
    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   gl.supports_S3TC: false
    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   cocos2d.x.version: cocos2d-x 3.0
    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   gl.supports_discard_framebuffer: false
    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   cocos2d.x.compiled_with_profiler: false

    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   gl.supports_PVRTC: false
    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   cocos2d.x.build_type: DEBUG
    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   gl.renderer: Android Emulator OpenGL ES Translator (Intel HD Graphics 5000 OpenGL Engine)
    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   gl.supports_ETC1: true
    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   cocos2d.x.compiled_with_gl_state_cache: true
    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   gl.version: OpenGL ES 2.0 (2.1 INTEL-8.24.12)
    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   gl.supports_NPOT: true
    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   gl.max_texture_units: 16
    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   gl.vendor: Google (Intel Inc.)
    05-11 14:46:32.446: D/cocos2d-x debug info(1442):   gl.max_texture_size: 16384
    05-11 14:46:32.446: D/cocos2d-x debug info(1442): }
    05-11 14:46:32.522: I/ActivityManager(539): Displayed com.kn.gravity/org.cocos2dx.cpp.AppActivity: +263ms
    05-11 14:46:32.782: D/main(1442): cocos_android_app_init
    05-11 14:46:32.782: D/CCFileUtilsAndroid.cpp(1442): relative path = CloseNormal.png
    05-11 14:46:32.786: D/CCFileUtilsAndroid.cpp(1442): relative path = CloseSelected.png
    05-11 14:46:32.786: A/libc(1442): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 1455 (Thread-102)
    05-11 14:46:32.890: I/DEBUG(106): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    05-11 14:46:32.890: I/DEBUG(106): Build fingerprint: 'generic/vbox86tp/vbox86tp:4.4.2/KOT49H/eng.buildbot.20140326.034346:userdebug/test-keys'
    05-11 14:46:32.890: I/DEBUG(106): Revision: '0'
    05-11 14:46:32.890: I/DEBUG(106): pid: 1442, tid: 1455, name: Thread-102  >>> com.kn.gravity 
    05-11 14:46:33.078: I/DEBUG(106):     #11  pc 0003b962  /system/lib/libdvm.so (dvmMterpStd(Thread*)+66)
    05-11 14:46:33.078: I/DEBUG(106):     #12  pc 00037029  /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+217)
    05-11 14:46:33.078: I/DEBUG(106):     #13  pc 000bd097  /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, char*)+759)
    05-11 14:46:33.078: I/DEBUG(106):     #14  pc 000bd4a7  /system/lib/libdvm.so (dvmCallMethod(Thread*, Method const*, Object*, JValue*, ...)+55)
    05-11 14:46:33.078: I/DEBUG(106):     #15  pc 00099433  /system/lib/libdvm.so (interpThreadStart(void*)+995)
    05-11 14:46:33.078: I/DEBUG(106):     #16  pc 0000bc7c  /system/lib/libc.so (__thread_entry+236)
    05-11 14:46:33.078: I/DEBUG(106):     #17  pc 0003e295  /system/lib/libc.so (__pthread_clone+69)
    05-11 14:46:33.078: I/DEBUG(106):     #18  pc 0009904f  /system/lib/libdvm.so (internalThreadStart(void*)+655)
    05-11 14:46:33.078: I/DEBUG(106):     #19  pc ffffffff  
    05-11 14:46:33.078: I/DEBUG(106):     #20  pc 000005ae  
    05-11 14:46:33.078: I/DEBUG(106):     #21  pc 00000022  
    05-11 14:46:33.078: I/DEBUG(106):     #22  pc 0003bbdf  /system/lib/libbinder.so
    05-11 14:46:33.078: I/DEBUG(106):     #23  pc 00012eaf  /system/lib/libutils.so
    05-11 14:46:33.078: I/DEBUG(106):     #24  pc 00012ebf  /system/lib/libutils.so
    05-11 14:46:33.078: I/DEBUG(106):     #25  pc ffffffff  
    05-11 14:46:33.078: I/DEBUG(106): stack:
    05-11 14:46:33.078: I/DEBUG(106):          95895800  b8bc67b0  [heap]
    05-11 14:46:33.078: I/DEBUG(106):          95895804  b8bc6338  [heap]
    05-11 14:46:33.078: I/DEBUG(106):          95895808  95655bb9  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so
    05-11 14:46:33.078: I/DEBUG(106):          9589580c  9577eb90  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so
    05-11 14:46:33.078: I/DEBUG(106):          95895810  956823b0  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so
    05-11 14:46:33.078: I/DEBUG(106):          95895814  95614586  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so (operator delete(void*)+6)
    05-11 14:46:33.078: I/DEBUG(106):          95895818  9577eb90  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so
    05-11 14:46:33.078: I/DEBUG(106):          9589581c  95653fbc  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so
    05-11 14:46:33.078: I/DEBUG(106):          95895820  b8bc67b0  [heap]
    05-11 14:46:33.078: I/DEBUG(106):          95895824  956823b8  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so
    05-11 14:46:33.078: I/DEBUG(106):          95895828  953a204b  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so (cocos2d::Label::createWithTTF(std::string const&, std::string const&, float, cocos2d::Size const&, cocos2d::TextHAlignment, cocos2d::TextVAlignment)+11)
    05-11 14:46:33.078: I/DEBUG(106):          9589582c  9577eb90  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so
    05-11 14:46:33.078: I/DEBUG(106):          95895830  95895890  [stack:1455]
    05-11 14:46:33.078: I/DEBUG(106):          95895834  95653fa6  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so
    05-11 14:46:33.078: I/DEBUG(106):          95895838  9577eb90  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so
    05-11 14:46:33.078: I/DEBUG(106):          9589583c  95350f29  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so (HelloWorld::init()+1145)
    05-11 14:46:33.078: I/DEBUG(106):     #00  95895840  b8bc67b0  [heap]
    05-11 14:46:33.078: I/DEBUG(106):          95895844  95895890  [stack:1455]
    05-11 14:46:33.078: I/DEBUG(106):          95895848  42200000  
    05-11 14:46:33.078: I/DEBUG(106):          9589584c  9578a724  
    05-11 14:46:33.078: I/DEBUG(106):          95895850  00000000  
    05-11 14:46:33.078: I/DEBUG(106):          95895854  00000000  
    05-11 14:46:33.078: I/DEBUG(106):          95895858  953b7760  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so (cocos2d::Node::setPosition(cocos2d::Point const&))
    05-11 14:46:33.078: I/DEBUG(106):          9589585c  44480000  
    05-11 14:46:33.082: I/DEBUG(106):          95895860  9589588e  [stack:1455]
    05-11 14:46:33.082: I/DEBUG(106):          95895864  9589588d  [stack:1455]
    05-11 14:46:33.082: I/DEBUG(106):          95895868  95895890  [stack:1455]
    05-11 14:46:33.082: I/DEBUG(106):          9589586c  9589588f  [stack:1455]
    05-11 14:46:33.082: I/DEBUG(106):          95895870  958958a4  [stack:1455]
    05-11 14:46:33.082: I/DEBUG(106):          95895874  41a00000  
    05-11 14:46:33.082: I/DEBUG(106):          95895878  01000000  
    05-11 14:46:33.082: I/DEBUG(106):          9589587c  b8bc57c8  [heap]
    05-11 14:46:33.082: I/DEBUG(106):          ........  ........
    05-11 14:46:33.082: I/DEBUG(106):     #01  958958e0  b8bc57c8  [heap]
    05-11 14:46:33.082: I/DEBUG(106):          958958e4  9577eb90  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so
    05-11 14:46:33.082: I/DEBUG(106):          958958e8  b8b90390  [heap]
    05-11 14:46:33.082: I/DEBUG(106):          958958ec  9537c65d  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so (cocos2d::DisplayLinkDirector::setAnimationInterval(double)+45)
    05-11 14:46:33.082: I/DEBUG(106):          958958f0  b8b90390  [heap]
    05-11 14:46:33.082: I/DEBUG(106):          958958f4  b8ba80d0  [heap]
    05-11 14:46:33.082: I/DEBUG(106):          958958f8  95350f69  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so (HelloWorld::createScene()+9)
    05-11 14:46:33.082: I/DEBUG(106):          958958fc  9577eb90  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so
    05-11 14:46:33.082: I/DEBUG(106):          95895900  b8b90390  [heap]
    05-11 14:46:33.082: I/DEBUG(106):          95895904  b8ba80d0  [heap]
    05-11 14:46:33.082: I/DEBUG(106):          95895908  958959f8  [stack:1455]
    05-11 14:46:33.082: I/DEBUG(106):          9589590c  953503ef  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so (AppDelegate::applicationDidFinishLaunching()+63)
    05-11 14:46:33.082: I/DEBUG(106):     #02  95895910  b8b90390  [heap]
    05-11 14:46:33.082: I/DEBUG(106):          95895914  11111111  
    05-11 14:46:33.082: I/DEBUG(106):          95895918  3f911111  
    05-11 14:46:33.082: I/DEBUG(106):          9589591c  953504ad  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so (AppDelegate::AppDelegate()+29)
    05-11 14:46:33.082: I/DEBUG(106):          95895920  b8ba3fd0  [heap]
    05-11 14:46:33.082: I/DEBUG(106):          95895924  9577eb90  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so
    05-11 14:46:33.082: I/DEBUG(106):          95895928  b77a07a9  /system/lib/liblog.so (__android_log_print+9)
    05-11 14:46:33.082: I/DEBUG(106):          9589592c  953503b8  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so (AppDelegate::applicationDidFinishLaunching()+8)
    05-11 14:46:33.082: I/DEBUG(106):          95895930  9577eb90  /data/app-lib/com.kn.gravity-1/libcocos2dcpp.so
    05-11 14:46:33.082: I/DEBUG(106):          95895934  b8b90390  [heap]
    05-11 14:46:33.082: I/DEBUG(106):          95895938  b8ba80d0  [heap]
    05-11 14:46:33.082: I/DEBUG(106):          9589593c  9550c580  /data/app-lib/com.kn.gravity-1/libcocos2dcpp

.so (cocos2d::Application::run()+16)

请帮帮我。

4 个答案:

答案 0 :(得分:1)

how to declare label in global class (helloworld.h) with cocos2d-x v3.2?

首先在资产文件夹中添加fount。

ios就像这样使用

"Perfect Dark Zone.ttf"

android就像这样使用

"Perfect Dark Zone"

答案 1 :(得分:0)

我遇到了同样的问题,并通过从fontName参数中删除路径来修复它。

尝试

"完美黑暗Zone.ttf"

而不是

" fonts / Perfect Dark Zone.ttf"

答案 2 :(得分:0)

试试这个

 auto label = Label::createWithTTF("hogehoge", "Perfect Dark Zone.ttf", 40);
        label->setPosition(Point(visibleSize.width/2, visibleSize.height/2));
        this->addChild(label,1);

答案 3 :(得分:0)

我正要失去男人!这个虫子很讨厌,感谢上帝,我在放弃之前就幸运了!(希望这也能解决你的问题)

尝试尊重字体名称的确切格式(大写等),这是我之前的代码

cocos2d::Label* gameOver = cocos2d::Label::createWithTTF("OVER!", "fonts/Roboto-Light.TTF", 26 * fratio);
尝试此后

cocos2d::Label* gameOver = cocos2d::Label::createWithTTF("OVER!", "fonts/Roboto-Light.ttf", 26 * fratio);

一切正常