PDA

View Full Version : Error : Buffer not initialized when changing video format



acanicio
August 28, 2010, 09:11:08
Dear Stefan,

Here I am again with another little question.
With a DBK camera, when changing the videoformat from any video format to another video format (i.e. for example when switching from Y800 to BY8, or YGB0 to Y800 or BY8 to UYVY), I often get (but not always) the following error :
<<
The Membuffer is not valid (maybe it is uninitialized or the format of the given MemBuffer does not fit to the current colorformat/videoformat).
>>

http://www.astrosnap.com/divers/photos/ERR_TIS_Buffer_not_initialized.jpg

In my code, whenever I change the videoformat property, I always change the MemoryCurrentGrabberColorFormat property to the corresponding value, in order to always match the new videoformat :


procedure TFRM_CamPropertyDlg.CBX_VideoFormatsChange(Sender: TObject);
begin
If ICImagingControl.DeviceValid then
Begin
If ICImagingControl.LiveVideoRunning then
begin
ICImagingControl.LiveStop;
ICImagingControl.OverlayBitmapPosition := PATHPOSITION_NONE;
ICImagingControl.VideoFormat := ICImagingControl.VideoFormats[CBX_VideoFormats.ItemIndex+1].Name;
ICImagingControl.SinkCompatibilityMode := True;
ICImagingControl.MemoryCurrentGrabberColorFormat := GetGrabberColorFormat(ICImagingControl.VideoFormat );
ICImagingControl.SinkCompatibilityMode := False;
ICImagingControl.DeviceFrameRate := ICImagingControl.DeviceFramerates[CBX_Framerates.ItemIndex+1];
If @VideoFormatChangeCB <> Nil then
Begin
VideoFormatChangeCB(Self.Camera,CBX_VideoFormats.T ext);
End;
Sleep(500);
ICImagingControl.LiveStart;
End
else
Begin
ICImagingControl.OverlayBitmapPosition := PATHPOSITION_NONE;
ICImagingControl.VideoFormat := ICImagingControl.VideoFormats[CBX_VideoFormats.ItemIndex+1].Name;
ICImagingControl.SinkCompatibilityMode := True;
ICImagingControl.MemoryCurrentGrabberColorFormat := GetGrabberColorFormat(ICImagingControl.VideoFormat );
ICImagingControl.SinkCompatibilityMode := False;
If @VideoFormatChangeCB <> Nil then
Begin
VideoFormatChangeCB(Self.Camera,CBX_VideoFormats.T ext);
End;
End;
End;

end;


Function GetGrabberColorFormat(VideoFormat : String) : ICImagingControlColorformats;
Begin
If Pos('BY8',VideoFormat) > 0 then
Begin
Result := ICBY8;
End
else
If Pos('UYVY',VideoFormat) > 0 then
Begin
Result := ICUYVY;
End
else
If Pos('Y800',VideoFormat) > 0 then
Begin
Result := ICY800;
End
else
If Pos('YGB0',VideoFormat) > 0 then
Begin
Result := ICYGB0;
End
Else
If Pos('YGB1',VideoFormat) > 0 then
Begin
Result := ICYGB1;
End;

End;


The error does NOT appear all the time. It does happen once every 7 or 8 changes, and it appears when in the "imageavailable" event is triggered and I do the following :


Var CurrentBuffer : ImageBuffer;
Begin
//SNIP//
CurrentBuffer:= Control.ImageBuffers.Item[BufferIndex];
//SNIP//
End;



Is there something that I forget to do ? Or is there some lag time that I must respect in order to wait for the changes to the video format to be completely applied ?

Thank you again for your help :-)
Best regards
Axel

Stefan Geissler
August 30, 2010, 07:17:21
Hello Axel,

First of all, are you sure, you want to use BY8 and UYVY in the sink as pixel format? This does not make sense in any case, except you know how to handle each format. Also the USB cameras use YUY2 instead of UYVY. In this case, your program will fail. I would like you to remove the ICBY8 and ICUYVY branches and use RGB32 instead. Maybe the error will be away then.