wilsonsilva / raylib-ruby

Ruby bindings for raylib, a simple and easy-to-use library to enjoy videogames programming.
https://raylib-ruby.com
zlib License
18 stars 1 forks source link

Missing FFI functions #5

Open julik opened 5 months ago

julik commented 5 months ago

Hi! I've tried to play with the project a bit, but I don't manage to get the script to run. I get this error:

julik@jet <redacted> $ ruby window.rb 
/Users/julik/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ffi-1.17.0-x86_64-darwin/lib/ffi/library.rb:216:in `attach_function': Function 'DrawLineBezierQuad' not found in [libraylib.dylib] (FFI::NotFoundError)
    from /Users/julik/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/raylib-4.5.0.alpha1/lib/raylib/core/functions.rb:582:in `<module:Raylib>'
    from /Users/julik/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/raylib-4.5.0.alpha1/lib/raylib/core/functions.rb:1:in `<top (required)>'
    from <internal:/Users/julik/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
    from <internal:/Users/julik/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
    from /Users/julik/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/raylib-4.5.0.alpha1/lib/raylib/core.rb:5:in `<top (required)>'
    from <internal:/Users/julik/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
    from <internal:/Users/julik/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
    from /Users/julik/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/raylib-4.5.0.alpha1/lib/raylib.rb:12:in `<top (required)>'
    from <internal:/Users/julik/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:141:in `require'
    from <internal:/Users/julik/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:141:in `rescue in require'
    from <internal:/Users/julik/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:135:in `require'
    from window.rb:1:in `<main>

I've looked for the function in the raylib GH repo but it doesn't show anywhere. Could it be that the FFI bindings need to be regenerated from time to time?

Ruby is

julik@jet banksvc (main) $ ruby -v
ruby 3.3.1 (2024-04-23 revision c56cd86388) [x86_64-darwin21]

and this is macOS Monterey (10.12) and raylib is installed using brew (brew install raylib)

julik commented 5 months ago

After commenting a few function bindings (GenImageGradientV, GenImageGradientH, DrawLineBezierQuad and DrawLineBezierCubic) the script does start, but then quits with

julik@jet banksvc (main) $ ruby window.rb 
INFO: Initializing raylib 5.0
INFO: Platform backend: DESKTOP (GLFW)
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
INFO: DISPLAY: Device initialized successfully
INFO:     > Display size: 2560 x 1440
INFO:     > Screen size:  640 x 480
INFO:     > Render size:  640 x 480
INFO:     > Viewport offsets: 0, 0
INFO: GLAD: OpenGL extensions loaded successfully
INFO: GL: Supported extensions count: 46
INFO: GL: OpenGL device information:
INFO:     > Vendor:   ATI Technologies Inc.
INFO:     > Renderer: AMD Radeon HD - FirePro D700 OpenGL Engine
INFO:     > Version:  4.1 ATI-4.8.101
INFO:     > GLSL:     4.10
INFO: GL: VAO extension detected, VAO functions loaded successfully
INFO: GL: NPOT textures extension detected, full NPOT textures supported
INFO: GL: DXT compressed textures supported
INFO: PLATFORM: DESKTOP (GLFW): Initialized successfully
INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 1] Default texture loaded successfully
INFO: SHADER: [ID 1] Vertex shader compiled successfully
INFO: SHADER: [ID 2] Fragment shader compiled successfully
INFO: SHADER: [ID 3] Program shader loaded successfully
INFO: SHADER: [ID 3] Default shader loaded successfully
INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU)
INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU)
INFO: RLGL: Default OpenGL state initialized successfully
INFO: TEXTURE: [ID 2] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps)
INFO: FONT: Default font loaded successfully (224 glyphs)
[DEPRECATION] Struct layout is already defined for class Raylib::Vector2. Redefinition as in window.rb:9:in `initialize' will be disallowed in ffi-2.0.
/Users/julik/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ffi-1.17.0-x86_64-darwin/lib/ffi/types.rb:94:in `find_type': unable to resolve type '' (TypeError)

        raise TypeError, "unable to resolve type '#{name}'"
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    from /Users/julik/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ffi-1.17.0-x86_64-darwin/lib/ffi/library.rb:415:in `find_type'
    from /Users/julik/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ffi-1.17.0-x86_64-darwin/lib/ffi/struct.rb:278:in `find_type'
    from /Users/julik/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ffi-1.17.0-x86_64-darwin/lib/ffi/struct.rb:272:in `find_field_type'
    from /Users/julik/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ffi-1.17.0-x86_64-darwin/lib/ffi/struct.rb:312:in `array_layout'
    from /Users/julik/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/ffi-1.17.0-x86_64-darwin/lib/ffi/struct.rb:218:in `layout'
    from window.rb:9:in `initialize'
    from window.rb:9:in `new'
    from window.rb:9:in `<main>'

That is on the initialization of the Vector2. What version of raylib is actually supported with these bindings?

wilsonsilva commented 5 months ago

Hello @julik these bindings are for Raylib 4.5. They released version 5.0 about 6 months ago. I haven't looked into this yet, but can you try to install an earlier version of the native homebrew raylib package?

julik commented 5 months ago

It doesn't look like Homebrew has an older formula with a version, so I would have to install all the way from scratch (which is a bit terrifying) 😱 Is there a way to regen the bindings?

wilsonsilva commented 5 months ago

@julik, the link to the archive is still valid. Homebrew stores the formulas in a git repository, so there's surely a way to point your homebrew to an earlier version.

https://stackoverflow.com/questions/3987683/homebrew-install-specific-version-of-formula

Alternatively, you'll need to compile raylib from the source. With their Makefiles, you should't run into any issues.

Upgrading the bindings from Raylib v4.5 to v5.0 is not an easy task. There are a lot of dependencies. I'll need to check the validity of every function and manually test all examples. I'll do it someday.

In any case, thanks for bringing this to my attention! This explains why the project stopped getting stars. I'll update the documentation at some point and even implement a version check with troubleshooting instructions.