Version: 0.20 (using KDE 3.1.94 (CVS >= 20031206), Mandrake Linux Cooker i586 - Cooker) Compiler: gcc version 3.3.2 (Mandrake Linux 10.0 3.3.2-4mdk) OS: Linux (i686) release 2.6.0-1mdk The behavior of kghostview on my system after opening a PS file is rather erratic. 1. Sometimes the first page is displayed correctly and all page thumbnails appear correctly. 2. Sometimes all page thumbnails appear but the main viewer displays an empty page. (In this case I can get the main viewer to show the first page either by clicking the second page and then the first page again or by zooming in/out.) 3. Sometimes the main viewer displays the first page correctly but the page thumbnails are blank. (In this case the widget in the upper left corner actually displays a thumbnail of the _last_ page.) 4. Finally, sometimes both the main viewer and the page thumbnails are blank, in which case all the comments from cases 2 and 3 above apply. I can reproduce all these different behaviors just by opening a single file and then repeatedly hitting "File / Open Recent" on the same file. I'll attach one particular PS file which reliably exhibits this bug on my system.
Created attachment 4221 [details] test PS file which reliably exhibits this bug
I plunged into the code today. The problem with the main viewer turned out to be caused by the following. KPSWidget::gs_input(), which controls the parceling-out of data to GhostScript, is supposed to be called only when the KProcess _process is ready to accept some more data. The way this is enforced is that the KProcess emits a signal when it is ready, and that signal is connected to gs_input(), which then sends the data to the KProcess pointed to by the member variable _process. However, sometimes a stale KProcess can emit this signal although _process has been changed. On receipt of this signal gs_input() tries to send data to _process, which isn't yet ready to accept it, and the data gets lost. A workaround for this problem is to modify KPSWidget::gs_input() to KPSWidget::gs_input(KProcess *), which can then keep track of which KProcess sent the signal, and just do nothing if it was a KProcess other than _process. On my system this workaround fixes the problems with the main viewer, although I still very occasionally have problems with the thumbnails. A patch implementing this workaround will be attached.
Created attachment 4233 [details] workaround for problem with main viewer
Subject: kdegraphics/kghostview CVS commit by luis_pedro: Fixes bug 72864 by correctly identifying if it's our KProcess which is ready. Patch by Andy Neitzke. Thanks a lot. CCMAIL:72864-close@bugs.kde.org M +10 -4 kpswidget.cpp 1.138 M +1 -1 kpswidget.h 1.76 --- kdegraphics/kghostview/kpswidget.cpp #1.137:1.138 @@ -180,5 +180,5 @@ bool KPSWidget::sendPS( FILE* fp, unsign // Start processing the queue. if( _stdinReady ) - gs_input(); + gs_input(_process); return true; @@ -371,5 +371,5 @@ bool KPSWidget::startInterpreter() this, SLOT( gs_output( KProcess*, char*, int ) ) ); connect( _process, SIGNAL( wroteStdin( KProcess*) ), - this, SLOT( gs_input() ) ); + this, SLOT( gs_input( KProcess* ) ) ); kapp->flushX(); @@ -449,8 +449,14 @@ void KPSWidget::gs_output( KProcess*, ch } -void KPSWidget::gs_input() +void KPSWidget::gs_input( KProcess* process ) { kdDebug(4500) << "KPSWidget: gs_input" << endl; + if (process != _process) + { + kdDebug(4500) << "KPSWidget::gs_input(): process != _process" << endl; + return; + } + _stdinReady = true; const unsigned bufferSize = 8192; @@ -483,5 +489,5 @@ void KPSWidget::gs_input() _currentRecord->begin += bytesRead; _currentRecord->len -= bytesRead; - if( _process && _process->writeStdin( _inputBuffer, bytesRead ) ) + if( process && process->writeStdin( _inputBuffer, bytesRead ) ) _stdinReady = false; else --- kdegraphics/kghostview/kpswidget.h #1.75:1.76 @@ -197,5 +197,5 @@ protected: protected slots: - void gs_input(); + void gs_input( KProcess* ); void gs_output( KProcess*, char* buffer, int len ); void interpreterFailed();
This has been working for me since the patch was applied, but I just tried out 3.3 Beta 1 from the Onebase LiveCD and the misbehavior seems to be back -- I tried downloading a bunch of postscript/PDF files from arxiv.org, and every time, the first page appeared blank. In fact, the first page remained blank even after I went to the second page and back to the first. The thumbnails also appeared all blank, except for the thumbnail corresponding to the first page, which showed a thumbnail of the last page. This behavior seems similar to what was observed a while ago in this bug report, and it seems like it might have a similar origin, so I'm reopening this bug, but I could open a new one if that's preferable.
This is not the case in Okular.