Render Crash

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

On 28/12/2009 at 21:26, xxxxxxxx wrote:

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

---------
For some reason, when my plugin is rendered, c4d crashes.   I can do a viewport render with no problem, but when I do a full render with the picture viewer c4d crashes.  Is there something specific I should be looking at to figure out what is causing this crash?   Does anyone have any suggestions for where to begin looking?

Thanks,

~Shawn

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

On 29/12/2009 at 07:21, xxxxxxxx wrote:

Keep in mind that when rendering in the picture viewer you render a clone of the document. So for instance if you use GetActiveDocument() in your plugin you get the currently open document and not the actual rendered document. Rendering into the editor renders the actual document and not a clone.

cheers,
Matthias

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

On 29/12/2009 at 07:26, xxxxxxxx wrote:

So when the user chooses to render in the picture viewer and my plugin uses GetActiveDocument(),  then the Active Document changes and thus the crash?

~SHawn

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

On 29/12/2009 at 07:34, xxxxxxxx wrote:

In general yes, GetActiveDocument() should not be used in a render or object creation context. Usally you get a valid document passed to these sensitive functions. Where are you using GetActiveDocument()?

Btw. what kind of plugin are we talking about, an object, tag, shader etc?

cheers,
Matthias

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

On 29/12/2009 at 07:36, xxxxxxxx wrote:

an object plugin.

I searched through the code and I do not use GetActiveDocument()..   I use GetDocument()   but never GetActiveDocument()..    I do use GetActiveObject()...

would GetActiveObject cause the same problem?

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

On 29/12/2009 at 07:53, xxxxxxxx wrote:

Originally posted by xxxxxxxx

would GetActiveObject cause the same problem?

Probably. It does sound kinda strange to me to use GetActiveObject() in an object plugin. In which context are you using this function? Anyway as long as you always check for NULL pointers and react accordingly it should not crash. But there can be alot of reasons why your plugin is crashing.

cheers,
Matthias

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

On 29/12/2009 at 08:02, xxxxxxxx wrote:

I use GetActiveObject like this

BaseObject* prnt = doc->GetActiveObject();

then whenever I need to find objects that are the children of my object I use....

prnt->GetDown()-GetNext()   etc.....

It is possible that I have not checked for a NULL pointer somewhere...    I will look around and use some GePrint() to see what is causing the crash.

~Shawn

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

On 29/12/2009 at 08:14, xxxxxxxx wrote:

I have determined that the crash is happening here:   Do you see anything that should be different?

  
  
void Planet::Free(GeListNode* node)  
{  
  GePrint("FREE");      
  BaseObject* op = static_cast<BaseTag*>(node)->GetObject();  
      if (!op) goto BYPASS;  
  
  BaseObject* prnt = op->GetDocument()->GetActiveObject();  
      if (!prnt) goto BYPASS;  
  
      //Remove Materials when Object is deleted  
      if (prnt->GetDown())  
      {  
          TextureTag* surfaceTag = (TextureTag* )(prnt->GetDown()->GetFirstTag());  
          TextureTag* lightTag = (TextureTag* )(prnt->GetDown()->GetFirstTag()->GetNext());  
          TextureTag* cloudTag = (TextureTag* )(prnt->GetDown()->GetNext()->GetFirstTag());  
          TextureTag* atmTag = (TextureTag* )(prnt->GetDown()->GetNext()->GetNext()->GetFirstTag());  
        
          surfaceTag->GetMaterial()->Remove();  
          lightTag->GetMaterial()->Remove();  
          cloudTag->GetMaterial()->Remove();  
          atmTag->GetMaterial()->Remove();  
      }  
BYPASS:;  
  
}  
  

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

On 29/12/2009 at 09:29, xxxxxxxx wrote:

yes, you must free all the materials that you have removed. You should check the docs more carefully.

