Collider-cache Null-Object memleak

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 22/07/2011 at 13:57, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   12 
Platform:   Windows  ;   
Language(s) :     C++  ;

---------
Hi,

i have a problem with te Collider Engine.
I want to fill the Collider Cache with all Objects in the Scene,
to make a hiddenline Test.

So all is ok with my function, but if there is a Null-Objekct in the Scene, than
my memory usage increases rapidly so that the plugin finaly crashes the computer
if I don't stop. I think the problem is in FillColliderCache which i have mostly taken from the SDK help.

I don't know why this happens and how to work around this.
Maybe you have an Idea ?

Thanks,:slightly_smiling_face:

Mackel

For the hiddenlineTest I use this:

while(opc){
  GePrint(opc->GetName());
  if(!FillColliderCache(cCache, opc)) GePrint("Fail Cache");
  else{
      GePrint(opc->GetName());
      for(int i = 0; i <= 100; i++){
          if(opc->GetType() != Onull) //make shure it is not my code in here that causes the problem
          {
              //Do some stuff

if(cEngine->DoRayCollide(cCache,wtail, !oray,op != opc ? ldist : (ldist-0.1)) != COL_OK)
                  GePrint("Error");

else if(cEngine->GetNumPairs() > 0){
                  count ++;
                  GePrint(opc->GetName() + "Collision begin" + LongToString(cEngine->GetNumPairs()));                          
                  collisions _= true;
              }
              else if(cEngine->GetNumPairs()== 0){
                  count ++;
              }
          }
      }
  }
                                         
  if(opc->GetDown()){
      level++;
      opc = opc->GetDown();
  }else if(opc->GetNext()){
      opc = opc->GetNext();
  }else if( level > 0){
      opc = opc->GetUp()->GetNext();
      level--;
  }else{
      opc = opc->GetNext();
  }
}

Filling the ColliderChace I using this:

Bool FillColliderCache(GeColliderCache* c, BaseObject* obj)
  { 
      // Get polygon object
      ModelingCommandData md1;
      md1.op = obj; md1.doc = obj->GetDocument();
      if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, md1)) return FALSE;
 
      // Triangulate it
      ModelingCommandData md2;
      md2.op = static_cast<BaseObject*>(md1.result->GetIndex(0));
      if (!SendModelingCommand(MCOMMAND_TRIANGULATE, md2)) return FALSE;
      AutoAlloc<PolygonObject> poly(static_cast<PolygonObject*>(md2.op)); if (!poly) return FALSE;
 
      // Get the polygon data
      const CPolygon* tris = poly->GetPolygonR();
      const Vector* points = poly->GetPointR();

//GeColliderCache* c = GeColliderCache::Alloc();
 
      // Fill the cache
      if (c->BeginInput(poly->GetPolygonCount()) != COL_OK) return FALSE;
      for (int i = 0; i < poly->GetPolygonCount(); ++i)
      {
        if (c->AddTriangle(obj->GetMg() * points[tris _.a], obj- >GetMg() * points[tris _.b], obj- >GetMg() * points[tris _.c], i) != COL_OK) return FALSE;
      }
      if (c->EndInput() != COL_OK) return FALSE;
 
      //bool succ = c->CopyTo(dest);

poly.Free();

//GeColliderCache::Free(c);

return true;//succ;
  }

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 22/07/2011 at 16:20, xxxxxxxx wrote:

1. The object for GeCollider must be a polygon object.

2. Current-State-To-Object returns the cache result so your polygon object may be under a Null object:

Null
-- Mesh

To avoid that situation, I call a method after doing the CSTO to find the polygon object that might be childed under something else.

  
{  
...  
  if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, mcd) && mcd.result)  
      return NULL;  
  // Get result  
  PolygonObject*        cstoObj =    ToPoly(mcd.result->GetIndex(0L));  
  AtomArray::Free(mcd.result);  
  if (!cstoObj)                    return NULL;  
  return GetCSTOObject(cstoObj);  
}  
// Drill down into mainop and find the polygon object (if any)  
//*---------------------------------------------------------------------------*  
PolygonObject* CollisionDeformerObj::GetCSTOObject(BaseObject* op)  
//*---------------------------------------------------------------------------*  
{  
  PolygonObject*    pop    =    NULL;  
  for (; op; op = op->GetNext())  
  {  
      if (op->GetType() == Opolygon)    return ToPoly(op);  
      if (op->GetDown())  
      {  
          pop =        GetCSTOObject(op->GetDown());  
          if (pop)    return pop;  
      }  
  }  
  return NULL;  
}