[erlang-bugs] wxErlang: using wxSizer with wxStaticBox causes shell crash on frame close
Steve Davis
steven.charles.davis@REDACTED
Sun Mar 15 00:39:35 CET 2009
This seems to be the correct way to deal with wxStaticBox, that is
pretty unintuitive, but stable and works correctly.
I post this for comparison with the code that causes the crash issue,
since having the comparison may help nail things down a bit further.
%%
box(Parent, Opts) ->
GxName = get_atom(id, Opts),
Label = get_string(label, Opts),
%% NOTE: wxStaticBox must be added as a first sibling, and not used as
%% the parent or wxWidgets will *crash* on exit. Thus we enclose the
%% box in a panel and add in the StaticBox as the first child.
Panel = wxPanel:new(Parent),
Sizer = wxBoxSizer:new(?wxVERTICAL),
Box = wxStaticBox:new(Panel, -1, Label),
BoxSizer = wxStaticBoxSizer:new(Box, ?wxVERTICAL),
wxSizer:add(BoxSizer, Sizer),
wxPanel:setSizer(Panel, BoxSizer),
ParentSizer = wxWindow:getSizer(Parent),
SizerFlags = get_sizer_flags(Opts),
wxSizer:add(ParentSizer, Panel, SizerFlags),
wxSizer:fit(Sizer, Parent),
gx:register(GxName, Panel).
Steve Davis wrote:
> More info: This is not wxErlang per se but the wxWidgets code.
>
> While the erlang code below is "legal", the wxWidgets documentation for
> wxStaticBoxSizer explicitly states that it should be added as a sibling
> to the controls that should be visually enclosed, and not used as a
> parent; and that using it as a parent will cause a crash.
>
> However, perhaps wxErlang can catch that problem before it results in a
> complete system thread crash that takes erl/werl with it?
>
> Regs,
> Steve
>
> Steve Davis wrote:
>> Dan and co.
>>
>> This is reproable on Windows XP SP3, I don't have another platform to
>> hand...
>>
>> The following function contains a line that causes a SHELL crash on
>> frame close.
>>
>> Note! the exactly equivalent code using wxPanel does not cause the crash.
>>
>> %% Function causes shell to crash on top level window close... why?
>> box(Parent, Opts) ->
>> GxName = get_atom(id, Opts),
>> Label = get_string(label, Opts),
>> Box = wxStaticBox:new(Parent, -1, Label),
>>
>> %% Do sizer stuff...
>> Sizer = wxStaticBoxSizer:new(Box, ?wxVERTICAL),
>> wxWindow:setSizer(Box, Sizer),
>> SizerFlags = wxSizerFlags:new(),
>> wxSizerFlags:expand(SizerFlags),
>> ParentSizer = wxWindow:getSizer(Parent),
>>
>> % layout doesn't doesn't work without the following line...
>>
>> wxSizer:add(ParentSizer, Sizer, SizerFlags),
>>
>> % ...but this sizer addition crashes the SHELL on top level window close
>>
>> wxSizer:fit(Sizer, Parent), gx:register(GxName, Box).
>>
>>
>> BR,
>> Steve
>>
>
>
More information about the erlang-bugs
mailing list