GTK2: wxListCtrl::SortItems throws an assertion when called from event handler Topic is solved

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
jpo234
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Feb 25, 2020 11:34 am

GTK2: wxListCtrl::SortItems throws an assertion when called from event handler

Post by jpo234 »

Hello all,
to keep the items in a wxListCtrl sorted, I'm calling wxListCtrl::SortItems in a handler for wxEVT_COMMAND_LIST_INSERT_ITEM or wxEVT_COMMAND_LIST_DELETE_ITEM. This works fine on Windows, but throws the following assertion in Linux with GTK2:

Code: Select all

../src/generic/listctrl.cpp(4473): assert "IsEmpty() || (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount())" failed in GetVisibleLinesRange(): GetVisibleLinesRange() returns incorrect result
../src/generic/listctrl.cpp(4473): assert "IsEmpty() || (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount())" failed in GetVisibleLinesRange(): GetVisibleLinesRange() returns incorrect result
As a work-around I have disabled the sorting in the event handler and call wxListCtrl::SortItems whenever I change items directly.
Question: Is calling wxListCtrl::SortItems from an event handler forbidden? Or is this a bug in the GTK2 implementation?

The wxwidgets version on Linux is:

Code: Select all

dpkg --status libwxgtk3.0-0v5:amd64
Package: libwxgtk3.0-0v5
Status: install ok installed
Priority: optional
Section: libs
Installed-Size: 16463
Maintainer: Ubuntu Developers <[email protected]>
Architecture: amd64
Multi-Arch: same
Source: wxwidgets3.0
Version: 3.0.4+dfsg-3
Replaces: libwxgtk3.0-0
Depends: libc6 (>= 2.15), libcairo2 (>= 1.6.0), libgcc1 (>= 1:3.0), libgdk-pixbuf2.0-0 (>= 2.22.0), libgl1, libglib2.0-0 (>= 2.24.0), libgtk2.0-0 (>= 2.24.0), libjpeg8 (>= 8c), libnotify4 (>= 0.7.0), libpango-1.0-0 (>= 1.18.0), libpangocairo-1.0-0 (>= 1.14.0), libpng16-16 (>= 1.6.2-1), libsm6, libstdc++6 (>= 5.2), libtiff5 (>= 4.0.3), libwxbase3.0-0v5 (>= 3.0.4+dfsg), libx11-6, libxxf86vm1
Breaks: libwxgtk3.0-0
Description: wxWidgets Cross-platform C++ GUI toolkit (GTK+ runtime)
 wxWidgets (formerly known as wxWindows) is a class library for C++ providing
 GUI components and other facilities on several popular platforms (and some
 unpopular ones as well).
 .
 This package provides the shared libraries needed to run programs linked
 against wxWidgets.  To use the (optional) glcanvas library you will need
 to have Mesa or OpenGL installed.
Original-Maintainer: wxWidgets Maintainers <[email protected]>
Homepage: https://www.wxwidgets.org/
Thanks in advance
J.
jpo234
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Feb 25, 2020 11:34 am

Re: GTK2: wxListCtrl::SortItems throws an assertion when called from event handler

Post by jpo234 »

Small correction: The problem happens when I call wxListCtrl::SortItems from the wxEVT_COMMAND_LIST_DELETE_ITEM handler. Since deletion doesn't change the sorting, the fix is to not call wxListCtrl::SortItems on wxEVT_COMMAND_LIST_DELETE_ITEM.
BUT: The assertion still bothers me. The sorting on deletion is not necessary, but it's not actually wrong.

Regards
J.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: GTK2: wxListCtrl::SortItems throws an assertion when called from event handler

Post by PB »

I do not know anything concrete regarding this, but generally some actions cannot be done from some event handlers, and that may be platform specific and usually not documented. The common solution is to use one of the two CallAfter() variants.
jpo234
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Feb 25, 2020 11:34 am

Re: GTK2: wxListCtrl::SortItems throws an assertion when called from event handler

Post by jpo234 »

PB wrote: Tue Mar 31, 2020 11:27 am The common solution is to use one of the two CallAfter() variants.
Thanks! While I already found my own fix, this is good to know.
Post Reply