Bug 3851

Summary: Calling cairo_image_surface_get_width/height() on the wrong type of surface
Product: cairo Reporter: Pat Beirne <patbeirneottawa>
Component: generalAssignee: Carl Worth <cworth>
Status: RESOLVED FIXED QA Contact: cairo-bugs mailing list <cairo-bugs>
Severity: normal    
Priority: high    
Version: 0.9.3   
Hardware: x86 (IA32)   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:

Description Pat Beirne 2005-07-23 12:33:58 UTC
In a -gtk or -xlib environment, if I call cairo_get_target() and then use that surface to call
get_image_surface_width/height(), I get silly numbers. Is this the correct way to determine
the screen drawing size?

I have sample code to demo this, along the lines of:



  // find out our surface size
  cairo_surface_t *cs = cairo_get_target(cr);
  int width = cairo_image_surface_get_width(cs);
  int height = cairo_image_surface_get_height(cs);
#if DEBUG
  printf("surface area w: %d, h:%d\n",width,height);
#endif
Comment 1 Pat Beirne 2005-07-24 01:39:05 UTC
*** Bug 3852 has been marked as a duplicate of this bug. ***
Comment 2 Pat Beirne 2005-07-24 03:57:09 UTC
*** Bug 3853 has been marked as a duplicate of this bug. ***
Comment 3 Owen Taylor 2005-07-29 03:07:09 UTC
It's definitely not legal code, but since we can catch it, it would be
nice to be at least optionally verbose about these types of mistakes.
Comment 4 Carl Worth 2005-07-29 03:33:07 UTC
[Copying from the mailing list discussion of the same issue:
http://lists.freedesktop.org/archives/cairo/2005-July/004544.html
]

Here's a simple patch that at the very least calls into _cairo_error
with CAIRO_STATUS_SURFACE_TYPE_MISMATCH as it should in this case, and
also returns 0 rather than garbage.

The remaining question is whether this error should also set
surface->status to CAIRO_STATUS_SURFACE_TYPE_MISMATCH to shut the
surface down.

That would be consistent with our error handling strategy of
shutdown-on-error, and it does have the advantage of doing something
to ensure the user can tell that _something_ is wrong. (After which
the debugging approach could be to break on _cairo_debug or enable
some print messages in _cairo_error that we don't have yet).

Suggestions?

Comment 5 Carl Worth 2005-07-29 03:34:30 UTC
Created attachment 3184 [details]
Strange painting in crack attack
Comment 6 Carl Worth 2005-08-19 10:57:36 UTC
date: 2005/07/28 17:47:40;  author: cworth;  state: Exp;  lines: +10 -0

        * src/cairo-image-surface.c: (cairo_image_surface_get_width),
        (cairo_image_surface_get_height): Fix to call _cairo_error and
        return 0 on surface-type mismatch.
Comment 7 Carl Worth 2005-08-22 17:14:24 UTC
Move bugs against "cvs" version to "0.9.3" so we can remove the "cvs" version.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.