sublime_text icon indicating copy to clipboard operation
sublime_text copied to clipboard

Sublime hangs on pasting image data and loses all unsaved data

Open niedzielski opened this issue 2 years ago • 9 comments

Description of the bug

Accidentally pasting image data into Sublime Text hangs the program. Closing ST at this point causes it to lose all unsaved data.

Peek 2022-06-25 19-00

Steps to reproduce

  1. Open Sublime Text 3.
  2. Create some tabs with unsaved work.
  3. Close Sublime Text.
  4. Reopen Sublime Text and see your unsaved work restored.
  5. Open an image editor and copy a region.
  6. Paste into a Sublime Text buffer.
  7. At this point, Sublime Text is partially hung. The cursor is unresponsive but newly entered text is rendered and the line highlight works.
  8. Close Sublime Text by typing alt+f4.
  9. Reopen Sublime Text. All unsaved work is lost forever.

FWIW, I tried pasting the same copied data into GIMP and it pasted fine.

Expected behavior

Sublime Text v3 has better ability to restore unsaved work and workspaces.

Actual behavior

Sublime Text crashed and all my unsaved work was lost along with my workspace and open tabs. Obviously, I'm frustrated but the ability to never lose data is a critical feature for text editors.

Sublime Text build number

4126

Operating system & version

Debian 11 bullseye 64b

(Linux) Desktop environment and/or window manager

GNOME v3.38.5

Additional information

No response

OpenGL context information

No response

niedzielski avatar Jun 26 '22 01:06 niedzielski

Note that build 4126 is ST4 not ST3. I'm unable to reproduce this by copying a region from gimp in ubuntu 20.04 gnome 3.36. Does it happen in X11 or Wayland?

BenjaminSchaaf avatar Jun 29 '22 07:06 BenjaminSchaaf

Thanks for the reply. Sorry for the wrong version. Build number confirmed from the about menu item. I'm on X11. I cannot repro with GIMP or Krita.

niedzielski avatar Jun 30 '22 06:06 niedzielski

What software can you reproduce it with?

BenjaminSchaaf avatar Jun 30 '22 07:06 BenjaminSchaaf

I know it happens with Aseprite (source) as shown in the GIF. I haven't tried anything else beside GIMP and Krita.

niedzielski avatar Jul 01 '22 01:07 niedzielski

This seems to come from Aseprite causing gtk_clipboard_wait_for_text to hang forever. My guess is that it should be replying that it doesn't have any text to copy, but isn't.

BenjaminSchaaf avatar Jul 11 '22 06:07 BenjaminSchaaf

Dang! Thank you for the great sleuthing! :+1: I couldn't find any known issue in Aseprite but it's a pretty niche program.

For me, the biggest issue is that when Sublime Text does hang or crash (whether due to external or internal bugs), it's easy for it to lose data. As far as I'm aware, there's no concept in Sublime of multiple recovery sessions so when something bad happens, that data is gone for good. Recovery sessions don't stack and there's no trick to reviving an outdated one. In Vim, for example, I don't think there's any scenario with a .sw* recovery file is automatically overwritten.

niedzielski avatar Jul 17 '22 22:07 niedzielski

I haven't been able to reproduce any data loss on my end; except for the obvious last ~30s being lost due to any crash. Does it happen consistently for you? Is it losing the whole session or just the most recent changes?

BenjaminSchaaf avatar Jul 18 '22 04:07 BenjaminSchaaf

It's a 100% and all unsaved state is lost. Normally, the Sublime background process closes when all application windows are closed. From what I can tell, what happens here is that Sublime runs in a background process despite its only open (and frozen) window being closed. When a new window is opened, that background process is reused (?) and the new window blows away the save state of the frozen window so all data is lost. If there was a history of prior sessions preserved, instead of only a single session, this would never happen. That's the real issue.

I tried to illustrate more explicitly here where I open a Sublime window with preexisting state from launch:

  1. Grep for Sublime (no processes exist, it's just grep itself matching).
  2. Launch Sublime. See preexisting unsaved state.
  3. Modify state.
  4. Copy in Aseprite.
  5. Paste in Sublime. Sublime hangs in weird state.
  6. Press close cross in Sublime.
  7. Sublime still exists in background process!
  8. Launch Sublime again. A new window is made instead of restoring state! All prior state lost!
  9. Close new Sublime window.
  10. Sublime process is still running so kill Sublime.
  11. Launch Sublime.

Peek 2022-07-23 11-45

niedzielski avatar Jul 23 '22 17:07 niedzielski

Thanks, I've been able to reproduce that.

BenjaminSchaaf avatar Aug 15 '22 06:08 BenjaminSchaaf

Fixed in build 4135.

BenjaminSchaaf avatar Sep 15 '22 06:09 BenjaminSchaaf

I confirm the specific hang fix. Thank you!

niedzielski avatar Sep 16 '22 03:09 niedzielski