#15225 closed defect (fixed)

wxGrid - calling AppendCols after SetColSize causes assert exception

Reported by: iwbnwif Owned by: vadz
Priority: normal Milestone:
Component: wxGrid Version: 2.9.4
Keywords: SetColSize, AppendCols Cc:
Blocked By: Blocking:
Patch: no

Description

On wxMSW when using native drawn headers

If columns are appended to a wxGrid (using the method AppendCols) after some columns have already had their size set with SetColSize there is an assert exception raised.

This is because AppendCols causes GetColWidth to be called for all columns (including the newly appended one), however the m_colWidths array is only dimensioned to the existing columns (excluding the appended one).

A simple fix is to replace the m_colWidths.IsEmpty test at line 2567 of grid.cpp with m_colWidths.GetCount <= col.

However it might be better to rearrange the order in which the grid is updated so that the m_colWidths array is resized as part of the AppendCols actions. This is for someone who has much greater knowledge of how the wxGrid works than I do to decide!

Attachments (1)

griddemo-iwbnwif.diff download (300 bytes) - added by iwbnwif 15 months ago.
Modification of the standard wxGrid to highlight issue with SetColSize()

Download all attachments as: .zip

Change History (6)

comment:1 follow-up: Changed 15 months ago by vadz

As usual, it would be great to have a small patch to the grid sample reproducing the problem. Could you please make one?

Changed 15 months ago by iwbnwif

Modification of the standard wxGrid to highlight issue with SetColSize()

comment:2 in reply to: ↑ 1 Changed 15 months ago by iwbnwif

I have tried to create a patch file using the GNUWin32 Utils. I hope that it has come out in the correct format

comment:3 Changed 15 months ago by vadz

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

Thanks for your effort, it would have been even better if you could please follow the guidelines and notably make the diff from the top level directory but even in its current state it's already useful as it allows me to see the problem easily, thanks!

I'll check in a fix soon.

comment:4 Changed 15 months ago by iwbnwif

Sorry, I missed that the diff should start at the root but I am glad that you are able to use the file.

comment:5 Changed 15 months ago by VZ

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

(In [74063]) Fix assert when adding columns to wxGrid using native header.

Change the order of updating m_colWidths array and the native header control
in wxGird::Redimension() to ensure that we can test whether the column is
shown (which results in accessing m_colWidths element at this column index)
from the wxGridHeaderCtrl::SetColumnCount().

Closes #15225.

Note: See TracTickets for help on using tickets.