> 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.




Hello,

I will provide you with more details about my observation, and with this 
picture in a couple of days, as soon as my deadline will be over.

However, maybe it is a "newbie" question (and I apologize for that), but in 
your previous post, you told me that my code "is likely to produce memory leaks 
for the primary image and maybe the copied image". Could you please tell me 
what is wrong in this code, or what should I do to avoid this problem ?

I give you below the declaration in the *.h, and the code in the *.cpp files.
* == *.h file  ===============================================

class LocalfswToolWindow {
  public:
    LocalfswToolWindow( int deltaFontSize );
    ~LocalfswToolWindow();

    void                  show();
    void                  hide();

    Fl_Window             *win;
    int                   width;
    int                   height;
    bool                  morfeo_install_dir;
    Fl_PNG_Image          *Tool_FSW;
    Fl_Box                *Tool_FSW_Box;
};

* ============================================================
* == *.cpp file  =============================================

LocalfswToolWindow::LocalfswToolWindow( int deltaFontSize )
{
  // --- Size of the window
  width = 14 * (BB + WB);
  height = 10 * (BB + WB);

  win = new paletteWindow( width, height,
                           CTX::instance()->nonModalWindows ?
                           false : true, "Local FSW Tool");
  win->box(GMSH_WINDOW_BOX);

  if( getenv( "MORFEO_INSTALL_DIR" ) != NULL ){
    morfeo_install_dir = true;

    // --- Path to the picture
    string picture_path = getenv( "MORFEO_INSTALL_DIR" );
    picture_path += "/Figures/Tool_Description.png";

    fl_register_images();
    Tool_FSW = new Fl_PNG_Image( picture_path.c_str() );
    Tool_FSW_Box = new Fl_Box(0,0, width, height);
    Tool_FSW_Box->box(FL_FLAT_BOX);
    Tool_FSW_Box->image(Tool_FSW->copy(width, height));
    win->position( CTX::instance()->solverPosition[-1],
                   CTX::instance()->solverPosition[0] );
  }
  else{
    morfeo_install_dir = false;
    Msg::Warning("The environment variable 'MORFEO_INSTALL_DIR' is not 
defined.");
    Msg::Warning("The windows describing the heat source types and the tool 
geometry are not displayed.");
    Msg::Warning("Please, refer to the Documentation in order to define this 
environment variable.");
    FlGui::instance()->messages->show();
    Tool_FSW = NULL;
    Tool_FSW_Box = NULL;
  }

  win->end();
}
* ============================================================

Thanks a lot in advance for your help,

Jean-Pierre
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to