Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 552568

Summary: Eclipse crashes with reference count error message cairo_surface_destroy
Product: [Modeling] GMF-Runtime Reporter: Ansgar Radermacher <ansgar.radermacher>
Component: GeneralAssignee: Project Inbox <gmf-runtime-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: matteo.morelli, pierre-charles.david, quentin.lemenez
Version: unspecified   
Target Milestone: 1.12.2   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/151797
https://bugs.eclipse.org/bugs/show_bug.cgi?id=544501
https://git.eclipse.org/c/gmf-runtime/org.eclipse.gmf-runtime.git/commit/?id=a3935f26991d49d0996b976f3d087cc0c94cb0a6
Whiteboard:

Description Ansgar Radermacher CLA 2019-10-30 11:10:50 EDT
In more complex diagrams with SVG shapes, Eclipse sometimes crashes with the error message.
cairo-surface.c:955: cairo_surface_destroy: Assertion  `CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)' failed.

This error has been reported in the context of SWT earlier (see bug 544501), but is probably a GMF-runtime issue.
The class RenderHelper from GMF creates new images via getSWTImage in a rendering thread. The code of this method shown below disposes an eventual existing image - this could only happen, if another thread calls getSWTImage on the same image at the same time - in this case "dispose" could be called twice.

in oe.gmf.runtime.draw2d.ui.render.internal.AbstractRenderedImage:

final public Image getSWTImage() {
    if (img != null)
        return img;

    Image image = renderImage();   [calls SVGImage.renderImage in our case]
    if (img != null && !img.isDisposed()) {
        img.dispose();
     }
     img = image;
     return img;
}

The issue does not happen any more, if the method getSWTImage is tagged as "synchronized" (in this case the 2nd (img != null) check and eventual removal can be removed, as img is always null).
Comment 1 Eclipse Genie CLA 2019-10-30 11:21:49 EDT
New Gerrit change created: https://git.eclipse.org/r/151797
Comment 3 Pierre-Charles David CLA 2019-11-06 02:45:11 EST
A build with the patch merged is available at https://download.eclipse.org/modeling/gmp/gmf-runtime/updates/milestones/S201911050758/

I could reproduce the bug on Papyrus Robotics (without your patch), but given how the product is structured I could not install/update the patched GMF Runtime in it to verify the fix, so I'll let you validate.

For some reason I could not trigger the bug with a Sirius diagram with several SVGs. Given that it is cause by subtle thread scheduling issues maybe we do something in a slightly different way that make it impossible in our case (or just less likely).
Comment 4 Ansgar Radermacher CLA 2019-11-06 05:13:26 EST
Hi,

I can't reproduce the exception any more, after installing the integration build. Thanks.

Ansgar