Bug 72864 - [PATCH] kghostview behaves erratically after opening a file -- sometimes shows blank pages
Summary: [PATCH] kghostview behaves erratically after opening a file -- sometimes show...
Status: RESOLVED WORKSFORME
Alias: None
Product: okular
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Okular developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-01-18 00:27 UTC by Andy Neitzke
Modified: 2012-10-15 05:21 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
test PS file which reliably exhibits this bug (527.56 KB, application/x-gzpostscript)
2004-01-18 00:29 UTC, Andy Neitzke
Details
workaround for problem with main viewer (2.43 KB, patch)
2004-01-19 06:29 UTC, Andy Neitzke
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Neitzke 2004-01-18 00:27:56 UTC
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.
Comment 1 Andy Neitzke 2004-01-18 00:29:36 UTC
Created attachment 4221 [details]
test PS file which reliably exhibits this bug
Comment 2 Andy Neitzke 2004-01-19 06:28:30 UTC
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.
Comment 3 Andy Neitzke 2004-01-19 06:29:15 UTC
Created attachment 4233 [details]
workaround for problem with main viewer
Comment 4 Luís Pedro Coelho 2004-01-20 03:26:56 UTC
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();


Comment 5 Andy Neitzke 2004-07-14 07:41:46 UTC
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.
Comment 6 Adrián Chaves (Gallaecio) 2012-10-15 05:21:31 UTC
This is not the case in Okular.