pescuma / swt-paperclips

Automatically exported from code.google.com/p/swt-paperclips
0 stars 0 forks source link

[GTK] PrintPreview issues page feed #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Copied from
http://sourceforge.net/tracker/index.php?func=detail&aid=1773091&group_id=148509
&atid=771872

As discussed in the forum, I'm opening a bug report here on this issue
(sorry for being late)..

Bug report from the corresponding forum thread:

On Linux-GTK (GTK 2.10.11, Ubuntu 7.04 Feisty Fawn, both Eclipse 3.3 and
3.4M1, PaperClips from latest SVN source), using PrintPreview issues
something like a page feed, i.e. my printer spits out an empty page, even
though no printing function has actually been called. Mostly this happens
when closing a preview window, but I've seen this happen also directly when
the preview is displayed.

----

= Comments =

----

Date: 2007-08-22 04:28
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

I haven't had the time to load Linux on a machine and try this out myself,
however I'm not surprised.  In SWT 3.2 on MacOSX, there was a bug where if
you construct a GC on a Printer device, before calling startJob() on the
printer, then the GC will be immediately disposed.  To get around this I
would call startJob() on the Printer, and then when I'm done with the
printer instance, I call cancelJob().  I believe that the behavior you're
seeing is related to this implementation detail.

It's a little funny that you're getting a page feed since I never actually
call startPage() on the Printer instance.  I suspect this is a bug in SWT
on GTK.  Please try running the following snippet on your setup and see if
it spits out an empty page:

public class PageFeedTest {
  public statis void main(String[] args) {
    Printer printer = new Printer();
    printer.startJob("job");
//    GC gc = new GC(printer);
//    gc.dispose();
    printer.cancelJob();
  }
}

If it doesn't spit out a page, try uncommenting the lines in the middle
and run the test again.

If this test shows the same behavior then we will need to forward this bug
to SWT.  At that stage it might be a good idea to find out how many
versions of SWT are affected by this.

Matthew

----

Date: 2007-08-22 04:31
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

Heh.  Whoops.

Add a call to printer.dispose() at the end of the main() method body
before you run the test.

Sorry I took so long getting back to you, I've been out of town.

----

Date: 2007-08-22 06:35
Sender: ngc2997
Logged In: YES 
user_id=621901
Originator: YES

Hm, the test snippet does nothing but crashes the Java VM, when executed;
I've attached the error log.
File Added: hs_err_pid6964.log

----

Date: 2007-08-22 16:03
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

Was the crash with or without the GC lines?  Did it include the
printer.dispose() call?

This needs to be reported to SWT, and probably to Sun.

----

Date: 2007-08-22 16:44
Sender: ngc2997
Logged In: YES 
user_id=621901
Originator: YES

Both with and without the GC lines, including printer.dispose(); even this
one crashes:

public static void main(String[] args) {
  System.out.println(Printer.getPrinterList());
}

----

Date: 2007-08-22 16:50
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

Holy crap.  Report that to SWT right away, and make sure to attach the
error log.  A SIGSEGV is a big deal, and I've had several reports of those
lately.  This should be brought to their attention right away.  Make sure
to add the bug report address here so I can follow this.

----

Date: 2007-08-22 16:51
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

Whoops, didn't mean to close the bug.

----

Date: 2007-08-23 07:57
Sender: ngc2997
Logged In: YES 
user_id=621901
Originator: YES

When surrounded by this:

