d2phap / ImageGlass

🏞 A lightweight, versatile image viewer
https://imageglass.org
Other
7.9k stars 502 forks source link

Error when attempting to copy image "Requested Clipboard operation did not succeed." #1130

Closed snowbie closed 3 years ago

snowbie commented 3 years ago

System information:

To Reproduce

Steps to reproduce the behavior:

  1. Open image
  2. Copy via context menu or hotkey (Ctrl+Shift+C) If it successfully copies, do it again until error occurs.

Actual behavior:

Upon attempting to copy an image, if it doesn't immediately copy, an error will pop up after a second or so, saying

Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately,

Requested Clipboard operation did not succeed."

************** Exception Text **************
System.Runtime.InteropServices.ExternalException (0x800401D0): Requested Clipboard operation did not succeed.
   at System.Windows.Forms.Clipboard.ThrowIfFailed(Int32 hr)
   at System.Windows.Forms.Clipboard.SetDataObject(Object data, Boolean copy, Int32 retryTimes, Int32 retryDelay)
   at System.Windows.Forms.Clipboard.SetFileDropList(StringCollection filePaths)
   at ImageGlass.frmMain.CopyMultiFiles()
   at ImageGlass.frmMain.mnuMainCopy_Click(Object sender, EventArgs e)
   at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripMenuItem.ProcessCmdKey(Message& m, Keys keyData)
   at System.Windows.Forms.ToolStripManager.ProcessShortcut(Message& m, Keys shortcut)
   at System.Windows.Forms.Form.ProcessCmdKey(Message& msg, Keys keyData)
   at System.Windows.Forms.Control.ProcessCmdKey(Message& msg, Keys keyData)
   at System.Windows.Forms.ContainerControl.ProcessCmdKey(Message& msg, Keys keyData)
   at System.Windows.Forms.Control.ProcessCmdKey(Message& msg, Keys keyData)
   at System.Windows.Forms.Control.ProcessCmdKey(Message& msg, Keys keyData)
   at System.Windows.Forms.ContainerControl.ProcessCmdKey(Message& msg, Keys keyData)
   at System.Windows.Forms.Control.ProcessCmdKey(Message& msg, Keys keyData)
   at System.Windows.Forms.Control.ProcessCmdKey(Message& msg, Keys keyData)
   at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
   at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
   at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)

It seems somewhat random in frequency. Sometimes it happens consistently; sometimes it doesn't happen at all. Using the same image, the error was produced for 40/70 copy attempts. It appears it fails & succeeds in batches, like F F F F F S S S F F F S S F... Regardless, just the other day I was able to view & copy hundreds if not thousands of images and not have a single error appear, but now it seems to be happening again. I updated from 8.2.6.6 to the latest Moon release hoping it'd fix it, but no luck. Is it a bug in the program or is it something on my end? I haven't received an error like this for any other program.

Expected behavior:

The image to be copied (the copying method that allows for several images to be copied to the clipboard)

Additional context:

The error does not occur at all for the copying of image data (Ctrl+C) Relaunching the program does not fix it. Restarting of the computer does not fix it.

fire-eggs commented 3 years ago

Some quick research indicates this error occurs because another application is using the clipboard at the same time. [The clipboard is a shared-with-everyone resource.] E.g. one post suggests using task manager to look for a process called "rdpclip" and killing it.

ImageGlass needs to do two things here:

  1. Catch the exception so the crash/unhandled-exception scenario doesn't occur.
  2. Retry the copy. SetDataObject has retry/delay parameters to do so automagically but IG is using SetDropFilesList, so I don't understand the implications off-hand.
snowbie commented 3 years ago

Some quick research indicates this error occurs because another application is using the clipboard at the same time. [The clipboard is a shared-with-everyone resource.] E.g. one post suggests using task manager to look for a process called "rdpclip" and killing it.

Thanks for the explanation. I went process by process to try and narrow down what could potentially be conflicting, and I was able to find it. Terminating "syncthing", a program used to sync directories between devices, is what was conflicting with IG. If a program regularly updates its files/generates temp files, it can break the syncing process. Like instead of foobar2000 failing to run, its "running" file fails to sync. Something like KeePass works flawlessly since I assume it doesn't rely on temp files.

I wouldn't be surprised if the copying method conflicts more heavily with syncthing, thus causing errors instead of simply causing the syncing process to fail. Either way, I'm glad it was sorted out.