Skip to content

Instantly share code, notes, and snippets.

@nawarian
Last active March 8, 2021 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nawarian/319d363dacea2feebc409e5413d03887 to your computer and use it in GitHub Desktop.
Save nawarian/319d363dacea2feebc409e5413d03887 to your computer and use it in GitHub Desktop.
PHP FFI nested struct bug
<?php
$ffi = FFI::load(__DIR__ . '/raylib.h');
$camera = $ffi->new('Camera2D');
$ffi->InitWindow(800, 600, 'Nawarian');
while (!$ffi->WindowShouldClose()) {
$ffi->BeginDrawing();
$ffi->BeginMode2D($camera);
$ffi->EndMode2D();
$ffi->EndDrawing();
}
$ffi->CloseWindow();
// .dylib is specific to MacOS, please replace with a .so or .dll if necessary
#define FFI_LIB "libraylib.dylib"
typedef struct Vector2 {
float x;
float y;
} Vector2;
typedef struct Camera2D {
Vector2 offset;
Vector2 target;
float rotation;
float zoom;
} Camera2D;
void InitWindow(int width, int height, const char *title);
bool WindowShouldClose(void);
void CloseWindow(void);
void BeginDrawing(void);
void EndDrawing(void);
void BeginMode2D(Camera2D camera); // <---- Buggy function
void EndMode2D(void);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment