Mega Search
23.2 Million


Sign Up

Make a donation  
wxGTK 2.9.2 crash when printing  
News Group: comp.soft-sys.wxwindows

Hi,

I'm afraid there's a little bug when printing a richtext control, on
wxGTK.

Easy to reproduce :

I take the richtext sample,
go to File->Print
click Cancel on the print dialog

go back to File->Print   ==> Kaboom....


I get the following stack trace

ASSERT INFO:
../src/gtk/print.cpp(923): assert "Assert failure" failed in Print():
The print dialog returned an error.

BACKTRACE:
[1] wxOnAssert(char const*, int, char const*, char const*, wxString
const&)
[2] wxGtkPrinter::Print(wxWindow*, wxPrintout*, bool)
[3] wxPrinter::Print(wxWindow*, wxPrintout*, bool)
[4] wxRichTextPrinting::DoPrint(wxRichTextPrintout*)
[5] wxRichTextPrinting::PrintBuffer(wxRichTextBuffer const&)
[6] wxAppConsoleBase::CallEventHandler(wxEvtHandler*, wxEventFunctor&,
wxEvent&) cons)
[7] wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase
const&, wxEvtHandler*, wxEvent&)
[8] wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*)
[9] wxEvtHandler::TryHereOnly(wxEvent&)
[10] wxEvtHandler::ProcessEventLocally(wxEvent&)
[11] wxEvtHandler::ProcessEvent(wxEvent&)
[12] wxEvtHandler::SafelyProcessEvent(wxEvent&)
[13] wxMenuBase::SendEvent(int, int)
[14] menuitem_activate() menu.cpp
[15] g_cclosure_marshal_VOID__VOID()
[16] g_closure_invoke()
[17] g_signal_emit_valist()
[18] g_signal_emit()
[19] gtk_widget_activate()
[20] gtk_menu_shell_activate_item()
[21] g_closure_invoke()
[22] g_signal_emit_valist()
[23] g_signal_emit()
[24] gtk_propagate_event()
[25] gtk_main_do_event()
[26] g_main_context_dispatch()
[27] g_main_loop_run()
[28] gtk_main()

I'm using Ubuntu 10.04 running inside a Parallels Desktop VM.

Is it a bug or something wrong on my system ?

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 5-Oct-2011, at 11:04 AM EST
From: Buzz
 
Re: wxGTK 2.9.2 crash when printing  
News Group: comp.soft-sys.wxwindows
Hi,

First things first, beware that my C++ knowledge is rather basic, and
this GTK printing stuff looks pretty complex to me. So I'm not sure
the fix I propose will be the best one...

So, to sum up, it crashes on Linux, the second time you print a
document. Whether you've cancelled the first print or not.

