如题 ,出现堆无法分配内存的问题
求教如何解决
代码贴出来?你用的是哪个版本?怎么会用new
2.2.3版本的 , 移植到3.0上依旧存在这个问题
void CrossActorEffect::PlayEffect(int actorId , CCPoint start , CCPoint boomPoint , CCNode* parent , float timer )
{
m_boom = CCSprite::create();
m_boomAni = CCAnimation::create();
m_boomAni->retain();
for(int i = 0 ;i < 8 ; i++)
{
char szImage = {0};
sprintf(szImage,“Effects/NineLinkEffect/bamboo%d.png”,i+1);
CCTexture2D* tex = GameCenter::SharedCenter()->GetTexture(szImage);
m_boomAni->addSpriteFrameWithTexture(tex , CCRect(0,0,tex->getPixelsWide() , tex->getPixelsHigh()));
}
m_boomAni->setRestoreOriginalFrame(true);
m_boomAni->setDelayPerUnit(0.3f / 5.0f);
m_line = CCSprite::createWithTexture(GameCenter::SharedCenter()->GetTexture("Effects/NineLinkEffect/line.png"));
m_shine = CCSprite::createWithTexture(GameCenter::SharedCenter()->GetTexture("Effects/NineLinkEffect/shine.png"));
m_direction = -ccpNormalize(ccpSub(boomPoint , start));
m_distance = ccpDistance(start,boomPoint);
float angel = ccpAngleSigned( ccpSub(boomPoint , start) , ccpSub(boomPoint , ccp(0.0f , boomPoint.y))) * 180.0f / 3.14f;
m_boomPoint = boomPoint;
m_effSpd = timer;
m_line->setAnchorPoint(ccp(0.0f, 0.5f));
m_line->setScaleX(0.1f);
m_line->setScaleY(0.1f);
m_line->setPosition(start);
float scale1 = m_line->getScaleX();
float scale2 = m_line->getScaleY();
if(m_boom->getParent() == NULL)
parent->addChild(m_boom,90);
m_boom->setPosition(boomPoint);
m_boom->setScale(1.7f);
if(m_line->getParent() == NULL)
parent->addChild(m_line,90);
m_line->setRotation(angel);
m_shine->setScaleX(640.0f);
m_shine->setScaleY(960.0f);
m_shine->setPosition(ccp(320,480));
m_shine->setVisible(false);
m_shine->setOpacity(150);
ccColor3B color;
color.r = 254;
color.g = 255;
color.b = 162;
m_shine->setColor(color);
if(m_shine->getParent() == NULL)
parent->addChild(m_shine,80);
CCAction* scaleAct = CCSequence::create(CCScaleTo::create(m_effSpd,1.0f,3.0f) ,CCCallFunc::create(this,callfunc_selector(CrossActorEffect::ActorOnBoomPoint)) , NULL);
m_line->runAction(scaleAct);
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("SoundEffect/Slash.mp3");
}
在boom create的时候出错
其实是使用create时候,COCOS2DX 调用的new sprite
不知道为何,在某个节点上只要new 任何的sprite都会出现这个问题
很明显不是new sprite的问题,你的程序是在手机上跑吗?看下你实际内存已经使用了多少,你的程序估计有内存问题导致的,应该是内存泄露的问题
WIN32平台, 实际内存使用了约50MB左右
遇到同样问题 不过我的是真机调试时才会出
模拟器上不会报错
问题就在于在同一个地点,我尝试使用malloc申请了1000000的内存,依旧没有报错,但是使用new spirte就会报错
Visual Leak Detector detected 960 memory leaks (62717 bytes).
Largest number used: 636886 bytes.
Total allocations: 1563715 bytes.
Visual Leak Detector is now exiting.
用vld检测了一下内存泄露, 总共6M的泄露(部分是临时关闭没有主动释放)
应该没道理申请不了内存