On 26.04.2010, at 09:07, Jean-Pierre Lefebvre wrote:

> Maybe I am wrong, but it seems that the size of the box where the picture 
> will be loaded determines the size of the allocated memory.
> By increasing the size of the box, we managed to solve this bug.

This is an interesting observation, although your conclusions are 
probably not completely correct. From your posted code:

   Heat_Source = new Fl_PNG_Image( picture_path.c_str() );

This ^ allocates the image in its full size.

   Heat_Source_Box = new Fl_Box( 0, 0, width, height );
   ...
   Heat_Source_Box->image(Heat_Source->copy( width, height) );

This ^ copies the image and probably _reduces_ its size by scaling it 
down to the given width and height. In fact, this "determines the size 
of the allocated memory" of the copied image, leaving the original image 
alone.

If my conclusion is right, this would indicate that Fl_Image::copy() 
would crash if the image is shrunk too much. This should be investigated 
further.

Can you give us more informations about your image, please?

  (1) width and height of the original 100kB image
  (2) width and height of the image box (its previous size)
  (3) if possible, an example image.

Here is a minimal example to test, something like:

#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_PNG_Image.H>
#include <FL/Fl_Shared_Image.H>


#define WIDTH 50
#define HEIGHT 50
int main() {
   Fl_Window *win = new Fl_Window( WIDTH, HEIGHT);
   fl_register_images();
   Fl_PNG_Image *Heat_Source = new Fl_PNG_Image( "test.png" );
   Fl_Box *Heat_Source_Box = new Fl_Box( 0, 0, WIDTH, HEIGHT );
   Heat_Source_Box->box(FL_FLAT_BOX);
   Heat_Source_Box->image(Heat_Source->copy( WIDTH, HEIGHT) );

   win->show();

   return Fl::run();
}

compile with

  fltk-config --use-images --compile image.cxx

I tested this with FLTK 1.3 with images up to 2000x2000 and
3000x275, and it didn't crash.

Your data would be very much appreciated!

Which FLTK version do you use?

Albrecht

PS: your code snippet, as it stands, is likely to produce memory leaks 
for the primary image and maybe the copied image, unless you free the 
memory somewhere else.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to