Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception: Surface does not respond to 'getData' #305

Open
galexite opened this issue Aug 28, 2015 · 2 comments
Open

Exception: Surface does not respond to 'getData' #305

galexite opened this issue Aug 28, 2015 · 2 comments

Comments

@galexite
Copy link

When using the following code to resize an image so that I can use it in my program, I get the following error:

resizing main.png from 640x640 to 20x20

  Exception: Surface does not respond to 'getData'
  ---------
  Surface getData                      Image.io 26
  Image resizedTo                      art.io 2
  CLI doFile                           Z_CLI.io 140
  CLI run                              IoState_runCLI() 1

My code is:

i := Image open("main.png") resizedTo(20, 20)
@ghost
Copy link

ghost commented Jan 29, 2016

Might need a bit of help on this one...

Tracing backwards from George's error:

  • Image.io:26: outputSurface getData fails (does not respond to message)
  • Image.io:22: outputSurface is created by CairoImageSurface create
  • IoCairoImageSurface.c:84: creates a surface with IoCairoSurface_newWithRawSurface_, passing in a raw surface from cairo_image_surface_create
  • IoCairoSurface.c:78: IoCairoSurface_newWithRawSurface_ looks at the type of surface and sets variable initFunc to an appropriate function (e.g. IoCairoImageSurface_proto), presumably to create an appropriate subclass of the Cairo surface. However initFunc is not then used.

The result is (I think) that the return value of CairoImageSurface create is a CairoSurface but not a CairoImageSurface - and the former does not have a getData method.

Possibly in IoCairoSurface.c:96 the new surface should be created by calling initFunc rather than IOCLONE(IoState_protoWithId_(state, protoId))

I'm not sure.

@ghost
Copy link

ghost commented Feb 4, 2016

OK, I've got this diff bypassing IoCairoSurface_newWithRawSurface_, which I think is bust.

diff --git a/addons/Cairo/source/IoCairoImageSurface.c b/addons/Cairo/source/IoCairoImageSurface.c
index 5f16b8f..96f8b69 100644
--- a/addons/Cairo/source/IoCairoImageSurface.c
+++ b/addons/Cairo/source/IoCairoImageSurface.c
@@ -81,7 +81,10 @@ IoObject *IoCairoImageSurface_create(IoCairoImageSurface *self, IoObject *locals
        cairo_format_t format = (cairo_format_t)IoMessage_locals_intArgAt_(m, locals, 0);
        int w = IoMessage_locals_intArgAt_(m, locals, 1);
        int h = IoMessage_locals_intArgAt_(m, locals, 2);
-       return IoCairoSurface_newWithRawSurface_(IOSTATE, m, cairo_image_surface_create(format, w, h));
+       cairo_surface_t* surface = cairo_image_surface_create(format, w, h);
+       IoCairoImageSurface* created = IoObject_rawClonePrimitive(self);
+       IoObject_setDataPointer_(created, surface);
+       return created;
 }

 IoObject *IoCairoImageSurface_createForData(IoCairoImageSurface *self, IoObject *locals, IoMessage *m)

Q. is this the right way to create a clone of an ImageSurface?
With this code, George's code does work as it should, but:

  1. Doesn't fix the underlying issue with IoCairoSurface_newWithRawSurface_
  2. I also uncovered a bug in Image open() - it doesn't work with paletted PNG files.
    Onwards and upwards!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant