After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 168582 - Application crashes when dragging the jpeg quality slider
Application crashes when dragging the jpeg quality slider
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: General
2.2.x
Other All
: Normal critical
: 2.2
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2005-02-26 12:57 UTC by Bas Kok
Modified: 2008-01-15 12:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch for plug-ins/jpeg/jpeg-save.c and jpeg.c (2.24 KB, patch)
2005-03-20 21:34 UTC, weskaggs
none Details | Review
remove the floating selection with the layer it belongs to (1.06 KB, patch)
2005-03-23 19:06 UTC, Sven Neumann
needs-work Details | Review
Different patch to fix the problem (1.33 KB, patch)
2005-03-24 21:49 UTC, Michael Natterer
none Details | Review
revised patch (3.22 KB, patch)
2005-03-30 00:01 UTC, Sven Neumann
committed Details | Review

Description Bas Kok 2005-02-26 12:57:52 UTC
Steps to reproduce:
1. Open some jpeg image in GIMP
2. Edit it a bit (anything will do)
3. choose "Save as" from the menu
4. enter some name in the Name field of the "Save Image" dialog
5. press the save button
6. The "save as JPEG" dialog pops up
7. mark "Show previes in image window"
8. Now: select a rectangular region on the image
9. move this selection a bit
10. Drag the "Quality" slider of the "Save as JPEG" dialog

GIMP crashes!

Stack trace:


Other information:
Comment 1 Sven Neumann 2005-02-26 14:29:13 UTC
Doesn't crash here (but gives tons of warnings). Well, manipulating the layer
that says "JPEG preview" is of course asking for trouble.
Comment 2 weskaggs 2005-02-27 20:49:15 UTC
It isn't clear to me what GIMP ought to do in this situation.  The best thing
would be to somehow mark the preview "read only" so that the situation doesn't
arise, but there isn't currently a way to do that.  Should GIMP then silently
undo whatever the user has done to the preview, or what?
Comment 3 Sven Neumann 2005-02-27 23:17:02 UTC
Well, it definitely must not crash. So the first step is to find out what
exactly the problem is. Running gimp in gdb with --g-fatal-warnings should be
good start.
Comment 4 weskaggs 2005-02-28 17:39:14 UTC
Well, doing so basically just tells us that the image is corrupt.  And that's
not so surprising:  the jpeg plug-in, in updating the preview in this situation,
is removing a layer and then creating a new layer in an image that has a
floating selection.
Comment 5 weskaggs 2005-03-11 00:31:02 UTC
Here's a thought:  the jpeg plug-in could mark the image as "clean" after
creating a preview, and then, when trying to update the preview, bail out if the
image has become "dirty" in the meantime.
Comment 6 weskaggs 2005-03-20 21:33:25 UTC
Here is a patch implementing the idea suggested above -- this is not ready to
apply, and is presented more to give the idea.  At the very least there must be
a better way to bail out than simply calling exit, but from a callback I don't
know how to do it.  I switched from freeze-thaw to an undo group for two
reasons:  first, if it is necessary to bail out, an undo can then remove any
cruft that has gotten into the image during the save process.  Second, the
approach taken here will leave the image marked clean even if the user cancels
or saves a copy. Doing this right would ultimately involve having to implement
gimp_image_undo() in the pdb.
Comment 7 weskaggs 2005-03-20 21:34:15 UTC
Created attachment 38982 [details] [review]
patch for plug-ins/jpeg/jpeg-save.c and jpeg.c
Comment 8 Sven Neumann 2005-03-21 19:54:18 UTC
w/o looking at your patch: the preferred way to abort a plug-in is to call
gimp_quit() instead of exit().
Comment 9 weskaggs 2005-03-21 21:08:36 UTC
Thank you.  But I am really asking for an opinion on the acceptability of an
approach that involves (when previewing in-image for a non-exported image):

1) Starting an undo group when the preview is generated.
2) Marking the image as clean after generating a preview.
3) Checking whether the image has become dirty when updating the preview, and if
so, aborting the save.
4) Either on success or abort, when finished, closing the undo group and undoing.

This is the only way I see to prevent the user doing things that can cause GIMP
to crash (other than dropping the ability to preview in-image).
Comment 10 Sven Neumann 2005-03-23 18:21:10 UTC
Bill, I don't understand your approach. We haven't even figured out yet where
the problem is. How can we discuss a solution then?
Comment 11 Sven Neumann 2005-03-23 18:26:09 UTC
As a start, here's a stack trace of the crash:

Program received signal SIGSEGV, Segmentation fault.

