SerafimArts / ffi-sdl-ttf

SDL2 TTF FFI bindings for the PHP language
MIT License
2 stars 1 forks source link

C function 'TTF_RenderText_Solid', expecting 'struct SDL_Color', found 'struct SDL_Color' #1

Closed boonkerz closed 1 year ago

boonkerz commented 1 year ago

example does not work.

the ttf ffi part does not know what the structure of SDL_color is because its defined in SDL_pixels.h

SerafimArts commented 1 year ago

Thanks! Fixed in version 2.0.1

boonkerz commented 1 year ago

Does not work as expected, its not possible to set color properly because the sdl_color has to be: typedef struct SDL_Color { Uint8 r; Uint8 g; Uint8 b; Uint8 a; } SDL_Color;

SerafimArts commented 1 year ago

All types are located in the main SDL library. TTF provides only API (so as not to duplicate types from the main library):

$color = $sdl->new('SDL_Color');
$color->r = 42;
// ...

or

$color = $sdl->cast('SDL_Color', $ttf->new('SDL_Color'));
$color->r = 42;

// ...
boonkerz commented 1 year ago

All types are located in the main SDL library. TTF provides only API (so as not to duplicate types from the main library):

yea thats right

$color = $sdl->new('SDL_Color');
$color->r = 42;
// ...

when i assign this to the rendertext function it doesn't respect the color it is produce an random color. i think the color struct get lost.

or

$color = $sdl->cast('SDL_Color', $ttf->new('SDL_Color'));
$color->r = 42;
// ...

poduce an error

SerafimArts commented 1 year ago

poduce an error

Yes, you're right, I checked - it's really a mistake =(((

Didn't think about this case. Allocating a pointer and then converting it to a structure creates a SIGSEGV error in this case.

It looks like I can't make a "stub" just like that and I'll have to duplicate all types from the original SDL in TTF.

For now, the only option is to create types from the original SDL:

$color = $sdl->new('SDL_Color');
// etc...
SerafimArts commented 1 year ago

Please check now if everything is ok.

Since everything worked locally for me even without these fixes, I can’t check it myself)

boonkerz commented 1 year ago

yea works now sdl_color created by ttf

SerafimArts commented 1 year ago

Still, it is recommended to create all structures using SDL instead of TTF ;)

boonkerz commented 1 year ago

yea but it works only with sdl_color from ttf

SerafimArts commented 1 year ago

If it's not difficult, it would be nice to provide a code example to reproduce the problem, because the creation of all structures from the main SDL library is implied.