Page 1 of 1

get_IsEmpty crashes

Posted: Wed Nov 05, 2008 7:28 am
by psykoboy
Hi,

I'm using this simple (too simple ?) C++ code, but something goes wrong.

The error seems to come from get_IsEmpty call.
I'm using VS2008 and it seems that the frame returned by GetFrame is null (actually the p field from the COM object is null).
What did I do wrong ?

I went to watch the minimal C++ code, but doesn't help.
I thought this might come from not using FrameAvailableEvent, but events arenn't used in the Grayscale Example and it works fine...

Thx for help

Code: Select all

	CComPtr<INPCameraCollection> collection;
	CComPtr<INPCamera>           camera;
	CComPtr<INPCameraFrame>      frame;


	CoInitialize(NULL);

	collection.CoCreateInstance(CLSID_NPCameraCollection) ;
   
	collection->Enum() ;

	collection->Item(0, &camera) ;
   
	camera->Open()  ;
	camera->Start() ;
  
	camera->GetFrame(0, &frame);
	
        VARIANT_BOOL t;
        // Error here
	frame->get_IsEmpty( &t );	
  
	camera->Stop();
	camera->Close();
	camera.Release();
	collection.Release();
	CoUninitialize();

Re: get_IsEmpty crashes

Posted: Wed Nov 05, 2008 11:30 am
by beckdo
You always want to check if thee frame is NULL before using it. When you call ->Start() on a camera it takes some amount of time before the first frame is available, so as written, your code will always crash.

Always check the camera object to make sure it's not null as well.

Re: get_IsEmpty crashes

Posted: Tue Nov 11, 2008 3:32 pm
by psykoboy
Hi,

Ok I did like you said and it seems to work fine.
The only problem is now when there is no object in the field of view of my camera, the GetFrame operation crashes with an access violation... (I'm not using any grayscale, or anything else...only the detected IR balls as white area )
However everything works fine when there is something to display (a body for example).

How can I avoid that ?
I'm not using events because I don't know how to implement them. I tried with the sink, the online example, but nothing works with me (maybe 'cause I'm doing a wrapper to avoid using Com object...).
Do I absolutely need to use Events ?

Thx

Re: get_IsEmpty crashes

Posted: Tue Nov 11, 2008 3:48 pm
by beckdo
You don't need to user events. Implementing events in C++ is a real challenge.

However the app shouldn't crash from a simple GetFrame() call. It should just return NULL.

Also, there are some camera 'sendframe' options. Set the option to send empty frames. Then you'll get frames even if they are empty.