forked from Mirrors/openclonk
Rope: Fix crash when a connected object is removed
parent
dd4469ec30
commit
72d4aa69c5
|
@ -914,6 +914,7 @@ void C4Game::ClearPointers(C4Object * pObj)
|
|||
TransferZones.ClearPointers(pObj);
|
||||
if (pGlobalEffects)
|
||||
pGlobalEffects->ClearPointers(pObj);
|
||||
Ropes.ClearPointers(pObj);
|
||||
}
|
||||
|
||||
bool C4Game::TogglePause()
|
||||
|
|
|
@ -262,7 +262,6 @@ void C4RopeElement::Execute(const C4Rope* rope, C4Real dt)
|
|||
if(Target->Shape.GetVertexContact(i, dwCNATCheck, Target->GetX(), Target->GetY()))
|
||||
iContactVertex = i;
|
||||
|
||||
// TODO: Check force redirection at the vertex which has contact
|
||||
if(iContactVertex != -1)
|
||||
SetForceRedirection(rope, Target->Shape.VtxX[iContactVertex], Target->Shape.VtxY[iContactVertex]);
|
||||
}
|
||||
|
@ -590,6 +589,23 @@ void C4Rope::Execute()
|
|||
}
|
||||
}
|
||||
|
||||
void C4Rope::ClearPointers(C4Object* obj)
|
||||
{
|
||||
for(C4RopeElement* cur = Front; cur != NULL; cur = cur->Next)
|
||||
{
|
||||
if(cur->GetObject() == obj)
|
||||
{
|
||||
cur->x = obj->fix_x;
|
||||
cur->y = obj->fix_y;
|
||||
cur->vx = obj->xdir;
|
||||
cur->vy = obj->ydir;
|
||||
cur->m = obj->Mass;
|
||||
|
||||
cur->Object = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Move this to StdGL
|
||||
void C4Rope::Draw(C4TargetFacet& cgo, C4BltTransform* pTransform)
|
||||
{
|
||||
|
@ -769,3 +785,9 @@ void C4RopeList::Draw(C4TargetFacet& cgo, C4BltTransform* pTransform)
|
|||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void C4RopeList::ClearPointers(C4Object* obj)
|
||||
{
|
||||
for(unsigned int i = 0; i < Ropes.size(); ++i)
|
||||
Ropes[i]->ClearPointers(obj);
|
||||
}
|
||||
|
|
|
@ -72,6 +72,8 @@ public:
|
|||
void Draw(C4TargetFacet& cgo, C4BltTransform* pTransform);
|
||||
void Execute();
|
||||
|
||||
void ClearPointers(C4Object* obj);
|
||||
|
||||
C4Real GetSegmentLength() const { return l; }
|
||||
C4Real GetOuterFriction() const { return mu; }
|
||||
|
||||
|
@ -97,11 +99,6 @@ private:
|
|||
C4DefGraphics* Graphics;
|
||||
int32_t SegmentCount;
|
||||
|
||||
// TODO: Add a "dynlength" feature which adapts the spring length to the
|
||||
// distance of the two ends, up to a maximum... and/or callbacks to script
|
||||
// when the length should be changed so that script can do it (and maybe
|
||||
// play an animation, such as for the lift tower).
|
||||
|
||||
C4Real l; // spring length in equilibrium
|
||||
C4Real k; // spring constant
|
||||
C4Real mu; // outer friction constant
|
||||
|
@ -141,6 +138,8 @@ public:
|
|||
|
||||
C4Rope* CreateRope(C4Object* first_obj, C4Object* second_obj, int32_t n_segments, C4DefGraphics* graphics);
|
||||
|
||||
void ClearPointers(C4Object* obj);
|
||||
|
||||
private:
|
||||
C4RopeAul RopeAul;
|
||||
std::vector<C4Rope*> Ropes;
|
||||
|
|
Loading…
Reference in New Issue