[wxruby-users] Segfault with GridCellChoiceEditor
Alex Fenton
alex at pressure.to
Tue Jul 29 06:37:41 EDT 2008
Hi Glen
Glen Holcomb wrote:
> In my application I have a few Grid objects in a Notebook. The Grid
> objects are populated via GridTableBase. Certain Grid cells need to
> have a choice interface (I'm artificially enforcing foreign key
> constraints). All this works to the point where you try to edit the
> value for that cell. The choice box renders (i.e. the drop down arrow
> appears) then the application segfaults. Unfortunately I'm stuck
> developing this in a Windows (XP) environment so I can't do much with
> the segfault. Any help would be most appreciated.
The problem here is the combination of GridTableBase and cell editors /
renderers, which makes the memory management very tricky. It's noted as
a bug here:
http://rubyforge.org/tracker/index.php?func=detail&aid=19187&group_id=35&atid=218
I don't know how to fix it in the library, but you should be able to
work around it by storing the cell editor in an instance variable
somewhere. Then ruby will mark it and preserve it from GC. From the code
you posted on c.l.r (please do post code on this mailing list as well)
def get_attr(row, col, attr_kind)
attr = Wx::GridCellAttr.new
if @db_table == "computers" and col == 4
## INSTEAD OF THIS
# attr.set_editor(Wx::GridCellChoiceEditor.new(["CAD", "GIS", "CMT"]))
## TRY THIS
@editors ||= []
@editors << Wx::GridCellChoiceEditor.new(["CAD", "GIS", "CMT"])
attr.set_editor(@editors.last)
end
attr
end
hth
alex
More information about the wxruby-users
mailing list