Improved snap deletion and added remove function to instance class
The current issue is that sometimes after deleting a snap and closing the game it throws an access violation (race condition?)
This commit is contained in:
@@ -25,6 +25,7 @@ public:
|
||||
void removeChild(Instance*);
|
||||
void clearChildren();
|
||||
Instance* getParent();
|
||||
void remove();
|
||||
virtual Instance* clone() const { return new Instance(*this); }
|
||||
virtual std::vector<PROPGRIDITEM> getProperties();
|
||||
virtual void PropUpdate(LPPROPGRIDITEM &pItem);
|
||||
|
||||
@@ -8,6 +8,7 @@ class SnapInstance:
|
||||
public:
|
||||
SnapInstance(PartInstance* Part1, PartInstance* Part2);
|
||||
~SnapInstance(void);
|
||||
PartInstance* Joint1;
|
||||
PartInstance* Joint2;
|
||||
PartInstance* jPart1;
|
||||
PartInstance* jPart2;
|
||||
dJointID JointID;
|
||||
};
|
||||
|
||||
@@ -17,6 +17,6 @@ public:
|
||||
void deleteBody(PartInstance* partInstance);
|
||||
void updateBody(PartInstance* partInstance);
|
||||
void resetBody(PartInstance* partInstance);
|
||||
void createJoint(PartInstance *part1, PartInstance *part2);
|
||||
void destroyJoint(PartInstance *part);
|
||||
dJointID createJoint(PartInstance *part1, PartInstance *part2);
|
||||
void destroyJoints(PartInstance *part);
|
||||
};
|
||||
@@ -87,6 +87,7 @@ Instance::~Instance(void)
|
||||
{
|
||||
delete children.at(i);
|
||||
}
|
||||
setParent(NULL);
|
||||
}
|
||||
|
||||
void Instance::setName(std::string newName)
|
||||
@@ -174,5 +175,7 @@ Instance* Instance::findFirstChild(std::string name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Instance::remove()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
@@ -20,16 +20,15 @@ void JointsService::createSnap(PartInstance* Part1, PartInstance* Part2)
|
||||
Snap->setParent(this);
|
||||
}
|
||||
|
||||
//This is only for removing the Snap instance not for removing the joint
|
||||
void JointsService::destroyPartSnap(PartInstance* Part)
|
||||
{
|
||||
std::vector<Instance* > children = getChildren();
|
||||
for(size_t i = 0; i < children.size(); i++)
|
||||
{
|
||||
SnapInstance* Snap = (SnapInstance*)children.at(i);
|
||||
if((Snap->Joint1 == Part) || (Snap->Joint2 == Part))
|
||||
if((Snap->jPart1 == Part) || (Snap->jPart2 == Part))
|
||||
{
|
||||
removeChild(Snap);
|
||||
Snap->remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,8 @@ SnapInstance::SnapInstance(PartInstance* Part1, PartInstance* Part2)
|
||||
XplicitNgine* Phys = g_xplicitNgine;
|
||||
name = "Snap";
|
||||
className = "Snap";
|
||||
Joint1 = Part1;
|
||||
Joint2 = Part2;
|
||||
jPart1 = Part1;
|
||||
jPart2 = Part2;
|
||||
|
||||
if (Part1->physBody == NULL)
|
||||
Phys->createBody(Part1);
|
||||
@@ -17,13 +17,13 @@ SnapInstance::SnapInstance(PartInstance* Part1, PartInstance* Part2)
|
||||
if (Part2->physBody == NULL)
|
||||
Phys->createBody(Part2);
|
||||
|
||||
Phys->createJoint(Part1, Part2);
|
||||
JointID = Phys->createJoint(Part1, Part2);
|
||||
}
|
||||
|
||||
SnapInstance::~SnapInstance(void)
|
||||
{
|
||||
XplicitNgine* Phys = g_xplicitNgine;
|
||||
//XplicitNgine* Phys = g_xplicitNgine;
|
||||
printf("SnapInstance destroyed...");
|
||||
Phys->destroyJoint(Joint1);
|
||||
Phys->destroyJoint(Joint2);
|
||||
if (JointID != NULL)
|
||||
dJointDestroy(JointID);
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ void XplicitNgine::updateBody(PartInstance *partInstance)
|
||||
}
|
||||
|
||||
|
||||
void XplicitNgine::createJoint(PartInstance *part1, PartInstance *part2)
|
||||
dJointID XplicitNgine::createJoint(PartInstance *part1, PartInstance *part2)
|
||||
{
|
||||
printf("XplicitNgine::createJoint called\n");
|
||||
if((part1->physBody != NULL) & (part2->physBody != NULL)){
|
||||
@@ -246,10 +246,12 @@ void XplicitNgine::createJoint(PartInstance *part1, PartInstance *part2)
|
||||
dJointID c = dJointCreateFixed(physWorld, 0);
|
||||
dJointAttach(c, part1->physBody, part2->physBody);
|
||||
dJointSetFixed(c);
|
||||
return c;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void XplicitNgine::destroyJoint(PartInstance *part)
|
||||
void XplicitNgine::destroyJoints(PartInstance *part)
|
||||
{
|
||||
for(int i = 0; i < dBodyGetNumJoints(part->physBody); i++)
|
||||
dJointDestroy(dBodyGetJoint(part->physBody, i));
|
||||
|
||||
Reference in New Issue
Block a user