Bug 3851 - Calling cairo_image_surface_get_width/height() on the wrong type of surface
Summary: Calling cairo_image_surface_get_width/height() on the wrong type of surface
Status: RESOLVED FIXED
Alias: None
Product: cairo
Classification: Unclassified
Component: general (show other bugs)
Version: 0.9.3
Hardware: x86 (IA32) Linux (All)
: high normal
Assignee: Carl Worth
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
: 3852 3853 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-07-23 12:33 UTC by Pat Beirne
Modified: 2005-08-22 00:14 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

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.