public static void main(String[] args) {
  Display display = new Display();
  Shell shell = new Shell(display);
  // Example code from below
  while (!shell.isDisposed()) {
    if (!display.readAndDispatch()
      display.sleep();
  }
  display.dispose();
}

the example code does not crash with a SIGSEGV fault, it rather crashes
with 'Exception in thread "main" org.eclipse.swt.SWTError: No more
handles'. When replacing
  Printer printer = new Printer();
with
  Printer printer = new Printer(Printer.getPrinterList()[1]);
(-> which is actually the correct printer on my system), it produces lots
of "(SWT:8605): GLib-CRITICAL **: g_io_channel_write_chars: assertion
`channel->is_writeable' failed" errors in stderr and then hangs (i.e. must
be 'killed'). ATM I'm not quite sure if the whole problem is caused by the
underlying system, or if it's really an SWT bug.. In my application,
printing works most of the time, it has never crashed with a SIGSEGV, it
just hangs sometimes (and issues an SWT message I don't quite remember) and
does not print (and does not freeze the app), and it shows the "empty page
feed" behaviour when using a print preview.. What might be related to this
is the fact that Printer.getDefaultPrinterData() returns null on my system,
even though I've set my printer as system default. (I've already reported
this to SWT -> https://bugs.eclipse.org/bugs/show_bug.cgi?id=199727)

I'm a bit in doubt how to get closer to the core of the matter.. :)

----

Date: 2007-08-23 09:22
Sender: ngc2997
Logged In: YES 
user_id=621901
Originator: YES

Hm, experimentally I've commented out the printer.dispose() call, and the
GLib-CRITICAL erros are gone.. -> ?!?

So, to summarize this:

  public static void main(String[] args) {

    Display display = new Display();
    Shell shell = new Shell(display);

    shell.open();

    Printer printer = new Printer(Printer.getPrinterList()[1]);
    printer.startJob("job");
//    GC gc = new GC(printer);
//    gc.dispose();
    printer.cancelJob();
//    printer.dispose();

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }

    display.dispose();

  }

Works; shows an empty window (as expected) and does nothing else, both
with and without the GC lines. When printer.dispose() is added, it freezes
with the GLib-CRITICAL error mentioned below; when the Display and Shell
stuff is omitted, it crashes with a SIGSEGV.. *sigh*

----

Date: 2007-08-28 06:43
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

Have you reported the SIGSEGV crashes to SWT?  I monitor the SWT bugzilla
inbox and haven't seen anything related to this issue.  It is really
important to report problems like these to the SWT teams.  This is a
serious bug and I'm sure they would want to be made aware of it.

----

Date: 2007-08-28 07:09
Sender: ngc2997
Logged In: YES 
user_id=621901
Originator: YES

Sorry, this has taken a bit longer.. :) I've reported the SIGSEGV to SWT
now (https://bugs.eclipse.org/bugs/show_bug.cgi?id=167562).

----

Date: 2007-08-28 07:11
Sender: ngc2997
Logged In: YES 
user_id=621901
Originator: YES

Oops.. that was the wrong link, obviously.. Seems it's still too early in
the morning. *sigh* So, here's the correct bug id:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=201373

----

Date: 2007-08-28 11:29
Sender: mikydv
Logged In: YES 
user_id=1857408
Originator: NO

I have too the blank page problem, when I run StyledTextExample.java in
Linux. If I change code "printer.endJob();" in
"PaperClips.getPages(PrintJob, Printer)" method with "printer.cancelJob();"
problem is resolved; these changes also resolve problem of the print icon's
flash in the system tray, of which I have made reference in this tracker:
https://sourceforge.net/tracker/index.php?func=detail&aid=1771459&group_id=14850
9&atid=771873

----

Date: 2007-08-28 18:53
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

This bug was introduced in GTK to get around a bug in OSX..

Please update to SVN revision 284 (in the
/branches/experimental/styledtextprint/ branch) and see if this stops
spitting out the blank pages.

Original issue reported on code.google.com by qualidaf...@gmail.com on 9 Oct 2008 at 5:00

GoogleCodeExporter commented 9 years ago
= Comments (cont.) =

Date: 2007-08-28 22:33
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

Per the feedback in the SWT bugzilla, I've added a call to
Display.getDefault() in all the example programs that lacked a Display.

Please try out the examples again and verify whether they work without
crashing now.

Matthew

----

Date: 2007-08-29 08:39
Sender: mikydv
Logged In: YES 
user_id=1857408
Originator: NO

Changes on Paperclips.getPages( PrintJob, Printer ) cause an SWT exception
in Linux because of printer's job that is not started.
I post to you my own changes that resolve this one and the problem on
print icon's flash in the system tray in Windows.

  public static PrintPiece[] getPages( PrintJob printJob, Printer printer
) {
    String platform = SWT.getPlatform();
    boolean carbon = platform.equals( "carbon" );
    boolean gtk = platform.equals( "gtk" );

    // Bug in SWT on OSX: If Printer.startJob() is not called first, the
GC will be disposed by default.
    if ( carbon || gtk )
      if ( !printer.startJob( "" ) )
        throw new RuntimeException( "Unable to start print job" );

    try {
      GC gc = createConfiguredGC( printer );
      try {
        return getPages( printJob, printer, gc );
      }
      finally {
        gc.dispose();
      }
    }
    finally {
      // 2007-04-30: A bug in OSX renders Printer instances useless after
a call to cancelJob(). Therefore on
      // OSX we call endJob() instead of cancelJob().
      if ( carbon )
        printer.endJob();
      else
        if ( gtk )
          printer.cancelJob();
    }
  }

I hope is appreciate to you.

----

Date: 2007-08-29 17:07
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

Your changes are in SVN as of revision 292.

----

Date: 2007-08-30 12:04
Sender: ngc2997
Logged In: YES 
user_id=621901
Originator: YES

To return to the original issue we were talking about:

I've now tested your snippet from below with the addition of a
Display.getDefault(); both with and without the GC lines, it does not spit
out an empty page. *sigh*

  public static void main(String[] args) {

    Display display = Display.getDefault();

    Printer printer = new Printer(Printer.getPrinterList()[1]);
    printer.startJob("job");
    GC gc = new GC(printer);
    gc.dispose();
    printer.cancelJob();

    display.dispose();

  }

----

Date: 2007-09-14 15:28
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

I've merged the styledtextprint branch back into the trunk, and have made
further changes (lots and lots of refactoring) there.  Can you please
update to the latest source and ensure that the page feed problem is gone?

mikdyv, I'd like add you to the contributor list in the sources for your
PaperClips.getPages() fix--what name shall I use?

----

Date: 2007-09-14 16:40
Sender: mikydv
Logged In: YES 
user_id=1857408
Originator: NO

I don't think that you have to consider me a contributor (I've passed you
only two lines of code). However, if you really think that I could be a
contributor, my real name is Michele De Vecchi. Thanks, I'm never been a
contributor ;-)

----

Date: 2007-09-16 07:10
Sender: ngc2997
Logged In: YES 
user_id=621901
Originator: YES

Hm, I am sorry to report that after updating to the latest source the page
feed problem still persists.. :|

However, I've found out the following:

...
    final ScrolledComposite scroll = new ScrolledComposite(composite,
SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    final PrintPreview preview = new PrintPreview(scroll, SWT.NONE);

    // FIXME This is a hack.
    preview.setPrinterData(Printer.getPrinterList()[1]);
...

This is an excerpt from the preview code in my application (in fact, it is
an adapted version of the preview snippet on your PaperClips project site).
Now, without the line marked as "FIXME" (which actually is a hack..), it
won't preview anything at all, it only shows a black rectangle. This might
have something to do with the fact that on my system,
Printer.getDefaultPrinterData() returns null (for which I haven't found any
reasons so far). With that line, the preview works as expected, but it also
issues the page feed..

----

Date: 2007-10-17 16:15
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

ngc, please update to the latest sources from SVN and tell me if the page
feed still happens.

Matthew

----

Date: 2007-10-18 05:54
Sender: ngc2997
Logged In: YES 
user_id=621901
Originator: YES

Hm, the page feed is gone; instead, the application freezes when closing
the preview, and issues the following on Eclipse's stderr console:

(SWT:6767): GLib-CRITICAL **: g_io_channel_write_chars: assertion
`channel->is_writeable' failed
<repeated until the process is killed>

----

Date: 2007-10-18 15:07
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

Does this happen if you just start up the preview and immediately close
it?  We're talking about Snippet7, right?

Also, please try this with SWT 3.3.1 and 3.4M2 to see if either of these
has a different behavior.

Matthew

----

Date: 2007-11-01 17:47
Sender: ngc2997
Logged In: YES 
user_id=621901
Originator: YES

Sorry, took me a bit longer to answer as I've been busy upgrading my
system to Ubuntu Gutsy..

However; I was talking about the print preview feature in an application
I've developed for personal use, which in fact uses the code from snippet 7
(slightly modified). Snippet7 itself does not work at all on my system
(I've just tested this with Eclipse 3.4M2), when starting, it takes quite a
long time for the window to appear, then it consumes 50% CPU and stays
empty. *sigh*

----

Date: 2007-11-01 17:55
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

Try printing in Snippet7 and tell me what happens--I'm predicting a
RuntimeException that says it can't layout on page x.  A full stack trace
would be helpful.

----

Date: 2007-11-15 18:12
Sender: ngc2997
Logged In: YES 
user_id=621901
Originator: YES

Hm, no chance.. I've updated to the latest SVN source and also updated the
code for Snippet7; when starting, it still displays an empty window, while
cpu load stays at 50% permanently, until the process is killed. Could this
have sth to do with Eclipse 3.4M3?? (SWT 3418)

----

Date: 2007-11-16 04:06
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

I have no idea.  Have you tried a debugger session on the PrintPreview
class?  Set a breakpoint in the paint(Event) method and step into every
child method.  See if any of the fields are not set or if any sanity checks
return from the paint() method prematurely.

Matthew

----

Date: 2007-11-16 04:15
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

I'm not sure if you understood my suggestion from 2007-11-01 so I'll
restate it: Try running Snippet7, and click Print, select a printer, click
OK, and see if an exception occurs.  Another possible outcome is that the
document prints and the preview mysteriously appears.  Let me know if
either of those are the case and we'll proceed from that point.

----

Date: 2007-11-16 06:53
Sender: ngc2997
Logged In: YES 
user_id=621901
Originator: YES

Hm I actually have understood your suggestion, the problem is that I don't
even get any output, just a blank window. I've added a screenshot to
illustrate that; as you can see there, there is no print button and thus no
chance to try printing, unfortunately.

However, I've had a debugging session into the depths of PaperClips and
found the snippet hangs in PaperClips.getPages(PrintJob printJob, Printer
printer, GC gc), around line 313 (the while loop). For some reasons I've
not found yet, it seems to do an infinite loop there, creating an ever
growing and growing array list of pages (the iterator always seems to
report hasNext() as true), which is what causes the application 'freeze'
and the cpu load. I'll try and go even deeper into this..
File Added: Snippet7.png

----

Date: 2007-11-18 10:14
Sender: ngc2997
Logged In: YES 
user_id=621901
Originator: YES

Here's another hint from today's debugging session.. when changing this

[..]
String text = "The quick brown fox jumps over the lazy dog.";
for (int i = 0; i < 50; i++)
  grid.add(new TextPrint(text));
[..]

to

[..]
String text = "The quick brown fox jumps over the lazy dog.";
grid.add(new TextPrint(text));
[..]

the snippet works as expected, meaning: it displays the window, the
preview control and all buttons. Pushing the 'print' button prints the
document. However, when closing the window, the application crashes with
multiple

"(SWT:7153): GLib-CRITICAL **: g_io_channel_write_chars: assertion
`channel->is_writeable' failed"

errors in stderr.

----

Date: 2007-11-30 16:08
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

Exceptions that happen in native SWT code should be reported to SWT.

It seems that none of these GTK errors were happening in 3.2, what happens
if you run your snippet against that version?

----

Date: 2007-12-11 20:20
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

I finally broke down and installed Linux on my machine (dual boot).  I'm
seeing the same GLib-CRITICAL errors as you, and found that they are caused
during the Printer disposal process.  It only happens if you call
cancelJob() instead of endJob().  Unfortunately this means that I have to
go back to using endJob() since printing a blank page is a lot better than
a GTK core dump.  When SWT and/or GTK resolves these issues I will update
PaperClips accordingly.

I have logged a bug with SWT regarding the GLib-CRITICAL issue, perhaps
they will be able to find a workaround:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=212594

GTK also has a bugzilla requesting the ability to cancel a print job (this
is why cancelJob() doesn't work in SWT on GTK--there's no API for it in
GTK)
http://bugzilla.gnome.org/show_bug.cgi?id=339323 "Cancel print job"

----

Date: 2007-12-11 20:48
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

As of SVN revision 365 Printer.endJob() is used instead of
Printer.cancelJob().  If you update to the latest from SVN you will get
blank pages again but no GLib-CRITICAL errors.

I will file a separate bug with SWT regarding the blank pages.

----

Date: 2007-12-13 16:51
Sender: qualidafialProject AdminAccepting Donations
Logged In: YES 
user_id=168544
Originator: NO

This will not be fixed until Gnome creates an API for cancelling a print
job:
http://bugzilla.gnome.org/show_bug.cgi?id=339323 "Cancel print job"

Original comment by qualidaf...@gmail.com on 9 Oct 2008 at 5:05

GoogleCodeExporter commented 9 years ago

Original comment by qualidaf...@gmail.com on 9 Oct 2008 at 7:55

GoogleCodeExporter commented 9 years ago

Original comment by qualidaf...@gmail.com on 13 Oct 2008 at 2:33

GoogleCodeExporter commented 9 years ago

Original comment by qualidaf...@gmail.com on 13 Oct 2008 at 2:33

GoogleCodeExporter commented 9 years ago

Original comment by qualidaf...@gmail.com on 17 Dec 2008 at 5:45

GoogleCodeExporter commented 9 years ago
PaperClips is migrating to the Eclipse project.

This bug is now being tracked at http://bugs.eclipse.org/291862

Original comment by qualidaf...@gmail.com on 9 Oct 2009 at 5:45