[BUG][FOX] iconlist and multiple icon usage

Hi, –

i’ve encountered a bug in the FOX library from the PragProg installer.
When using a FXIconList, it does not seem to be possible to use the
same FXIcon for more than 1 item in the list. Trying to do so result in
a segfault on win2k (and win98se) at least.

Attached you will find a simple test case (you just need to set
FOLDER_OPEN to a valid png file on your system).

I’ve tried to .clone the FXIcon but it says the icon was already
detached or some kind of obscure error message related to, i guess,
reference counting.

FOX does seem to be quite sensitive on the icon topic and i’ve had hard
time to figure where segfaults where coming from… I even started to
believe that simple ruby code could make sefgault the interpreter :))

Apart from reinstancing an icon everytime, is there a solution to have
icons used more than once on with FOX ?

Thanks a lot,

eicon_bug.rb (918 Bytes)

···


Pierre Baillet
Tout avantage a ses inconvénients et réciproquement.
Devise Shadok

Pierre Baillet wrote:

i’ve encountered a bug in the FOX library from the PragProg installer.
When using a FXIconList, it does not seem to be possible to use the
same FXIcon for more than 1 item in the list. Trying to do so result in
a segfault on win2k (and win98se) at least.

Attached you will find a simple test case (you just need to set
FOLDER_OPEN to a valid png file on your system).

The problem is that you’re trying to use an icon before its server-side
representation has been created. For more information about this issue,
see this entry from the FOX FAQ:

 http://www.fox-toolkit.org/faq.html#ILLEGALICON

The quick fix for your program is to just add the line:

 icon.create

immediately after the line in Foo#redraw_list that instantiates the new
FXPNGIcon, i.e.

 def redraw_list
   @iconlist.clearItems
   # display empty boxes
   icon = FXPNGIcon.new(getApp(), @@folder_data)
   icon.create
   (1..3).each{ |f|
     item = FXIconItem.new(f.to_s, icon )
     @iconlist.appendItem(item)
   }
 end

Apart from reinstancing an icon every time, is there a solution to have
icons used more than once on with FOX?

As a matter of fact you only need one copy of this icon object, and
can share it amongst all of the list items. If I were to modify your
example program, it would look like this:

 class Foo < FXMainWindow

   FOLDER_OPEN = "icon/stock_open.png"

   def redraw_list
     @iconlist.clearItems
     (1..3).each{ |f|
       item = FXIconItem.new(f.to_s, @folder_icon)
       @iconlist.appendItem(item)
     }
   end

   def initialize(anApp)
     super(anApp, "COM Marker Viewer " + VERSION, nil, nil,
       DECOR_ALL, 0, 0, 640, 480, 0, 0)

     # Read the image file data and construct the
     # shared icon object
     folder_data = File.open(FOLDER_OPEN, "rb").read()
     @folder_icon = FXPNGIcon.new(getApp(), folder_data)

     frame = FXVerticalFrame.new(self,
               LAYOUT_FILL_X|LAYOUT_FILL_Y)
     @iconlist = FXIconList.new(frame, nil, 0,
                   ICONLIST_BIG_ICONS|ICONLIST_ROWS|ICONLIST_COLUMNS|
                   LAYOUT_FILL_X|LAYOUT_FILL_Y)
     redraw_list
   end

   def create
     super
     @folder_icon.create
     self.show(PLACEMENT_SCREEN)
   end
 end

 theApp = FXApp.new("foo", "Bar")
 Foo.new(theApp)
 theApp.create
 theApp.run

Apart from moving the app-related stuff out of your main window class,
the important thing to note is that there is only one icon object
(@folder_icon) that is shared by all of the list items. It gets created
when the main window (Foo) object is created (see Foo#create).

Hope this helps,

Lyle

Hello again,

I worked like a charm, thanks a lot for your help, Lyle !

···

On Tue, Jan 07, 2003, Lyle Johnson wrote:

The problem is that you’re trying to use an icon before its server-side
representation has been created. For more information about this issue,
see this entry from the FOX FAQ:

http://www.fox-toolkit.org/faq.html#ILLEGALICON

The quick fix for your program is to just add the line:

icon.create

immediately after the line in Foo#redraw_list that instantiates the new
FXPNGIcon, i.e.

def redraw_list
  @iconlist.clearItems
  # display empty boxes
  icon = FXPNGIcon.new(getApp(), @@folder_data)
  icon.create
  (1..3).each{ |f|
    item = FXIconItem.new(f.to_s, icon )
    @iconlist.appendItem(item)
  }
end

Apart from reinstancing an icon every time, is there a solution to have
icons used more than once on with FOX?

As a matter of fact you only need one copy of this icon object, and
can share it amongst all of the list items. If I were to modify your
example program, it would look like this:

class Foo < FXMainWindow
[ ...>8... snip ...8<... ]

Apart from moving the app-related stuff out of your main window class,
the important thing to note is that there is only one icon object
(@folder_icon) that is shared by all of the list items. It gets created
when the main window (Foo) object is created (see Foo#create).


Pierre Baillet
Il faut pomper pour vivre et donc vivre pour pomper.
Devise Shadok