GNOME Bugzilla – Bug 778052
SDL.PixelFormat class cannot be instantiated
Last modified: 2017-02-14 08:39:41 UTC
Created attachment 344750 [details] [review] Suggested Patch Basically the same problem as with #669279 just with another class. PixelFormat and Palette are simple structs that cannot be mapped to classes, see suggested patch. At the moment the component is not usable!
sdl.vapi is not SDL2 What you want to test and use is this: https://git.gnome.org/browse/vala-extra-vapis/tree/sdl2.vapi#n1701
I'm totally talking about SDL1: https://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlpixelformat.html Just try to compile the following program using vanilla Vala: using SDL; public class SDLTest { static int main(string[] args) { PixelFormat pf = new PixelFormat(); return 0; } } It won't work because PixelFormat has no constructor (and is not even a compact class).
Sorry, I see, your "patch" didn't show much experience which is why I made this conclusion. Afaics creating a PixelFormat that way is not supported at all? The structure simply serves the purpose to access this information of the corresponding Surface. So defining it as compact class seems appropriate. Of course the PixelFormat.*mask fields are wrongly typed. I personally have no experience with the SDL API though.
I actually noticed that there is a problem when trying to use Surface.convert(). You need to instantiate a PixelFormat to pass it as a parameter which is not possible at the moment. Regarding my suggested solution, I just did the same as you did with the AudioSpec structure in #669279, because it is exactly the same situation: The structure is not only needed to access information but also to pass it to some functions. I don't know how to avoid properly the pointer to the Palette class/struct in PixelFormat class/struct. Concerning my experience writing vapi files you are right, it is rather tinkering than really knowing
Created attachment 344924 [details] [review] sdl: Make Palette and PixelFormat a struct
Could you provide a more complex/real-life test-case of the API in question here?
Okay, something like that shout be quite close to real-life usage: using SDL; public class SDLTest { static int main(string[] args) { Surface s = new Surface.RGB(0, 10, 10, 32, 0, 0xff, 0xff00, 0xff0000); PixelFormat pf = PixelFormat(); s.convert(pf, 0); stdout.printf("%d", s.format.palette.colors[0].r); return 0; } } It uses Surface.convert() (where I noticed the problem) and then it tries to access the PixelFormat structure as it worked before.
Attachment 344924 [details] pushed as 343bafe - sdl: Make Palette and PixelFormat a struct