bugGNU Octave - Bugs: bug #44387, unwind_protect_cleanup apparently...

 
 

bug #44387: unwind_protect_cleanup apparently fails to run when calling graphics C++ code

Submitter:  Dan Sebald <sebald>
Submitted:  Sat 28 Feb 2015 04:45:37 AM UTC
   
 
Category:  Plotting with OpenGL Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Other
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 31 Jan 2017 05:17:35 PM UTC, comment #13: 

Leaving bug #50198 as the definitive issue report for cross-thread error problems.  CLosing this report.

Rik <rik5>
Group administrator
Tue 31 Jan 2017 04:29:55 PM UTC, comment #12: 

Unknown devices are now handled differently and this bug can't be reproduced anymore. Should we close it as "fixed" even if the root cause is still not fixed (see bug #50198)?

Pantxo Diribarne <pantxo>
Group Member
Fri 07 Oct 2016 11:28:17 PM UTC, comment #11: 

For FLTK --no-gui flag, I now get pretty much the same as what you report, except perhaps you have more error messages.

Good hypothesis on your part.  I've recompile with this change:


                if (nwrite != nread)
                  {
//                    octave::signal_handler ();   // Clear SIGPIPE signal
//                    error ("gl2ps_renderer::draw: internal pipe error");
                  }


and the segfault is gone:


>> print -dfoo tst.eps
Unknown device: foo
Unrecoverable error: undefined in .uninstallpagedevice
Operand stack:
    defaultdevice
warning: broken pipe
>>


So, I recompile again with just this change:


                if (nwrite != nread)
                  {
//                    octave::signal_handler ();   // Clear SIGPIPE signal
                    error ("gl2ps_renderer::draw: internal pipe error");
                  }


and get segfault again.  With this change


                if (nwrite != nread)
                  {
                    octave::signal_handler ();   // Clear SIGPIPE signal
//                    error ("gl2ps_renderer::draw: internal pipe error");
                  }


I see "warning: broken pipe" a hundred plus times.  That seems backward to me, but it's beside the point.  The call to error() is the problem, as you surmised.

Dan Sebald <sebald>
Fri 07 Oct 2016 10:42:51 PM UTC, comment #10: 

The test code now works for me if I use the cli version of Octave and fltk (no qt).

The issue seems to have changed.  The problem now is that throwing an error when there are multiple threads (interpreter thread and qt thread) seems to cause a segfault.  This may be because the thrown error is captured by the wrong thread which does not have an error handler set up.

The message when using FLTK is


print -dfoo tst.eps
Unknown device: foo
sfopen: gs_parse_file_name failed.
sfopen: gs_parse_file_name failed.
  ./base/gsicc_manage.c:1084: gsicc_open_search(): Could not find default_gray.icc
| ./base/gsicc_manage.c:1690: gsicc_set_device_profile(): cannot find device profile
Unrecoverable error: unknownerror in .special_op
Operand stack:
    defaultdevice
Unrecoverable error: undefined in .uninstallpagedevice
Operand stack:
    defaultdevice
warning: broken pipe
error: gl2ps_renderer::draw: internal pipe error
error: called from
    __opengl_print__ at line 169 column 7
    print at line 503 column 14


versus this when using qt.


print -dfoo tst.eps
Unknown device: foo
sfopen: gs_parse_file_name failed.
sfopen: gs_parse_file_name failed.
  ./base/gsicc_manage.c:1084: gsicc_open_search(): Could not find default_gray.icc
| ./base/gsicc_manage.c:1690: gsicc_set_device_profile(): cannot find device profile
Unrecoverable error: unknownerror in .special_op
Operand stack:
    defaultdevice
Unrecoverable error: undefined in .uninstallpagedevice
Operand stack:
    defaultdevice
warning: broken pipe
error: gl2ps_renderer::draw: internal pipe error
terminate called after throwing an instance of 'octave::execution_exception'
panic: Aborted -- stopping myself...
attempting to save variables to 'octave-workspace'...
save to 'octave-workspace' complete
Abort



Rik <rik5>
Group administrator
Sat 04 Apr 2015 10:43:52 AM UTC, comment #9: 

Now I think about it, I have overlooked the mutex mechanism: the construct in the diff I provided doesn't ensure that "Canvas::print" will have locked the mutex before Fdrawnow tries to. 
So this is not the proper way to ensure sequential operation across threads. It only ensures that "Canvas::print" will have to be completed before it is called again.

Pantxo Diribarne <pantxo>
Group Member
Sat 04 Apr 2015 10:21:13 AM UTC, comment #8: 

As explained in bug #44463, I could check that the gh_manager::lock/unlock mechanism doesn't seem to work. As I understand it should work as a cross thread mutex.

I attached a diff in which I tried to follow who lock and unlock the gh_manager: I don't know if I should trust the order in which the callers are printed on screen (due to possible threading issues) but here is the result I see in the terminal when I paste Rick's script:


>> close all
>> surf (peaks)
>> get (gcf, "color")
ans =

   1   1   1

