naps2 icon indicating copy to clipboard operation
naps2 copied to clipboard

The application freezes if you try to split an image during background scanning

Open SeiOkami opened this issue 7 months ago • 9 comments

Describe the bug A background scan of the next page is taking place. I'm trying to edit an existing one. I press the "Split" button and the application freezes.

To Reproduce Steps to reproduce the behavior:

  1. Scan one page
  2. Start scanning the second page in the background
  3. While scanning is in progress, open the first page and click the "Split" button

Expected behavior The application should not freeze.

Desktop (please complete the following information):

  • OS: [e.g. Windows 11 Pro]
  • Version 24H2

SeiOkami avatar Apr 12 '25 17:04 SeiOkami

This might be a separate issue, but it sounds similar to what I'm experiencing - Saving a PDF and scanning in the background causes the application to freeze.

I am running Win10 Pro 22H2

snachodog avatar Apr 16 '25 17:04 snachodog

Yes, also hangs sometimes when using the crop tool

DozeyM avatar Apr 21 '25 13:04 DozeyM

What scanner? What driver type (twain/wia)? When you say freeze/hang, is that permanent or does it resolve itself once the scan finishes? If you scan from the Profiles window (then close the window and Split) does that freeze too? Is it fully consistent or only happens sometimes?

cyanfish avatar Apr 22 '25 20:04 cyanfish

I created the issue that you linked.

The application freezes and hangs forever. There seems to be no way to recover. The application does not react, but according to Windows it is still responsive (no "Application Is Not Responding" message in the title). The cropping button however visually stays in pressed state. The ongoing scan is not saved.

Scanner: Canon TS5350. WIA driver. The behaviour is easily reproducible.

It does not happen from the profiles window because you cannot edit a scanned page while the profiles window is open.

TobiasKnauss avatar Jun 03 '25 06:06 TobiasKnauss

Thanks, can you try this test version and see if it fixes the issue?

cyanfish avatar Jun 03 '25 06:06 cyanfish

I have tested it, the problem still exists, It freezes in the same way. But a few times I was able to start the cropping without NAPS2 freezing. But this also might be the case in the regular version (not tested). Are you not able to reproduce it yourself?

Here are some screenshots from Sysinternals Process Explorer. The tests were done on your new test version.

This is the process state before the problem: Image

This is the process state when it hangs: Image

I can kill all subtasks and it still hangs. Appears to me like a GUI update deadlock or a timing issue.

These are the main process' threads before the problem: Image

These are the main process' threads when it hangs: Image

One more thread is started every second (see the thread count) until I kill the main process: Image

This is the stack trace of the main thread when it hangs and creates new threads:

0x0000000000000000
combase.dll!HRGN_UserFree+0x23be
combase.dll!CoUnloadingWOW+0x1aca
combase.dll!CoUnloadingWOW+0x5f9
combase.dll!CoUnloadingWOW+0x1073
combase.dll!CoUnloadingWOW+0x2135
combase.dll!CoWaitForMultipleHandles+0xbb
coreclr.dll!GetCLRRuntimeHost+0x325cc
coreclr.dll!coreclr_set_error_writer+0x35a18
coreclr.dll+0xe523
coreclr.dll+0xe35a
coreclr.dll!coreclr_execute_assembly+0x622cc
coreclr.dll!coreclr_execute_assembly+0x620c7
System.Private.CoreLib.dll+0x3a2bd5
System.Private.CoreLib.dll+0x3af65f
System.Private.CoreLib.dll+0x3c8d96
System.Private.CoreLib.dll+0x3c8b5e
System.Private.CoreLib.dll+0x3c879e
System.Private.CoreLib.dll+0x3c8632
System.Threading.Tasks.Parallel.dll+0x8ef0
0x0000000000000000

TobiasKnauss avatar Jun 03 '25 18:06 TobiasKnauss

Yeah, it works fine for me (though I have some more scanners in my closet I could pull out to test with). It's very strange that the test version didn't fix it, as it makes it so WIA scanning runs in an entirely separate process.

At what point exactly does it freeze? When you first open the crop window? A bit after the crop window opens? If you're dragging around the crop handles? If you press the OK button?

cyanfish avatar Jun 03 '25 19:06 cyanfish

Also, if you're so inclined, debugging from source and seeing the UI thread's stack trace from within the Visual Studio debugger would be super helpful (Sysinternals can't see the .NET stack properly).

cyanfish avatar Jun 03 '25 19:06 cyanfish

At what point exactly does it freeze? When you first open the crop window? A bit after the crop window opens? If you're dragging around the crop handles? If you press the OK button?

It freezes in the moment I press the crop button in the edit window. The crop window never opens. I think the main thread is somehow blocked to open the cropping window, and tries over and over by starting new threads. I bet this is completely unrelated to WIA, but rather an internal issue in the UI handling, maybe because the update of the scan process bar takes place while the crop button is clicked. I scan at 300dpi which causes a quite fast update of the progress bar.

TobiasKnauss avatar Jun 03 '25 22:06 TobiasKnauss

version 8.2.0: the issue persists.

TobiasKnauss avatar Aug 24 '25 06:08 TobiasKnauss