Dear All,

I am finding the ++dfb library to be an effective way of accessing 
directfb from C++, leading to nice simple code.  But I have encountered 
some odd crashes.  A fairly minimal example is shown below.

The key point is that I pass *by value* an IDirectFB from the main 
program to the load_pic function.  Similar things happen when I pass 
other types by value.  But if I change to passing by reference it 
works.  I fear that the "main" DirectFB is being destroyed when the 
copy in the function is destructed.

Of course, passing a const reference is a little more efficient than 
passing by value.  But I think that passing by value should work: it 
looks as if the right sort of thing is going on in the reference 
counting code, keeping only one underlying object.  Maybe there is some 
subtle bug in there.  Or, maybe I have got the wrong idea.

So, can someone else try this example and see if it also fails for 
them?  Do you agree that this ought to work?  Can anyone suggest a 
debugging strategy?

I am using the 0.9.25.1-3 Debian packages for libdirectfb, ++dfb 0.9.25 
that I compiled myself (it's not in the Debian packages), and g++ 
4.1.2.  In general, directfb and ++dfb do work.

Here is the example:

#include <iostream>

#include <++dfb.h>

using namespace std;


IDirectFBSurface load_pic(IDirectFB the_dfb, const char* fn)
{
   IDirectFBImageProvider provider = the_dfb.CreateImageProvider(fn);
   DFBSurfaceDescription desc;
   provider.GetSurfaceDescription(&desc);
   IDirectFBSurface picture = the_dfb.CreateSurface(desc);
   provider.RenderTo(picture, NULL);
   return picture;
}


int main (int argc, char* argv[])
{
   DirectFB::Init(&argc, &argv);

   IDirectFB dfb = DirectFB::Create();
   dfb.SetCooperativeLevel(DFSCL_FULLSCREEN);

   DFBSurfaceDescription desc;
   desc.flags = DSDESC_CAPS;
   desc.caps  = DSCAPS_PRIMARY;
   DFB_ADD_SURFACE_CAPS(desc.caps,DSCAPS_FLIPPING);
   IDirectFBSurface primary = dfb.CreateSurface(desc);

   IDirectFBSurface picture = load_pic(dfb, argv[1]);

   primary.SetBlittingFlags(DSBLIT_BLEND_COLORALPHA);
   primary.SetSrcBlendFunction(DSBF_SRCALPHA);
   primary.SetDstBlendFunction(DSBF_ZERO);
   primary.SetColor(255,255,255,255);
   primary.Blit(&picture,NULL,0,0);
   primary.Flip(NULL, DSFLIP_WAITFORSYNC);

   sleep(10);
   return 0;
}


Compile:
$ g++ -W -O -I/usr/include/directfb -I/usr/local/include/++dfb -o 
dfbcheck dfbcheck.cc -l++dfb


When I run it, this is the output that I get:

# ./dfbcheck test.jpeg

        ---------------------- DirectFB v0.9.25 ---------------------
              (c) 2000-2002  convergence integrated media GmbH
              (c) 2002-2004  convergence GmbH
         -----------------------------------------------------------

(*) DirectFB/Core: Single Application Core. (2006-07-31 16:59)
(*) Direct/Memcpy: Using MMXEXT optimized memcpy()
(*) Direct/Thread: Running 'VT Switcher' (CRITICAL, 17475)...
(*) Direct/Thread: Running 'PS/2 Input' (INPUT, 17476)...
  (!!!)  *** UNIMPLEMENTED [fusion_reactor_set_lock] *** 
[../../../lib/fusion/reactor.c:853]
(*) DirectFB/Input: IMPS/2 Mouse 1.0 (Convergence GmbH)
(*) Direct/Thread: Running 'Keyboard Input' (INPUT, 17477)...
(*) DirectFB/Input: Keyboard 0.9 (convergence integrated media GmbH)
(*) Direct/Thread: Running 'Linux Input' (INPUT, 17478)...
(*) DirectFB/Input: Gyration Gyration RF Technology (1) 0.1 
(convergence integrated media GmbH)
(*) Direct/Thread: Running 'Linux Input' (INPUT, 17479)...
(*) DirectFB/Input: Gyration Gyration RF Technology (2) 0.1 
(convergence integrated media GmbH)
(*) DirectFB/Genefx: MMX detected and enabled
(*) DirectFB/Graphics: VIA/S3G CN400/UniChrome Pro 0.4 (-)
(*) DirectFB/Core/WM: Default 0.2 (Convergence GmbH)
(*) Direct/Interface: Loaded 'JPEG' implementation of 'IDirectFBImageProvider'.
  (!!!)  *** WARNING [still objects in 'Layer Region Pool'] *** 
[../../../lib/fusion/object.c:226 in fusion_object_pool_destroy()]
  (!!!)  *** WARNING [still objects in 'Surface Pool'] *** 
[../../../lib/fusion/object.c:226 in fusion_object_pool_destroy()]
IDirectFBSurface::SetColor(__u8, __u8, __u8, __u8) -> Resource was destroyed!
terminate called after throwing an instance of 'DFBException*'
Aborted



Thanks for any advice.

Phil.





_______________________________________________
directfb-users mailing list
[email protected]
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-users

Reply via email to