Menu

Bug in prefuse.render.ImageFactory? (patch)

Help
Nazri
2007-02-28
2013-05-29
  • Nazri

    Nazri - 2007-02-28

    The following code highlights the bug (make sure someimage.jpeg exist in current directory):

    import prefuse.render.ImageFactory;
    import java.awt.Image;
    class TestImageFactory {
        public static void main(String args[]) {
          ImageFactory images = new ImageFactory();
          Image image = images.getImage("someimage.jpeg");
          assert image != null; // This test fails (with assertion enabled, of course).
        }
    }

    The following patch should fix it.

    *** prefuse/render/ImageFactory.java.orig       2007-03-01 01:03:00.000000000 +0800
    --- prefuse/render/ImageFactory.java    2007-03-01 01:02:59.000000000 +0800
    ***************
    *** 120,126 ****
                  image = Toolkit.getDefaultToolkit().createImage(imageURL);
                 
                  // if set for synchronous mode, block for image to load.
    !             if ( !m_asynch ) {
                      waitForImage(image);
                      addImage(imageLocation, image);
                  } else {
    --- 120,126 ----
                  image = Toolkit.getDefaultToolkit().createImage(imageURL);
                 
                  // if set for synchronous mode, block for image to load.
    !             if ( m_asynch ) {
                      waitForImage(image);
                      addImage(imageLocation, image);
                  } else {

     
    • Jeffrey Heer

      Jeffrey Heer - 2007-10-21

      The ImageFactory loads images asynchronously (loads them in the background), so it will return null until the image has been loaded. This is the intended behavior. However, I will add new methods for toggling the synchronous/asynchronous state so that one can cause the image factory to block rather than load in the background. Just call setAsynchronous(false) first, then try the example above.

       

Log in to post a comment.