std::list
에서 CCNode
개체가있는 항목을 삭제하는 데 문제가 있습니다. XCode는 erase()
요소를 시도 할 때 다음 오류를 표시합니다.std :: list에서 CCNode를 제거하면 Xcode에서 오류가 발생합니다.
error: address doesn't contain a section that points to a section in a object file
.
EXC_BAD_ACCESS code=2
어셈블리 파일에서. 나에게 EXC_BAD_ACCESS를 제공
ccGLBindTexture2D(m_pobTexture->getName());
:에
그리고 가끔 충돌합니다.
응용 프로그램을 실행할 때마다 이러한 오류 중 하나가 발생합니다.
remove() 메소드는 CCLayer에서 CCNode를 올바르게 제거하고 사라지며 노드 수는 하나씩 감소합니다. 문제는 TestObject가 여전히 testList 목록에 남아있어 메모리, CPU를 먹어 버리고 게임을 엉망으로 만든다는 것입니다.
문제를 재현 할 테스트 사례를 작성했습니다. 여기있다 : 스택 트레이스의 엑스 코드 나 단지 내부 업데이트의 몇 가지를 나열하고의 기능을 렌더링 제공
TestObject::TestObject(){
sprite = *CCSprite::createWithTexture(MainScene::hostileship_tex);
}
void TestObject::spawn(){
CCSize size = sprite.getTexture()->getContentSize();
this->setContentSize(size);
this->addChild(&sprite);
}
void TestObject::remove(){
GameLayer::getInstance().removeChild(this, true);
}
:
testList = *new list<TestObject>;
testList.push_back(*new TestObject());
addChild(&testList.back());
testList.back().spawn();
testList.back().remove();
std::list<TestObject>::iterator test = testList.begin();
while (test != testList.end())
{
if(test->isRemoved){
testList.erase(test++);
}
}
TestObject 클래스는 단순히 추가 한 다음 remove()
및 spawn()
방법과 CCNode입니다 cocos2dx, 충돌을 일으키는 원인이 무엇인지 전혀 알 수 없습니다.
감사합니다. 결국 벡터을 사용하여 CCNodes 태그를 추적하여 문제를 해결했습니다. addChild (CCNode 노드, int zIndex, int 태그) 및 getChildByTagName (int 태그) 메서드를 사용하여 부모 CCLayer에서 객체를 삽입하고 가져올 수있었습니다. 귀하의 조언은 도움이 될 것입니다. –