用cocostudio编辑了一个UI,层次结构如下
RootLayer(1)
ScrollView(2)
Layer(3)
在程序中加载该UI,同时取出Layer(3),然后用代码动态创建Node,调用Layer(3)->addChild(Node)。
代码片断:
auto rootLayer = GUIReader::getInstance()->widgetFromJsonFile(“WorldMapLayer.json”);
auto worldSv = rootLayer->getChildByName(“world_sv”);
auto citysLayer = worldSv->getChildByName(“citys_layer”);
Sprite* sprite = Sprite::create();
citysLayer->addChild(sprite);
this->addChild(rootLayer);
当运行到citysLayer->addChlid(sprite);时,报错 vector subscript out of range
详细如下:
Program: C:\windows\system32\MSVCP120D.dll
File: D:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector
Line: 1201
Expression: vector subscript out of range
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
求解
这个帖子也是同样错误提示:http://www.cocoachina.com/bbs/read.php?tid=180738