Code: Select all
case 8:
if (event.GUIEvent.EventType == EGET_SCROLL_BAR_CHANGED)
{
game->returnGUIMenus()->ccScreen->updateBodyPart(game->returnGUIMenus()->selectedBP);
}
break;
Code: Select all
void CCScreen::updateBodyPart(int n)
{
int shape = game->returnGUIMenus()->shapeBar->getPos();
int scaleX = game->returnGUIMenus()->scaleXBar->getPos();
int scaleY = game->returnGUIMenus()->scaleYBar->getPos();
int scaleZ = game->returnGUIMenus()->scaleZBar->getPos();
int mass = game->returnGUIMenus()->massBar->getPos();
parts.at(n)->bPart->updateBody(shape,vector3df(scaleX,scaleY,scaleZ));
parts.at(n)->shape = shape;
parts.at(n)->scalex = scaleX;
parts.at(n)->scaley = scaleY;
parts.at(n)->scalez = scaleZ;
parts.at(n)->mass = mass;
}
Code: Select all
void BodyPart::updateBody(int shape, vector3df scale)
{
// Update the irrlicht node
vector3df pos = Node->getPosition();
Node->remove();
if (shape==1)
Node = device->getSceneManager()->addCubeSceneNode(1.f);
if (shape==2)
Node = device->getSceneManager()->addSphereSceneNode(1.f);
Node->setScale(scale);
Node->setPosition(pos);
Node->setMaterialFlag(EMF_LIGHTING, false);
Node->setMaterialFlag(EMF_NORMALIZE_NORMALS, true);
// Update physics body
body->remove();
ICollisionShape *shapenew;
if (shape==1)
{
shapenew = new IBoxShape(Node, 0, false);
}
if (shape==2)
{
shapenew = new ISphereShape(Node, 0, false);
}
body = physicsworld->ReturnWorld()->addRigidBody(shapenew,1,2);
}
http://4.bp.blogspot.com/-CPyg6EaHqJI/T ... /error.JPG
even if I comment that line the crash still happens at anywhere BodyPart:: occurs. It's like the pointer in the parts struct doesn't point to a valid object but it should do, i've checked to make sure all the correct values are being passed around. Help will be greatly appreciated this is so annoying!
Thanks in advance.
EDIT:
Code: Select all
void CCScreen::addBodyPart()
{
vector3df position;
noParts++;
parts.resize(noParts);
parts.at(noParts-1) = new part;
parts.at(noParts-1)->bPart = new BodyPart;
if (noParts==1)
position = vector3df(spawnGlobal+vector3df(499400,200,0));
if (noParts==2)
position = vector3df(spawnGlobal+vector3df(499400,50,400));
parts.at(noParts-1)->bPart->init(game->returnEngine()->ReturnDevice(),game->returnPhysics(), game->returnObjects()->returnWorld(),1,vector3df(100,100,100), 0, position);
parts.at(noParts-1)->shape = 1;
parts.at(noParts-1)->scalex = 100;
parts.at(noParts-1)->scaley = 100;
parts.at(noParts-1)->scalez = 100;
parts.at(noParts-1)->mass = 0;
}
EDIT:
Replaced with cleaner code.