This is the error :
Gtk-CRITICAL **: gtk_print_operation_run: assertion `op->priv->status
== GTK_PRINT_STATUS_INITIAL' failed

This is in gtk/print.cpp, following the call to
gtk_print_operation_run, on line 659 (from the official
wxWidgets-2.9.2 source).

gtk_print_operation_run takes GtkPrintOperation as one of its
parameters, and I have the feeling that the same GtkPrintOperation
instance cannot be used for multiple prints. The first time, it's OK,
but after that, GtkPrintOperation.status always gets the
GTK_PRINT_STATUS_FINISHED_ABORTED value, which causes the crash.

The only fix I could think of was to create a new GtkPrintOperation
instance after each print. But to avoid losing the page settings that
the user had entered during the first print (pages per side,
scale, ...), I created a little method inside of wxGtkPrintNativeData,
called RenewPrintJob(), that copies the necessary properties from the
old GtkPrintOperation into a new one.

That fixes the problem.


Among the things I still don't understand, I tried to free() the old
GtkPrintOperation, but this caused a crash, complaining that the
pointer was invalid... even though this pointer seemed OK to me...

Here's a diff between the official 2.9.2 gtk/print.cpp source, and the
modified one :

582a583,595
>
> // Replace the m_job property by a new instance of GtkPrintOperation,
> // preserving the settings from the previous print
> void wxGtkPrintNativeData::RenewPrintJob()
> {
>     GtkPrintOperation   *tmp = gtk_print_operation_new();
> 	gtk_print_operation_set_default_page_setup(tmp, gtk_print_operation_get_default_page_setup(m_job));
> 	gtk_print_operation_set_print_settings    (tmp, gtk_print_operation_get_print_settings    (m_job));
> //	delete m_job;
> 	m_job = tmp;
> }
>
>
657a671
>
662a677
> 	native->RenewPrintJob();


and the corresponding diff for the include/wx/gtk/print.h file:
199a200
> 	void RenewPrintJob();


Don't know if this will help ...  I guess someone with better
GtkPrinting knowledge will find a cleaner solution.
If you find a better fix, please let me know : I'd be curious to see
your way of doing ... :-)

Kind regards, Buzz.

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 10-Nov-2011, at 1:34 PM EST
From: Buzz
 
Re: wxGTK 2.9.2 crash when printing  
News Group: comp.soft-sys.wxwindows
> I tested printing from other applications, on the same virtual
> machine. I tried with Gedit end Eog, but it works fine there.

 So this is indeed a wxWidgets bug then...

> What do you mean by "the kind of error it returns" ?

 It wasn't clear to me which error exactly occurred, I understand it better
now.

> I just get a message box that says :
> ./src/gtk/print.cpp(923) : asset "Assert failure" failed in Print() :
> the print dialog returned an error.

 Does the dialog even appear on screen?

 Anyhow, I don't really know what's going on here, I'd suggest building a
debug version of wxWidgets and tracing inside wxGtkPrintDialog::ShowModal()
call which happens in print.cpp(915). Please let us know if you find
anything.

 Good luck,
VZ

-- 
TT-Solutions: wxWidgets consultancy and technical support
              http://www.tt-solutions.com/

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 2-Nov-2011, at 4:09 PM EST
From: Vadim Zeitlin
 
Re: wxGTK 2.9.2 crash when printing  
News Group: comp.soft-sys.wxwindows
On 7 oct, 16:29, Vadim Zeitlin  wrote:
> On 2011-10-05, Buzz  wrote:
>
>
>
>
>
>
>
>
>
> > I'm afraid there's a little bug when printing a richtext control, on
> > wxGTK.
>
> > Easy to reproduce :
>
> > I take the richtext sample,
> > go to File->Print
> > click Cancel on the print dialog
>
> > go back to File->Print   ==> Kaboom....
>
> > I get the following stack trace
>
> > ASSERT INFO:
> > ./src/gtk/print.cpp(923): assert "Assert failure" failed in Print():
> > The print dialog returned an error.
>
>  Could you please check what kind of error did it return?
>
> > Is it a bug or something wrong on my system ?
>
>  I think it's a bug but you should check whether printing works from other
> GTK applications on the same (virtual) system.
>
>  Regards,
> VZ
>
> --
> TT-Solutions: wxWidgets consultancy and technical support
>              http://www.tt-solutions.com/

Hi,

sorry for my late answer...

I tested printing from other applications, on the same virtual
machine. I tried with Gedit end Eog, but it works fine there.

What do you mean by "the kind of error it returns" ?

I just get a message box that says :
../src/gtk/print.cpp(923) : asset "Assert failure" failed in Print() :
the print dialog returned an error.

Kind regards,
Buzz.

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 1-Nov-2011, at 8:31 AM EST
From: Buzz
 
Re: wxGTK 2.9.2 crash when printing  
News Group: comp.soft-sys.wxwindows
On 2011-10-05, Buzz  wrote:
> I'm afraid there's a little bug when printing a richtext control, on
> wxGTK.
>
> Easy to reproduce :
>
> I take the richtext sample,
> go to File->Print
> click Cancel on the print dialog
>
> go back to File->Print   ==> Kaboom....
>
>
> I get the following stack trace
>
> ASSERT INFO:
> ./src/gtk/print.cpp(923): assert "Assert failure" failed in Print():
> The print dialog returned an error.

 Could you please check what kind of error did it return?

> Is it a bug or something wrong on my system ?

 I think it's a bug but you should check whether printing works from other
GTK applications on the same (virtual) system.

 Regards,
VZ

-- 
TT-Solutions: wxWidgets consultancy and technical support
              http://www.tt-solutions.com/

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 7-Oct-2011, at 3:29 PM EST
From: Vadim Zeitlin