>> print -dfoo tst.eps
drawnow unlocked the mutex
drawnow locked the mutex
>> get Canvas::print locked the mutex
Unknown device: foo
Unrecoverable error: undefined in .uninstallpagedevice
Operand stack:
    defaultdevice
              Canvas::print unlocked the mutex


In normal operation I would expected something like:


>> print -dfoo tst.eps
drawnow unlocked the mutex
Canvas::print locked the mutex
Canvas::print unlocked the mutex
drawnow locked the mutex
>>



(file #33531)

Pantxo Diribarne <pantxo>
Group Member
Mon 30 Mar 2015 04:30:58 PM UTC, comment #7: 

Still reproducible for me.  This is on Linux Mint 13 at cset 19995:185e8dbdaa40.  Maybe try running with the '-f' switch to make sure there isn't anything in your .octaverc which might influence the result.


./run-octave -f
close all
surf (peaks)
get (gcf, "color")
print -dfoo tst.eps
get (gcf, "color")



Rik <rik5>
Group administrator
Sat 28 Mar 2015 11:05:53 AM UTC, comment #6: 

I can't reproduce the error in comment #5: for me the figure color is reset to its original value. This is with a recent dev build on linux mint. Can some confirm that this bug is still present?

Pantxo Diribarne <pantxo>
Group Member
Tue 03 Mar 2015 09:05:11 PM UTC, comment #5: 

Here is a sample piece of code that illustrates the problem


octave:30> close all
octave:31> surf (peaks)
octave:32> get (gcf, "color")
ans =

   1   1   1

octave:33> print -dfoo tst.eps
Unknown device: foo
Unrecoverable error: undefined in .uninstallpagedevice
Operand stack:
    defaultdevice
warning: broken pipe

octave:33> get (gcf, "color")
ans = none


So it is clear that when an error occurs we are not restoring the plot to its original state.  This is probably because error() short-circuits running the normal end-of-print routines.

It probably means we need to have any code that might fail in a try/catch block or in an unwind_protect statement so that errors are cleaned up afterwards.

Actually, check out print.m.


    ## Set figure background to none.
    ## This is done both for consistency with Matlab and to eliminate
    ## the visible box along the figure's perimeter.
    props(3).h = opts.figure;
    props(3).name = "color";
    props(3).value{1} = get (props(3).h, props(3).name);
    set (props(3).h, "color", "none");


This is in an unwind_protect statement.  So, maybe there is some reason why the restore code is not working.

In fact, I just did a bunch of insertions of printf statements into print.m and lots of them do not seem to be executed after I use a function which calls into the C++ graphics code such as ishandle() or set().

Rik <rik5>
Group administrator
Tue 03 Mar 2015 07:20:51 PM UTC, comment #4: 

Here's a related example from https://savannah.gnu.org/bugs/?44406#comment6, but it isn't bogus device, instead typing Cntrl-C while the printing is taking place.

Dan Sebald <sebald>
Sun 01 Mar 2015 06:09:11 PM UTC, comment #3: 

https://savannah.gnu.org/bugs/?44400 is unrelated to this bug.

Dan Sebald <sebald>
Sun 01 Mar 2015 04:09:59 PM UTC, comment #2: 

I posted another bug #44400 that may be related to this one.

Pantxo Diribarne <pantxo>
Group Member
Sat 28 Feb 2015 05:21:38 AM UTC, comment #1: 

That's the new Qt toolkit running in the CLI.  It's a day or two old in Mercurial so I'm sure there are new issues with it.

Rik <rik5>
Group administrator
Sat 28 Feb 2015 04:45:37 AM UTC, original submission:  

When a print is done when FLTK graphics toolkit is operating, I notice that the background of the plot will go haywire momentarily.  I think if an error happens to occur while FLTK window is in that state, the window stays in that state.  I've attached an example plot window after running the following:


[sebald@ ~]$ [build directory]/run-octave --no-gui
GNU Octave, version 3.9.1+
[snip]
octave:1> print -dfoo tst.eps
error: print: no figure to print
error: called from
    print at line 301 column 5
octave:1> surf (peaks)
octave:2> print -dfoo tst.eps
Unknown device: foo
Unrecoverable error: undefined in .uninstallpagedevice
Operand stack:
    defaultdevice
warning: broken pipe

octave:2>


Dan Sebald <sebald>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #33531:  gh_manager_lock.diff added by pantxo (2KiB - application/x-download)
file #33207:  Screenshot-Figure 1.png added by sebald (71KiB - image/png)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by sebald (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-01-31 rik5 Open/ClosedOpen Closed
    2015-04-04 pantxo Attached File- Added gh_manager_lock.diff, #33531
    2015-03-03 rik5 SummaryQt left in bad state when printing with bogus device unwind_protect_cleanup apparently fails to run when calling graphics C++ code
    2015-03-03 rik5 StatusNone Confirmed
    2015-02-28 rik5 SummaryFLTK left in bad state when printing with bogus device Qt left in bad state when printing with bogus device
    2015-02-28 sebald Attached File- Added Screenshot-Figure 1.png, #33207

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code