I was planning to do some persistence trickery by doing my drawing onto a RenderTexture, which is a nested struct...
|
package Raylib::FFI::RenderTexture { |
|
use FFI::Platypus::Record qw( record_layout_1 ); |
|
record_layout_1( |
|
$ffi, |
|
uint => 'id', |
|
opaque => 'texture', # cast to Texture |
|
opaque => 'depth', # cast to Texture |
|
); |
|
} |
|
$ffi->type( 'record(Raylib::FFI::RenderTexture)' => 'RenderTexture' ); |
|
$ffi->type( 'RenderTexture' => 'RenderTexture2D' ); |
...that is, its members are not struct pointers, which would be nice and handy, they are stuffed into this struct, so instantiating one (via LoadRenderTexture()) segfaults.
My next thought was to use a FFI::C::Struct, which does support nested structs, but FFI::C objects must be passed into C via FFI::Platypus by pointers - pass-by-value is not supported. Raylib uses pass-by-value.
I don't have any solid ideas to resolve this right now - if I did this would be a pull request. So...
Replace the opaques with a type big enough to hold the structs (getting this to align/cast right would be ... "challenging")?
- Bundle a slew of wrapper functions which do pass-by-reference for structs?
- Add nested struct support to record or pass-by-value support to FFI::C
- Look at other tech (Affix? or something called "XS"?)
I was planning to do some persistence trickery by doing my drawing onto a
RenderTexture, which is a nested struct...Raylib-FFI/lib/Raylib/FFI.pm
Lines 122 to 132 in 2022665
...that is, its members are not struct pointers, which would be nice and handy, they are stuffed into this struct, so instantiating one (via
LoadRenderTexture()) segfaults.My next thought was to use a
FFI::C::Struct, which does support nested structs, butFFI::Cobjects must be passed into C via FFI::Platypus by pointers - pass-by-value is not supported. Raylib uses pass-by-value.I don't have any solid ideas to resolve this right now - if I did this would be a pull request. So...
Replace theopaques with a type big enough to hold the structs (getting this to align/cast right would be ... "challenging")?