[osg-users] playing AVI on Windows

Ulrich Hertlein u.hertlein at sandbox.de
Thu Sep 4 17:33:43 PDT 2008


Hi Janusz,

Janusz wrote:
> To play AVI from within OSG, I wrote a simple app. that plays (or should
> play) AVI files in OSG. The app. proceeds frame by frame displaying the
> AVI contents on a quad inside OSG.
> My problem is that only the first frame is generated and shown on the
> quad. As soon as the app. steps to another one, it breaks.
>...
> /* Code where it breaks: Image.cpp
> void Image::deallocateData()
> {
>     if (_data) {
>         if (_allocationMode==USE_NEW_DELETE) delete [] _data;
>         else if (_allocationMode==USE_MALLOC_FREE) ::free(_data);
>         _data = 0;
>     }
> }
>... 
>     hBitmap = CreateDIBSection (hdc, (BITMAPINFO*)(&bmih),
> DIB_RGB_COLORS, (void**)(&data), NULL, NULL);
>...
>         image->setImage(imWidth,imHeight,1,
>             GL_TEXTURE_2D,GL_RGB,
>             GL_UNSIGNED_BYTE, data,
>             osg::Image::USE_NEW_DELETE);
>...
>         image->allocateImage(256, 256, 1,
>             GL_RGB, GL_UNSIGNED_BYTE);

Your 'data' object is allocated by 'CreateDIBSection'.  You then pass it to osg::Image and
tell it to USE_NEW_DELETE to free the pointer if necessary.

When you call osg::Image::allocateImage the first thing it does is to try to get rid of
the previous image, in your case it does a 'delete[] data'.  This is probably the wrong
thing for two reasons: first 'data' mosty likely wasn't allocated using 'new[]' and second
you don't actually want to delete that data.

You don't actually need to tell the image anything other than that the contents of 'data'
has changed (I assume this is the case in 'GrabAVIFrame').

Try to use osg::Image::NO_DELETE instead of osg::Image::USE_NEW_DELETE and simply call
osg::Image::dirty() after your call to 'GrabAVIFrame' (no allocateImage/setImage).  The
dirty() call marks the Image data as modified and causes the Texture to re-upload it.

Hope this helps.
Cheers,
/ulrich



More information about the osg-users mailing list