View Full Version : Cannot stopLive()

November 11, 2003, 14:51:58

i wanted to render the preview stream into a java component.

Therefore i have implemented a CListener ( as in your callback sample ) and activated its frameReady() method. There i am providing the image Data by copying the MemBuffer pointer to a global pointer.

I'm starting a FrameGrabberSink with eGRAB,
grabber->startLive( false ), because i want to do the rendering myself.

Then i'm rendering the image data into a java component ( Canvas ) overriding its paint() method.

Up to this point everything works well and the preview is rendered into my java component.

The problem is, that every call to grabber->stopLive() after that causes crashes
( Like EXCEPTION_ACCESS_VIOLATIONS detected from Java VM in native code outside ).

It looks like i'm not able to release all the components from the grabber object savely.

What can i do ?

Thanks in advance


Stefan Geissler
November 12, 2003, 07:40:57

I think, you should not draw the image in the paint method, because this method is called every time, the frame is invalidated.
The membuffer collection must be declared as a global variable in your case. For example you have a class, that has as member the grabber and the membuffer collection. This class has an export function, that exports the pointer to a membuffer outside this class. This pointer is used, as in your case, outside the class for drawing purposes. Now you stop live and destroy the class, because the grabber is not longer used. With this, the membuffer contents will be destroyed too, but your outside pointer of the membuffer, points to the destroyed membuffer memory. This results in an access violation. Thus the class, that contains the membuffer and the grabber must exist, until no more references to the membuffer exist from outside.

November 17, 2003, 07:42:57
Hello Stefan,

you were right, the Problems are caused from the global Pointer to the actual Frame Data. This is now fixed and it works!

I know, that drawing the image data inside the paint method is a little bit tricky, but it is the recommended way from Sun to render image data from C++ into a Java Component within the JNI Interface.

Thanks a lot for your help.

Best regards