之前下载过前一个3.3的非正式版,发现多了ActionTimelineTestScene
于是就跑了跑,能够进入帧事件的测试场景预览效果
但是这一次正式版本,居然发现ActionTimelineTestScene当中唯独缺少了 TEST_TIMELINE_FRAME_EVENT 这个测试场景,
带着好奇我进入了工程代码,看到引擎在两个地方增加了两条注释:
ActionTimelineTestScene.h
line:23
enum {
TEST_ANIMATIONELEMENT = 0,
TEST_CHANGE_PLAY_SECTION,
TEST_TIMELINE_FRAME_EVENT, 【这个地方】
TEST_TIMELINE_PERFORMACE,
TEST_ANIMATION_LAYER_COUNT
};
ActionTimelineTestScene.cpp
line:30
Layer *CreateAnimationLayer(int index)
{
case TEST_TIMELINE_FRAME_EVENT: 【这附近】
}
崩溃日志显示:
suffix = csb
First-chance exception at 0x0FB5C296 (libcocos2d.dll) in cpp-tests.exe: 0xC0000005: Access violation reading location 0x3508A462.
Unhandled exception at 0x0FB5C296 (libcocos2d.dll) in cpp-tests.exe: 0xC0000005: Access violation reading location 0x3508A462.
跟进错误的代码,发现了导致错误的地方:
// TestFrameEvent
void TestTimelineFrameEvent::onEnter()
{
ActionTimelineTestLayer::onEnter();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("armature/Cowboy0.plist", "armature/Cowboy0.png");
Node* node = CSLoader::createNode("ActionTimeline/boy_1.csb"); 【这一行出现了错误】
ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/boy_1.csb");
}
C:\dev\source\cocos2d-x-3.3\cocos2d-x-3.3\cocos\editor-support\cocostudio\ActionTimeline
CSLoader.cpp
CSLoader* load = CSLoader::getInstance();
return load->createNodeWithFlatBuffersFile(filename); 【这一行】
CSLoader.cpp
Node* node = nodeWithFlatBuffersFile(filename);
Node* CSLoader::nodeWithFlatBuffersFile(const std::string &fileName)
{
auto csparsebinary = GetCSParseBinary(buf.getBytes()); 【真正错误发生在这一行】
[Unable to read memory]
// decode plist
auto textures = csparsebinary->textures(); 【这一行发生crash】
int textureSize = csparsebinary->textures()->size();
}
读取的文件是这一个:
cocos2d-x-3.3\tests\cpp-tests\Resources\ActionTimeline\DemoPlayer.csb
容量只有14.0 KB
也就是官方并没有使用自己的二进制的解析格式,而是贯彻拿来主义,不重复造车轮的精神~吸取了开源社区的力量,认了google做干爹 ^ ^。
可是这个干爹貌似也不是十全十美能事事包办得了的。。所以在解析的时候出现了问题
为什么会解析错误!?目前还不得而知,猜去猜来也就是有几种可能:
1. FlatBuffers对二进制的解析不完善
2. 官方在使用过程中有一些地方操作不得当,造成了bug
于是我想起了官方的更新日志里提到的一句话:
cocos2d-x 3.3最终版发布
http://cocos2d-x.org/news/387
Performance
Cocos Studio Reader: use Flat Buffer for data format
cocostudio的Reader使用了FlatBuffers作为数据格式,当然标题写得很清楚,是为了性能
引擎作者在发布新引擎之前,估计是没能搞定这个问题,所以为了不拖延项目时间结点,采取了注掉方案,之后再慢慢研究,如果是很简单的问题估计很快就修正了,就不会预留到下一个版本以后解决了。
可惜为了性能,一些功能成为了残疾。。有点得不偿失的感觉。
想起了下午研究FlatBuffers的一些相关知识,确实这个东东是最新的高效序列化解决方案,值得研究!^ ^~