Issue 89072 - Macro Printing crashes OOo
Summary: Macro Printing crashes OOo
Status: CLOSED FIXED
Alias: None
Product: Writer
Classification: Application
Component: printing (show other issues)
Version: OOo 3.0 Beta
Hardware: PC Windows XP
: P2 Trivial (vote)
Target Milestone: ---
Assignee: joerg.skottke
QA Contact: issues@sw
URL:
Keywords: crash
Depends on:
Blocks:
 
Reported: 2008-05-06 15:53 UTC by hakre
Modified: 2013-08-07 14:44 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description hakre 2008-05-06 15:53:48 UTC
Dispatching two print commands let OOo do the printing properly. Additionally 
it crashes. Somekind of Segfault or such. Here is the Code, calling PrintJob 
will lead to the crash:

sub PrintJob
PrintPDF
PrintPaper
end sub

sub PrintPaper
PrintSimple("Brother MFC-240C USB Printer", 2)
end sub

sub PrintPDF
rem ----------------------------------------------------------------------
PrintSimple("PDFCreator", 1)
end sub


sub PrintSimple(printer, copies)
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Printer"
args1(0).Value = printer
dispatcher.executeDispatch(document, ".uno:Printer", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Copies"
args2(0).Value = copies
args2(1).Name = "Collate"
args2(1).Value = true
dispatcher.executeDispatch(document, ".uno:Print", "", 0, args2())
end sub
Comment 1 michael.ruess 2008-05-06 19:57:48 UTC
Reassigned to HI.
Comment 2 h.ilter 2008-05-07 13:45:47 UTC
HI->JSK: Please take a look, thanks.
Comment 3 hakre 2008-05-24 11:31:00 UTC
I think this is not related to macros infact, there is a crash deeper inside 
the code, maybe the code which handels what is done when the print finishes. 
Maybe this code does not handle properly the situation that other subsystems 
are still printing.

To my imagination that can be the code which handles the dialog in which a 
print can be canceled while ooo prints. I guess it because in this scenario, 
the prints are done quite simulatneosly but I would guess that OOO GUI only 
handles one print-cancel-dialog at a time or at least the code was designed 
with the circumstances assumed that there is only one print command at a time.

maybe there is some documentation sothat i can tell the macro to not display 
that kind of cancel dialog?
Comment 4 joerg.skottke 2008-05-26 06:55:08 UTC
I am unable to reproduce the problem. Can you try to ask your question on one of
the mailinglists? I'm quite certain there is a feasible solution for your issue.

Setting issue to "WorksForMe". Please note that you may reopen it at any time if
you feel this still is a bug.
Comment 5 joerg.skottke 2008-05-26 06:55:31 UTC
Close
Comment 6 hakre 2008-05-27 13:54:08 UTC
JSK, thanks for taking time to look into this. Since the problem still exists 
for me, what version of OOo and which OS did you use sothat it worked for you?
Comment 7 joerg.skottke 2008-05-27 14:55:58 UTC
Hi Hakre,

I used Windows XP SP2 (de) and OOH680m16 (That's a OOo 2.4.1, latest and
greatest). Your sample macro was copied into the BASIC IDE and with a sample
document (Writer, just some text) i executed your macro. No crash.
Comment 8 hakre 2008-06-09 10:05:42 UTC
I can not check against that version (i do not have it installed and I am not 
able to find a download of exact that version compiled for my system), it might 
be fixed in that version then.

That as well means for me that "CLOSED WORKSFORME" is wrong. The current status 
should reflect that it works for others in an unstable version only. I could 
wait for the 2.4.1 release to try it again then. So I reopen the Issue with 
COMMENT: Might be solved in 2.4.1
Comment 9 hakre 2008-06-09 10:06:48 UTC
Might be solved in 2.4.1 as reported by jsk.
Comment 10 hakre 2008-06-11 00:02:00 UTC
I finally was able to update to OOo 2.4.1 and check against it. In comparison 
to Version 2.4.0 this time OOo Document Recovery pops up (OpenOffice.org 
Dokumentenwiederherstellung). When running Document Recovery, OOo Crashes again.

So I can only confirm that exact Error again, this time with Version 2.4.1.

How To reproduce:

* Takeover the Code in the first comment
* Adopt the script to two existing printer names in your configuration
* Create a new toolbar
* Add a button to the new toolbar that represent the Macro "PrintJob"
* Save the new Toolbar
* Press the Button
* OOo Crashes
Comment 11 joerg.skottke 2008-06-17 09:13:43 UTC
Now i got it. Confirmed.
Comment 12 joerg.skottke 2008-06-17 09:19:33 UTC
Program received signal SIGSEGV, Segmentation fault.
0x00922215 in String::Erase ()
   from /opt/staroffice9/program/../basis-link/program/libtlli.so
(gdb) where
#0  0x00922215 in String::Erase ()
   from /opt/staroffice9/program/../basis-link/program/libtlli.so
#1  0x012086fe in ?? ()
   from /opt/staroffice9/program/../basis-link/program/libvclli.so
#2  0x011b86ed in ?? ()
   from /opt/staroffice9/program/../basis-link/program/libvclli.so
#3  0x011b88c8 in ?? ()
   from /opt/staroffice9/program/../basis-link/program/libvclli.so
#4  0x011645db in Timer::Timeout ()
   from /opt/staroffice9/program/../basis-link/program/libvclli.so
#5  0x01164207 in Timer::ImplTimerCallbackProc ()
   from /opt/staroffice9/program/../basis-link/program/libvclli.so
#6  0x01fb92bb in X11SalData::Timeout ()
   from /opt/openoffice.org/basis3.0/program/libvclplug_genli.so
#7  0x05f8e70b in ?? ()
   from /opt/openoffice.org/basis3.0/program/libvclplug_gtkli.so
#8  0xb7f6f558 in ?? ()
#9  0x0141bf80 in ?? ()
   from /opt/staroffice9/program/../basis-link/program/libvclli.so
#10 0x01f6f264 in ?? () from /lib/libglib-2.0.so.0
#11 0xbfccbbac in ?? ()
#12 0x085b98d8 in ?? ()
#13 0xbfccbb38 in ?? ()
---Type <return> to continue, or q <return> to quit---
#14 0x05f8e731 in ?? ()
   from /opt/openoffice.org/basis3.0/program/libvclplug_gtkli.so
#15 0xb7f90908 in ?? ()
#16 0xbfccbb68 in ?? ()
#17 0x01ec67c6 in ?? () from /lib/libglib-2.0.so.0
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
Comment 13 joerg.skottke 2008-06-17 09:20:56 UTC
Reproduction succeeded for both 2.4.1, 3.0 (m19) on Windows and Linux.
Comment 14 Stephan Bergmann 2008-06-17 09:46:48 UTC
@pl: please take over
Comment 15 philipp.lohmann 2008-06-24 15:07:48 UTC
pl->cd: The crash occurs because of the first printer being destroyed while a
print job is active; this is not allowed. The printer is destroyed by SwView
which tries to set a new printer. I talked to os and he told me that two print
jobs at the same time should not be possible; he thinks this should be prevented
in framework.
Comment 16 hakre 2008-06-24 19:20:12 UTC
for a generel maturity and in-depth stability I would like to see at least an 
exception here that can be catched.

on the scripting-level it would be great to have a kind of wait-until-finished 
command/flag or a stillPrinting Property or similar to circumvent the bug on 
the scripting side. Maybe like in this pseudo code:

dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Printer"
args1(0).Value = printer
args1(1).Name = "UIWait"
args1(1).Value = true
dispatcher.executeDispatch(document, ".uno:Printer", "", 0, args1())
dispatcher.waitForExecuteDispatchDone(document, ".uno:Printer")

I'm quite new to scripting OOo and I do not know, maybe there is a parameter to 
wait but I had problems to find those dispatching commands well documented even 
tough I'm quite tekky.
Comment 17 Mathias_Bauer 2008-07-08 17:27:55 UTC
code freeze missed, target adjusted
Comment 18 hakre 2008-12-29 16:29:06 UTC
Just some Feedback: Tested against OOo 3.0.0 OOO300m9 (Build:9358). Does still 
crash (should though I think if the freeze was missed).
Comment 19 Mathias_Bauer 2009-05-11 11:09:36 UTC
The right approach seems to be:

return Error in virtual method SfxViewShell::SetPrinter(), as this is the
"offending" code part. Not only a second print job, but every attempt to set a
new printer while the old one is printing, will leads to a crash.
In case of printing the error will be handled in SfxViewShell::DoPrint.

Interesting observation: via API this crash can't happen as setPrinter() waits
until printing on the current printer has finished. I prefer to let the call fail.

@akre: a "Wait" property exists already, so your suggested workaround can be
used. Unfortunately (and for historical reasons - as always ;-)) the parameters
differ for the dispatching and the "real" API:

