Opened 4 years ago

Closed 4 years ago

#11698 closed defect (fixed)

crash in wxListbook if imagelist is assigned after adding pages

Reported by: jens Owned by: vadz
Priority: high Milestone: 2.9.1
Component: wxGTK Version:
Keywords: Cc:
Blocked By: Blocking:
Patch: yes

Description

We use xrc-files to create settings dialogs in Code::Blocks.
We work on making the sources compatible with wx2.9.
After loading the dialog from the resource file, we create an imagelist and assign it to the dialog with AssignImageList.

Due to changes in wx2.9 this makes the whole application crash.

After some debugging I found the cause.

The listcontrol used by the listbook is always created with the flag wxLC_REPORT set, if CAN_USE_REPORT_VIEW is defined (all platforms except MAC).

If we now add pages before adding a imagelist the member-variable m_gi will not be initialised in the constructor of wxListLineData (explicitely set to NULL).

If we set an imagelist afterwards, the styles are changed and wxLC_REPORT is no longer set.

This leads to a crash at the beginning of wxListMainWindow::GetLineRect :

    if ( !InReportView() )
        return GetLine(line)->m_gi->m_rectAll;

The function InReportView() returns false because wxLC_REPORT is no longer set, but m_gi is NULL.

I attach a simple patch that always creates the GeometryInfo in wxListLineData.

This might not be the best solution, but it works.

The patch is against trunk, so the linenumbers might differ from wx2.9.

Attachments (3)

listctrl.patch download (552 bytes) - added by jens 4 years ago.
added comment to th epatch
wxListBook-20100209-1.patch download (2.4 KB) - added by jens 4 years ago.
Patch to allocate the needed GeometryInfo when switching from report to non report view
sample_notebook.patch download (750 bytes) - added by jens 4 years ago.
Patch for the notebooks sample, that demonstrates the crash.

Download all attachments as: .zip

Change History (11)

Changed 4 years ago by jens

added comment to th epatch

comment:1 Changed 4 years ago by vadz

  • Priority changed from critical to high
  • Status changed from new to confirmed

Thanks for finding this bug!

I think the ideal fix would be to allocate wxListLineData::m_gi when the list control style is changed, i.e. check if wxLC_REPORT was unset in wxGenericListCtrl::SetWindowStyleFlag() and create m_gi for all elements of m_lines if this was the case. This would require a small modifiction of wxListLineData but seems easy to do, if you could please test if doing this fixes the problem and submit the patch implementing this, it would be great. If not, it would be great if you could submit a (probably trivial) patch to the notebook sample allowing to reproduce the problem now so that we'd at least have a simple way to test any fix ourselves later.

TIA!

Changed 4 years ago by jens

Patch to allocate the needed GeometryInfo when switching from report to non report view

Changed 4 years ago by jens

Patch for the notebooks sample, that demonstrates the crash.

comment:2 Changed 4 years ago by jens

I attach both, a patch for the [tt]notebook.cpptt that leads to the crash and a patch that creates the GeometryInfo, if we switch from report view to non report view.
The patch does not delete m_gi and set it to NULL, if we change the styles the other direction.

Regards

Jens Lody

comment:3 follow-up: Changed 4 years ago by frm

Hi Jens,

sorry but I applied the patch sample_notebook.patch (but not the wxListBook-20100209-1.patch one!) and tried to reproduce the bug but I couldn't make the notebook sample crash.

What are the exact steps I should do to crash it?

Thanks!

comment:4 in reply to: ↑ 3 ; follow-up: Changed 4 years ago by jens

Replying to frm:

Hi Jens, sorry but I applied the patch sample_notebook.patch (but not the wxListBook-20100209-1.patch one!) and tried to reproduce the bug but I couldn't make the notebook sample crash. What are the exact steps I should do to crash it? Thanks!

Sorry for the late reply, I've been very busy at work the last weeks.

To make the (patched) sample crash, I just need to build it with unpatched wxWidgets-trunk and switch the type to listbook ("File -> Type -> Listbook" or "Strg+2").

Jens

comment:5 in reply to: ↑ 4 ; follow-up: Changed 4 years ago by frm

Replying to jens:

To make the (patched) sample crash, I just need to build it with unpatched wxWidgets-trunk and switch the type to listbook ("File -> Type -> Listbook" or "Strg+2").

under which platform? which exact revision of wxWidgets trunk?

I've tested again r63806 under wxMSW (under Win7 64bit) and I couldn't reproduce the crash with the (patched) sample crash. I also see that your patch to the notebook sample contains Unix paths: are you using wxGTK perhaps? do you see the crash only on wxGTK or also on wxMSW? In the first case please update the "Component" category of this ticket to "wxGTK"... thanks!

comment:6 in reply to: ↑ 5 Changed 4 years ago by jens

  • Component changed from GUI-all to wxGTK

Replying to frm:

Replying to jens:

To make the (patched) sample crash, I just need to build it with unpatched wxWidgets-trunk and switch the type to listbook ("File -> Type -> Listbook" or "Strg+2").

under which platform? which exact revision of wxWidgets trunk?

I've tested again r63806 under wxMSW (under Win7 64bit) and I couldn't reproduce the crash with the (patched) sample crash. I also see that your patch to the notebook sample contains Unix paths: are you using wxGTK perhaps? do you see the crash only on wxGTK or also on wxMSW? In the first case please update the "Component" category of this ticket to "wxGTK"... thanks!

Yes, you are right, it does not crash under wxMSW.
My fault, we had a crash on windows in the same ctor for other reasons also related to wx29 (incorrect using of dimensions in wxFlexGridSizer in an xrc-file,that has worked in wx28 and before without problems and have been overseen therfore).
I did the mos test tests and the debugging on linux and so the error slipped in.

I think it will happen in all flavours of wxWidgets that use the generic listbook (don't know if this is only wxGTK or not, no way to test here), so I change component to wxGTK.

Again sorry for the error.

comment:7 Changed 4 years ago by vadz

  • Owner set to vadz
  • Status changed from confirmed to accepted

Yes, I can reproduce it, will fix, thanks.

comment:8 Changed 4 years ago by VZ

  • Resolution set to fixed
  • Status changed from accepted to closed

(In [63946]) Fix crash in wxListbook if image list is assigned after adding pages.

The generic wxListCtrl didn't properly support switching between report and
non-report modes without invalidating the control contents, the required in
non report view geometry info pointers were not allocated when the control was
switched to a, say, list mode and not created in it.

Fix this by updating all list control lines when the report mode changes.

Closes #11698.

Note: See TracTickets for help on using tickets.