wxWidgets / Phoenix

wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.
http://wxpython.org/
2.29k stars 516 forks source link

Using the native header for wx.Grid causes InsertCols() and AppendCols() to break #1777

Open AuroranAI opened 4 years ago

AuroranAI commented 4 years ago

Operating system: Windows 10 wxPython version & source: Pypi, ver.4.1.0, earliest version it was an issue: 4.0.6 Python version & source: Stock python 3.7.2

Description of the problem: If a wx.Grid is using a native header and AutoResize() has been called, InsertCols() will throw the following C++ error:

wx._core.wxAssertionError: C++ assertion "idx < m_size" failed at C:\PROJECTS\bb2\dist-win64-py37\build\ext\wxWidgets\include\wx/vector.h(482) in wxVector<int>::at(): 

A workaround for this is to disable the native header before Inserting a new column, then re-enabling the native header.

Similarly, AppendCols() is prone to break with native headers. To cause the issue, call self.grid.SetColPos() once, and subsequently call AppendCols(), which produces the following C++ error:

wx._core.wxAssertionError: C++ assertion "order >= 0 && order <= GetShownColumnsCount()" failed at ..\..\src\msw\headerctrl.cpp(634) in wxMSWHeaderCtrl::MSWToNativeOrder(): logic error

Like the last issue, disabling the native header before calling AppendCols() and SetColPos() causes correct functioning.

While both of these require another function being called before they break, both InsertCols() and AppendCols() break only while the grid uses a native header. The issue seems to be that AutoResize() and SetColPos() have incorrect/different side effects when called with a native header, leading to idx and order being set incorrectly.

Attached is a .py file demonstration. error.zip

DietmarSchwertberger commented 2 years ago

This is certainly a wxWidgets bug. I see it also in the wxWidgets grid demo when I use your settings (auto resize and native header).

DietmarSchwertberger commented 2 years ago

Actually, it would always trigger if the column widths are set individually. I have created a wxWidgets PR to fix this.

DietmarSchwertberger commented 2 years ago

The PR has been merged. At some time, it should find its way into wxPython as well...