Dispatching:

dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "PrinterName"
args1(0).Value = printer
args1(1).Name = "Asynchron"
args1(1).Value = false
dispatcher.executeDispatch(document, ".uno:Print", "", 0, args1())

Using XPrintable at the document:

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Name"
args1(0).Value = printer
doc.setPrinter( args1() )

dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Wait"
args2(0).Value = true
doc.print( args2() )
Comment 20 Mathias_Bauer 2009-05-11 12:52:54 UTC
Fixed in sfx2, sw, sc, sd, starmath.
Attempt to change printer or printer settings while a document is printing now
will be rejected.
Comment 21 hakre 2009-05-11 13:54:13 UTC
Thanks for looking into the Issue and fixing it at its root.

I just tested the workaround provide by mba and it works perfectly. Thanks for 
that, mba! You just made me smile. 
Comment 22 Mathias_Bauer 2009-05-11 18:04:59 UTC
I've made an interesting observation when I tried to re-queue a rejected
printing dispatch and I found out that the second call never arrived in my code. 

If two printing calls are dispatched the second call will be rejected already by
the dispatching implementation. The problem in the macro is that the Printer is
set in an own dispatch (instead of passing the printer name to the dispatch
call) and for the "uno:Printer" call the "busy" check is not executed.

So it seems that the fix we need is to guard a busy printer against that command
also and this should work with my fix.

Unfortunately this way a queuing is not possible, so the result of my fix will
be that the second print job is not done. So using the "Wait" parameter seems to
more than a workaround, it's the only way to get both jobs done.
Comment 23 Mathias_Bauer 2009-05-12 09:49:11 UTC
Duh, I was blind.

Of course it is easy to queue API requests, just remove the code that disables
printing commands in case of pending print jobs. Works fine and smooth now, with
my fix there is no reason to use the "Wait" property anymore. :-)
Comment 24 Mathias_Bauer 2009-09-01 11:41:25 UTC
@jsk: please verify
Comment 25 joerg.skottke 2009-09-11 07:02:09 UTC
2 pages, no crash. Verified.
Comment 26 joerg.skottke 2009-10-09 08:11:27 UTC
Close