Bug 427840 - Display becomes unresponsive when active print job
Summary: Display becomes unresponsive when active print job
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.8.1   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Abhishek Kishore CLA
QA Contact:
URL:
Whiteboard:
Keywords: needinfo
Depends on:
Blocks:
 
Reported: 2014-02-10 15:09 EST by Adam Briska CLA
Modified: 2014-10-07 03:02 EDT (History)
5 users (show)

See Also:


Attachments
File demonstrating the behavior (2.69 KB, application/octet-stream)
2014-02-10 15:09 EST, Adam Briska CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Briska CLA 2014-02-10 15:09:48 EST
Created attachment 239799 [details]
File demonstrating the behavior

In my application, I wish to print a complex document that requires some computation to set up each page.  The attempted approach was to create a printer job, then periodically call Display.readAndDispatch() to keep the display active.

Unfortunately, as soon as a print job exists, I am no longer seeing any updates to the screen.

Attached is a modified version of the progress bar snippet (57) that shows the bug.  When you run the snippet, the progress bar proceeds normally until you click the button to start a new print job.  After pressing the display freezes.  Clicking the button again cancels the job and the display becomes active.

I would expect that having a print job active would not impact the behavior of the main display.
Comment 1 Niraj Modi CLA 2014-02-11 01:10:13 EST
Abhishek, can you please try the test snippet ? Thanks.
Comment 2 Abhishek Kishore CLA 2014-02-12 00:58:21 EST
(In reply to Adam Briska from comment #0)
> Created attachment 239799 [details]
> File demonstrating the behavior
> 
> In my application, I wish to print a complex document that requires some
> computation to set up each page.  The attempted approach was to create a
> printer job, then periodically call Display.readAndDispatch() to keep the
> display active.
> 
> Unfortunately, as soon as a print job exists, I am no longer seeing any
> updates to the screen.
> 
> Attached is a modified version of the progress bar snippet (57) that shows
> the bug.  When you run the snippet, the progress bar proceeds normally until
> you click the button to start a new print job.  After pressing the display
> freezes.  Clicking the button again cancels the job and the display becomes
> active.
> 
> I would expect that having a print job active would not impact the behavior
> of the main display.

A call to startJob() on a Printer object must be followed by endJob() somewhere down the line, with the actual printing in between. The documentation on startJob() explains this in some more detail.

And of course, you can move the printing part of your code to a separate thread if its going to hold up UI for too long.
Comment 3 Arun Thondapu CLA 2014-02-13 06:20:31 EST
I tested the attached snippet on Linux and the progress bar continues to update even after the printer job is started. This could very well be a problem with the Cocoa printing API itself but we need to confirm that.
Comment 4 Abhishek Kishore CLA 2014-02-13 23:32:19 EST
(In reply to Arun Thondapu from comment #3)
> I tested the attached snippet on Linux and the progress bar continues to
> update even after the printer job is started. This could very well be a
> problem with the Cocoa printing API itself but we need to confirm that.

That's very likely true. I've tested, and it works fine on Windows 7 as well. However, without an endJob(), printing won't go through, atleast on Mac. I tested with Snippet132, after commenting endJob(), and it doesn't work. I don't see much use of fixing this issue if printing is not going to work with this code(without endJob()) anyway.
Comment 5 Arun Thondapu CLA 2014-02-14 04:31:25 EST
(In reply to Abhishek Kishore from comment #4)
> (In reply to Arun Thondapu from comment #3)
> > I tested the attached snippet on Linux and the progress bar continues to
> > update even after the printer job is started. This could very well be a
> > problem with the Cocoa printing API itself but we need to confirm that.
> 
> That's very likely true. I've tested, and it works fine on Windows 7 as
> well. However, without an endJob(), printing won't go through, atleast on
> Mac. I tested with Snippet132, after commenting endJob(), and it doesn't
> work. I don't see much use of fixing this issue if printing is not going to
> work with this code(without endJob()) anyway.

Agreed.

Adam, please mention if you're fine with closing this bug as Printer#endJob() is necessary for a successful print job anyway and adding the endJob() call makes this bug go away.
Comment 6 Abhishek Kishore CLA 2014-02-17 23:23:12 EST
Resolving this. Please reopen if you have problems with the suggested approach.
Comment 7 Adam Briska CLA 2014-02-18 11:46:26 EST
Re-opening.

(This is also in my observation a Mac-specific bug.)


Consider code like the following:

printer.startJob();  

while( havePages() ) {
  sendPageToPrinter();
  while(Display.getCurrent().readAndDispatch() );
}

printer.endJob();

In this example, the display will not update during the duration between startJob and endJob, even with the calls to readAndDispatch().

In my application, the act of printing may take several seconds, and during this time, the application appears to have hung.
Comment 8 Abhishek Kishore CLA 2014-02-20 03:40:34 EST
(In reply to Adam Briska from comment #7)
> Re-opening.
> 
> (This is also in my observation a Mac-specific bug.)
Yes, looks like it is.

> 
> 
> Consider code like the following:
> 
> printer.startJob();  
> 
> while( havePages() ) {
>   sendPageToPrinter();
>   while(Display.getCurrent().readAndDispatch() );
> }
> 
> printer.endJob();
> 
> In this example, the display will not update during the duration between
> startJob and endJob, even with the calls to readAndDispatch().
> 
> In my application, the act of printing may take several seconds, and during
> this time, the application appears to have hung.

And you're not fine with running your print job on a different thread?
Comment 9 Adam Briska CLA 2014-02-20 11:58:51 EST
> 
> And you're not fine with running your print job on a different thread?

Much of the printing code re-uses the same code that was used to draw the display in the application, hence much of it is built on SWT controls that do not work on the non-UI thread.

It seems surprising to me that the presence of an active print job would interfere at all with the normal function of the UI.
Comment 10 Abhishek Kishore CLA 2014-03-13 02:49:32 EDT
(In reply to Adam Briska from comment #9)
> > 
> > And you're not fine with running your print job on a different thread?
> 
> Much of the printing code re-uses the same code that was used to draw the
> display in the application, hence much of it is built on SWT controls that
> do not work on the non-UI thread.
> 
> It seems surprising to me that the presence of an active print job would
> interfere at all with the normal function of the UI.

Is there a snippet of code that you can provide where the printing code re-uses code that must be executed in the UI thread?
Comment 11 Abhishek Kishore CLA 2014-10-07 03:02:36 EDT
Resolving this. Please reopen when you've a response to comment 10.