From f9b793f8d19dd4f9b7628074a6537596036b2583 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 10 Mar 2020 19:16:29 +0100 Subject: [PATCH] Check for valid entry in wxTextEntry::EnableTextChangedEvents() GetTextObject() might return null, e.g. it does it for read-only wxBitmapComboBox, so EnableTextChangedEvents() must account for this possibility, as it's not really possible to avoid calling it in this case, as it's called indirectly from e.g. SetSelection(). Check that the entry is valid before enabling or disabling events for it to avoid several GLib assertion failures every time when e.g. wxBitmapComboBox::SetValue() is called. Closes https://github.com/wxWidgets/wxWidgets/pull/1756 --- src/gtk/textentry.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gtk/textentry.cpp b/src/gtk/textentry.cpp index ccb8b1c663..320c782f6e 100644 --- a/src/gtk/textentry.cpp +++ b/src/gtk/textentry.cpp @@ -1003,14 +1003,21 @@ int wxTextEntry::GTKEntryIMFilterKeypress(GdkEventKey* event) const void wxTextEntry::EnableTextChangedEvents(bool enable) { + // Check that we have the associated text, as it may happen (for e.g. + // read-only wxBitmapComboBox) and shouldn't result in any errors, we just + // don't have any events to enable or disable in this case. + void* const entry = GetTextObject(); + if ( !entry ) + return; + if ( enable ) { - g_signal_handlers_unblock_by_func(GetTextObject(), + g_signal_handlers_unblock_by_func(entry, (gpointer)wx_gtk_text_changed_callback, this); } else // disable events { - g_signal_handlers_block_by_func(GetTextObject(), + g_signal_handlers_block_by_func(entry, (gpointer)wx_gtk_text_changed_callback, this); } }