Windows: Copying text crashes with GTK 3
When trying to copy text from within GTK widgets with GTK 3 (possibly also GTK 4, but I'm currently unable to test this), the application crashes most of time, but not always. Sometimes it's also pasting that causes the crash (but I was not able to reproduce this myself, just from reports I got).
I'm pretty sure this would also affect GTK 4, since this seems to be a bug in GDK.
I think this is a distinct issue from #5591, but I used basically the same steps to reproduce and sample code, just ported to GTK 3, see below. Notably this "new" issue happens on copying and does not produce any warnings.
I think this may have been caused by !5690 (merged) - but I don't know.
Steps to reproduce
Given an application with a Gtk.TextView
(using Gtk.TextBuffer
), the following steps reproduce the issue 100% for me:
- Use the mouse to highlight some text in the
Gtk.TextView
- Copy the text (
Ctrl-C
or right-clickCopy
from context menu) - The application freezes brifely and then crashes without any error output.
Sample Code
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gio
class CopyPasteCrashDemo(Gtk.Application):
def __init__(self):
Gtk.Application.__init__(self, application_id=None, flags=Gio.ApplicationFlags.FLAGS_NONE)
self.window = None
self.connect('activate', self.on_activate)
def on_activate(self, application):
self.window = MainWindow(application=application)
self.window.set_title('GTK4 Copy/Paste Crash Demo')
self.window.present()
class MainWindow(Gtk.ApplicationWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.set_size_request(300, 200)
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.add(box)
self.textBuffer = Gtk.TextBuffer()
self.textView = Gtk.TextView(buffer=self.textBuffer)
self.textView.set_cursor_visible(False)
self.textView.set_editable(False)
self.textView.set_size_request(300, 150)
box.add(self.textView)
text = '\nHighlight me, right-click, and Copy. Then, paste in the Gtk.Entry below\n'
self.textBuffer.insert(self.textBuffer.get_end_iter(), text)
entry = Gtk.Entry()
box.add(entry)
self.show_all()
app = CopyPasteCrashDemo()
app.run(None)
Version information
- GTK 3.24.37, built around a week ago with gvsbuild
- Windows 10 22H2
- Python 3.11
- gvsbuild: gvsbuild build --enable-gi --py-wheel gtk3 pygobject openssl gettext gtksourceview4 hicolor-icon-theme adwaita-icon-theme
Console output
This was generated using GTK_DEBUG=all and GDK_DEBUG=all. It's the prints from after right-clicking to copy to the crash.
===> GDK_BUTTON_PRESS 0000000000180270 @ 4046093ms 3 (123,82) (476,350) => 0
gdk_display_request_selection_notification (..., CLIPBOARD) -> TRUE
gdk_selection_owner_get: CLIPBOARD = 0000000000000000
gdk_selection_convert: 00000000000603A0 CLIPBOARD TARGETS
Opened clipboard for 0x00000000000603A0 @ ../gdk/win32/gdkselection-win32.c:2263