_<_h4_>_void Remove(v_<_h4_>_/h4>
Remove this node from its list.

Note: When you remove a node you become responsible for freeing it, or passing the ownership to another list by inserting it there.

Furthermore you should check the pointers returned by GetDown() etc. if one of these is NULL, it´ll crash. ALWAYS check your pointers.

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

On 29/12/2009 at 10:31, xxxxxxxx wrote:

Would I free them like this?

  
  
void Planet::Free(GeListNode* node)  
{  
  GePrint("FREE");      
  GePrint("1");  
  BaseObject* op = static_cast<BaseTag*>(node)->GetObject();  
      if (!op) goto BYPASS;  
GePrint("2");  
  BaseObject* prnt = op->GetDocument()->GetActiveObject();  
      if (!prnt) goto BYPASS;  
GePrint("3");  
      //Remove Materials when Object is deleted  
      if (prnt->GetDown())  
      {  
          GePrint("4");  
          TextureTag* surfaceTag = (TextureTag* )(prnt->GetDown()->GetFirstTag());  
          TextureTag* lightTag = (TextureTag* )(prnt->GetDown()->GetFirstTag()->GetNext());  
          TextureTag* cloudTag = (TextureTag* )(prnt->GetDown()->GetNext()->GetFirstTag());  
          TextureTag* atmTag = (TextureTag* )(prnt->GetDown()->GetNext()->GetNext()->GetFirstTag());  
            
          GePrint("4.1");  
          surfaceTag->GetMaterial()->Remove();  
          lightTag->GetMaterial()->Remove();  
          cloudTag->GetMaterial()->Remove();  
          atmTag->GetMaterial()->Remove();  
  
          GePrint("4.2");  
  
          Free(surfaceTag->GetMaterial());  
          Free(lightTag->GetMaterial());  
          Free(cloudTag->GetMaterial());  
          Free(atmTag->GetMaterial());  
  
          GePrint("4.3");  
  
      }  
BYPASS:;  
GePrint("5");  
}  
  

sorry about all the GePrint()..    they are for my own debugging purposes.

~Shawn

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

On 29/12/2009 at 10:33, xxxxxxxx wrote:

that code I just sent crashes after GePrint("4.2");

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

On 29/12/2009 at 10:47, xxxxxxxx wrote:

if you remove then surfaceTag->GetMaterial() will be NULL as it is not in the scene anymore.

do it like this:

BaseMaterial\* mat1 = surfaceTag->GetMaterial();  
mat1->Remove();  
BaseMaterial::Free(mat1);

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

On 29/12/2009 at 10:59, xxxxxxxx wrote:

Okay it works great for deleting the object..,..    but when I try to render using the picture viewer,  it crashes at 4.1    here's the code I am using now.

  
void Planet::Free(GeListNode* node)  
{  
  GePrint("FREE");      
  GePrint("1");  
  BaseObject* op = static_cast<BaseTag*>(node)->GetObject();  
      if (!op) goto BYPASS;  
GePrint("2");  
  BaseObject* prnt = op->GetDocument()->GetActiveObject();  
      if (!prnt) goto BYPASS;  
GePrint("3");  
      //Remove Materials when Object is deleted  
      if (prnt->GetDown())  
      {  
            
          GePrint("4");  
          TextureTag* surfaceTag = (TextureTag* )(prnt->GetDown()->GetFirstTag());  
          TextureTag* lightTag = (TextureTag* )(prnt->GetDown()->GetFirstTag()->GetNext());  
          TextureTag* cloudTag = (TextureTag* )(prnt->GetDown()->GetNext()->GetFirstTag());  
          TextureTag* atmTag = (TextureTag* )(prnt->GetDown()->GetNext()->GetNext()->GetFirstTag());  
            
          GePrint("4.1");  
          BaseMaterial* sMat = surfaceTag->GetMaterial();  
          sMat->Remove();  
          BaseMaterial::Free(sMat);  
            
          GePrint("4.2");  
          BaseMaterial* lMat = lightTag->GetMaterial();  
          lMat->Remove();  
          BaseMaterial::Free(lMat);  
            
          GePrint("4.3");  
          BaseMaterial* cMat = cloudTag->GetMaterial();  
          cMat->Remove();  
          BaseMaterial::Free(cMat);  
            
          GePrint("4.4");  
          BaseMaterial* aMat = atmTag->GetMaterial();  
          aMat->Remove();  
          BaseMaterial::Free(aMat);  
            
          GePrint("4.5");  
  
      }  
BYPASS:;  
GePrint("5");  
}  

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

On 29/12/2009 at 11:58, xxxxxxxx wrote:

Please check your TextureTag* pointers!

cheers,
Matthias

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

On 30/12/2009 at 06:12, xxxxxxxx wrote:

Yep.  That was the problem.  I needed to check for NULL pointers for all of the pointers in this member function.   Thanks guys.

~Shawn