FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Bitmap class bug, or maybe GC bug???

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
jvr



Joined: 19 Nov 2007
Posts: 10

PostPosted: Mon Nov 19, 2007 9:05 pm    Post subject: Bitmap class bug, or maybe GC bug??? Reply with quote

Hi,

First of all, thanks Chris for the DFL library! Very Happy

I'm making a program that loads and displays 1024 small bitmaps (32x32), and everything runs OK, but when I display them on a picturebox the bitmap object number 113 doesn't show, instead appears a 32x32 window-color box with the down arrow button of the windows scroll bars. Shocked

This is the code I use to reserve and load the bitmaps:
Code:
m_bmps = new Bitmap[1024];
// Is maybe a problem with the garbage collector?; because the
// problem doesn't appear if I run this code before loading the bmps:
// for(uint i=0; i < 500; i++)
// {
//   new Bitmap("0.bmp");
// }
for(uint i=0; i < 1024; i++)
{
  m_bmps[i] = new Bitmap(format("%d.bmp", i));
}


(And if I run gc.fullCollect() before loading the bitmaps the problem changes to the bitmap number 120). Shocked


And this is the code I use to display the first 400 bitmaps (the problem is only with the bitmap number 113):
Code:
for(uint y=0; y < 20; y++)
{
  for(uint x=0; x < 20; x++)
  {
    m_bmps[y*20+x].draw(m_gfx, Point(x*32, y*32));
  }
}


Of course I've checked the bmp files and no problem with them.
I'm using DMD v1.023 and DFL 0.9.6.01.

Any idea?

Cheers,
Javi
Code:
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Fri Nov 23, 2007 8:12 am    Post subject: Re: Bitmap class bug, or maybe GC bug??? Reply with quote

This sounds strange but I don't know what it is. If you could give me some code and images so I can test and reproduce it, I might be able to get down to the issue. Without that, it'd be pretty hard for me.
Back to top
View user's profile Send private message
jvr



Joined: 19 Nov 2007
Posts: 10

PostPosted: Fri Nov 23, 2007 9:04 am    Post subject: Re: Bitmap class bug, or maybe GC bug??? Reply with quote

Yes of course, simply compile this code and put in the same folder any 32x32 bmp file (24 bits) as "test.bmp". Run the program, press OK button and you should see the "bad" sprite...

Code:

import dfl.all;

class MainForm: dfl.form.Form
{
private:
   // Do not modify or move this block of variables.
   //~Entice Designer variables begin here.
   dfl.picturebox.PictureBox m_pbox_board;
   dfl.button.Button m_but_ok;
   //~Entice Designer variables end here.
 
  Graphics m_gfx;
  Bitmap[] m_bmps;
   
   void initializeMainForm()
   {
      // Do not manually modify this function.
      //~Entice Designer 0.8.4 code begins here.
      //~DFL Form
      formBorderStyle = dfl.all.FormBorderStyle.FIXED_SINGLE;
      maximizeBox = false;
      startPosition = dfl.all.FormStartPosition.CENTER_SCREEN;
      text = "Test";
      clientSize = dfl.all.Size(528, 595);
      //~DFL dfl.picturebox.PictureBox=m_pbox_board
      m_pbox_board = new dfl.picturebox.PictureBox();
      m_pbox_board.name = "m_pbox_board";
      m_pbox_board.bounds = dfl.all.Rect(8, 8, 512, 512);
      m_pbox_board.parent = this;
      //~DFL dfl.button.Button=m_but_ok
      m_but_ok = new dfl.button.Button();
      m_but_ok.name = "m_but_ok";
      m_but_ok.text = "OK";
      m_but_ok.bounds = dfl.all.Rect(408, 536, 104, 40);
      m_but_ok.parent = this;
      //~Entice Designer 0.8.4 code ends here.
   }
   
  void ButOKClick(Object sender, EventArgs ea) 
  {
    for(uint y=0; y < 16; y++)
    {
      for(uint x=0; x < 16; x++)
      {
        m_bmps[y*16+x].draw(m_gfx, Point(x*32, y*32));
      }
    }
  }

public:

   this()
   {
    initializeMainForm();
   
    m_gfx = m_pbox_board.createGraphics();

    m_bmps = new Bitmap[1024];
    for(uint i=0; i < 1024; i++)
    {
      m_bmps[i] = new Bitmap("test.bmp");
    }

    m_but_ok.click ~= &ButOKClick;
   }
}


int main()
{
   int result = 0;
   
   try
   {
      Application.enableVisualStyles();
      Application.run(new MainForm());
   }
   catch(Object o)
   {
      msgBox(o.toString(), "Fatal Error", MsgBoxButtons.OK, MsgBoxIcon.ERROR);
      
      result = 1;
   }
   
   return result;
}
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Fri Nov 23, 2007 11:15 am    Post subject: Re: Bitmap class bug, or maybe GC bug??? Reply with quote

This does appear to be a problem with the garbage collector.

For testing, I switched to this in your draw loop:
Code:
        //auto bmp = "test.bmp\0"w.ptr;
        auto bmp = "test.bmp\0"w.dup.ptr;
        (new Bitmap(LoadImageW(null, bmp, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE))).draw(m_gfx, Point(x*32, y*32));
it just requires you to import dfl.internal.winapi as well. This causes the problem to happen, whereas the first bmp (switch the commented lines) doesn't have the problem as it doesn't use the GC.

The other way I got it to work was to fullCollect in each iteration where you construct the bitmaps, but it kills the load performance.

You might need to report this to the D bugzilla.
Back to top
View user's profile Send private message
jvr



Joined: 19 Nov 2007
Posts: 10

PostPosted: Fri Nov 23, 2007 12:12 pm    Post subject: Re: Bitmap class bug, or maybe GC bug??? Reply with quote

Ok, thank you Chris.
Could you report the problem to the D bugzilla?, I think you'd explain it better than me...

Cheers
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group