Thread 1083470624 (LWP 29332)

  • #0 g_type_check_instance_cast
    from /usr/lib/libgobject-2.0.so.0
  • #1 floating_sel_restore
    at gimplayer-floating-sel.c line 332
  • #2 floating_sel_composite
    at gimplayer-floating-sel.c line 435
  • #3 gimp_projection_construct_layers
    at gimpprojection-construct.c line 197
  • #4 gimp_projection_construct
    at gimpprojection-construct.c line 172
  • #5 gimp_projection_validate_tile
    at gimpprojection.c line 677
  • #6 tile_manager_validate
    at tile-manager.c line 304
  • #7 tile_lock
    at tile.c line 157
  • #8 tile_manager_get
    at tile-manager.c line 269
  • #9 render_image_tile_fault
    at gimpdisplayshell-render.c line 950
  • #10 render_image_rgb_a
    at gimpdisplayshell-render.c line 797
  • #11 gimp_display_shell_render
    at gimpdisplayshell-render.c line 348
  • #12 gimp_display_shell_draw_area
    at gimpdisplayshell-draw.c line 514
  • #13 gimp_display_shell_canvas_expose
    at gimpdisplayshell-callbacks.c line 401
  • #14 _gtk_marshal_BOOLEAN__BOXED
    from /usr/lib/libgtk-x11-2.0.so.0
  • #15 g_closure_invoke
    from /usr/lib/libgobject-2.0.so.0
  • #16 g_signal_emit_by_name
    from /usr/lib/libgobject-2.0.so.0
  • #17 g_signal_emit_valist
    from /usr/lib/libgobject-2.0.so.0
  • #18 g_signal_emit
    from /usr/lib/libgobject-2.0.so.0
  • #19 gtk_widget_send_expose
    from /usr/lib/libgtk-x11-2.0.so.0
  • #20 gtk_main_do_event
    from /usr/lib/libgtk-x11-2.0.so.0
  • #21 gdk_window_clear_area_e
    from /usr/lib/libgdk-x11-2.0.so.0
  • #22 gdk_window_process_all_updates
    from /usr/lib/libgdk-x11-2.0.so.0
  • #23 gdk_window_clear_area_e
    from /usr/lib/libgdk-x11-2.0.so.0
  • #24 g_child_watch_add
    from /usr/lib/libglib-2.0.so.0
  • #25 g_main_depth
    from /usr/lib/libglib-2.0.so.0
  • #26 g_main_context_dispatch
    from /usr/lib/libglib-2.0.so.0
  • #27 g_main_context_dispatch
    from /usr/lib/libglib-2.0.so.0
  • #28 g_main_loop_run
    from /usr/lib/libglib-2.0.so.0
  • #29 plug_in_run
    at plug-in-run.c line 174

Comment 12 Sven Neumann 2005-03-23 18:41:51 UTC
It appears that the problem is that we have a floating selection that has a
pointer to a layer which doesn't exist any longer. This is something that must
not happen and needs to be fixed in GIMP, not in the JPEG plug-in. I suggest
that when a layer is removed from an image, that the associated floating
selection is removed as well.
Comment 13 Sven Neumann 2005-03-23 19:06:27 UTC
Created attachment 39145 [details] [review]
remove the floating selection with the layer it belongs to

This change seems to fix it but I don't have the time right now to study it in
all detail. Attaching it here so that it doesn't get lost ...
Comment 14 Michael Natterer 2005-03-23 21:19:06 UTC
The patch should use gimp_drawable_has_floating_sel() and this
should be done whenever removing a layer, channel or layer mask.
Comment 15 Michael Natterer 2005-03-23 21:21:05 UTC
Oh, and it should put the stuff into an undo group.
Comment 16 weskaggs 2005-03-23 22:26:24 UTC
Note that part of the problem here is that the jpeg plug-in freezes undo when
generating previews.  There are a couple of reasons why it needs to do this: 
(1) it shouldn't change the dirtyness state of the image, and (2) it shouldn't
leave the undo stack altered.  A solution would require at least making
gimp_image_undo available in the pdb.

But really the basis of my proposed "fix" is that there's no way to win if you
allow the user to manipulate the image while the plug-in is using it to hold
previews.  If you freeze undo, then the user's changes will permanently mess up
the undo history.  If you work inside an undo group and undo it after the save
is finished, then you are undoing the changes that the user has made.  So the
only viable approach, as far as I can see, is to prevent the problem from
arising in the first place, by bailing out if the user alters the image while it
contains a plugin-generated preview.
Comment 17 Sven Neumann 2005-03-24 12:28:46 UTC
There's no point of fixing this in a plug-in. The problem is in the core and
needs to be fixed there. A plug-in must not be able to crash gimp nor to mess up
the undo stack.
Comment 18 Sven Neumann 2005-03-24 13:21:30 UTC
More generally, the problem here is lack of drawable locking and the lack of an
API that would allow plug-ins to use the image window for their preview needs.
None of this can be fixed in the JPEG plug-in.
Comment 19 weskaggs 2005-03-24 17:04:11 UTC
Well, with gimp_image_undo_disable and gimp_image_undo_freeze available in the
pdb, there is no way to prevent a malicious plug-in from messing up the undo
system if it wants to.

I completely agree with comment #18.
Comment 20 Sven Neumann 2005-03-24 21:05:02 UTC
Bill, there is a way. We can clean up after the plug-in exits and make sure that
the stack isn't left with open undo groups and/or frozen. We already do that for
contexts and pop contexts if the plug-in failed to do that. Of course the
plug-in can trash the undo stack by calling gimp_image_undo_disable() but that
will still leave the undo stack in a consistent state.
Comment 21 Michael Natterer 2005-03-24 21:49:02 UTC
Created attachment 39222 [details] [review]
Different patch to fix the problem

This patch tries to avoid possible side effects by removing the
floating selection in the same order as if it was a separately
called operation.
Comment 22 Sven Neumann 2005-03-30 00:01:26 UTC
Created attachment 39412 [details] [review]
revised patch

This is a successor of mitch's patch. This one actually compiles and also
handles floating selections on channels. It doesn't handle removal of layer
masks with attached floating selection yet but it should be sufficient for the
2.2 branch.
Comment 23 Sven Neumann 2005-04-04 23:16:03 UTC
Applied to both branches, closing as FIXED:

2005-04-05  Sven Neumann  <sven@gimp.org>

	* app/core/core-enums.[ch]
	* app/core/gimpimage.c
	(gimp_image_remove_layer, gimp_image_remove_channel): handle a
	floating selection attached to the layer or channel that is being
	removed.  Fixes bug #168582 but doesn't handle floating selections
	attached to layer masks.