Skip to content

Instantly share code, notes, and snippets.

@nawarian

nawarian/buggy.php Secret

Last active Mar 8, 2021
Embed
What would you like to do?
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