THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/08/2007 at 05:26, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 9.507
Platform: Windows ;
Language(s) : C++ ;
---------
I want to find out all cameras from active scene. I use the following code:
void GetAllCameras(AtomArray *oCams,BaseObject *oCam)
{
if(oCam)
{
MessageDialog("GetType Begin");
if( oCam->GetType() == Ocamera)
{
MessageDialog("Is Ocamera");
oCams->Append(oCam);
}
MessageDialog("GetDown Begin");
if(oCam->GetDown())
{
GetAllCameras(oCams,oCam->GetDown());
}
MessageDialog("GetDown End");
if(oCam->GetNext())
{
GetAllCameras(oCams,oCam->GetNext());
}
MessageDialog("GetNext End");
}
}
LONG GetAllCameras(AtomArray * oCams )
{
if(!oCams)
{
//MessageDialog("Alloc AtomArray Fail that Can't get Camera ");
return 0;
}
BaseDocument *doc=GetActiveDocument();
BaseObject *obj = doc->GetFirstObject();
if(obj)
{
MessageDialog("To get Camera ");
GetAllCameras(oCams,obj);
}
return oCams->GetCount();
}
void SnapCamera( AtomArray *oCams, LONG lCamCnt)
{
LONG nCount = 0;
if ( lCamCnt == 0)
{
return;
}
BaseDocument* doc = GetActiveDocument();
MessageDialog( LongToString(lCamCnt) );
for(LONG i = 0;i < lCamCnt; i++)
{
BaseObject *obj=(BaseObject * )oCams->GetIndex(i);
MessageDialog(obj->GetName());
if ( !obj) break;
String camname = obj->GetName();
LONG iLen = camname.GetCStringLen(St8bit)+1;
char* pName = bNew CHAR[iLen];
camname.GetCString( pName,iLen);
BaseObject * oldcam = doc->GetRenderBaseDraw()->GetSceneCamera( doc );
doc->GetRenderBaseDraw()->SetSceneCamera( obj );
Snapshoot( pName ); //perspective is snapshoot name
bDelete(pName);
}
void GetCameraSnapshoot( void )
{
//SetDisplayMode( TRUE );
AtomArray* oCameras = AtomArray::Alloc();
if ( !oCameras )
{
MessageDialog( "AtomArray Alloc Is Fail" );
return ;
}
//MessageDialog( "AtomArray Alloc Is Succuss" );
LONG lCamCnt = GetAllCameras(oCameras);
MessageDialog( "SnapCamera" );
SnapCamera( oCameras, lCamCnt );
AtomArray::Free(oCameras) ;
return ;
}
but obj->gettype() raise error:
Unhandled exception at 0x0081a299 in CINEMA 4D.exe: 0xC0000005: Access violation reading location 0x00000004.
Then it crash the C4D application.
Can anyone give hints on how to solve it?
Thanks in advance.
Kaviel