hugopl / gtk4.cr

GTK4 bindings for Crystal
https://hugopl.github.io/gtk4.cr/
MIT License
102 stars 8 forks source link

Error with ./gsk-4.0/path_point.cr #58

Open xenanthropy opened 1 year ago

xenanthropy commented 1 year ago

Edit: I realize this is most likely an issue with gi-crystal, but I'll leave the issue here as it also affects this repo as well

after cloning the repo and running shards install, running ./bin/gi-crystal gives the following output:

info - Starting at 2023-10-21 23:09:45 -05:00, project dir: /home/conner/git-projects/gtk4.cr
info - Gi-Crystal version 0.19.0, built with Crystal 1.9.2.
info - Generating bindings at /home/conner/git-projects/gtk4.cr/lib/gi-crystal/src/auto
info - Using binding config at /home/conner/git-projects/gtk4.cr/src/bindings/gdk/binding.yml
info - Using binding config at /home/conner/git-projects/gtk4.cr/src/bindings/gsk/binding.yml
info - Using binding config at /home/conner/git-projects/gtk4.cr/src/bindings/gtk/binding.yml
info - Using binding config at /home/conner/git-projects/gtk4.cr/lib/gi-crystal/src/bindings/g_lib
/binding.yml
info - Using binding config at /home/conner/git-projects/gtk4.cr/lib/gi-crystal/src/bindings/g_obj
ect/binding.yml
info - Using binding config at /home/conner/git-projects/gtk4.cr/lib/harfbuzz/src/bindings/harfbuz
z/binding.yml
info - Using binding config at /home/conner/git-projects/gtk4.cr/lib/gio/src/bindings/gio/binding.
yml
info - Using binding config at /home/conner/git-projects/gtk4.cr/lib/pango/src/bindings/pango/bind
ing.yml
info - Gdk - No binding config found for cairo-1.0.
info - Gdk - No binding config found for PangoCairo-1.0.
info - Gdk - No binding config found for GdkPixbuf-2.0.
warn - Gdk::TimeCoord axes field - Unknown conversion to crystal for fixed size array.
info - HarfBuzz - No binding config found for freetype2-2.0.
warn - HarfBuzz - Interface constant not supported.
warn - g_cancellable_connect - Callback without user_data!
warn - Gio::ActionEntry padding field - Unknown conversion to crystal for fixed size array.
warn - Gio::DBusInterfaceVTable padding field - Unknown conversion to crystal for fixed size array
.
warn - Gio::DBusSubtreeVTable padding field - Unknown conversion to crystal for fixed size array.
info - GdkPixbuf - No binding config found for GModule-2.0.
warn - gdk_pixbuf_get_options - Unknown conversion to crystal for GHash
info - Gsk - No binding config found for Graphene-1.0.
warn - gsk_border_node_get_widths - Unknown conversion to crystal for fixed size array.
warn - Boxed not working for enums
warn - Gtk::BuildableParser padding field - Unknown conversion to crystal for fixed size array.
syntax error in './gsk-4.0/path_point.cr:122:13': can't use variable name 'center' inside assignme
nt to variable 'center'
fatal - Error formating generated files at '/home/conner/git-projects/gtk4.cr/lib/gi-crystal/src/a
uto'.

Most notable being the actual error:
`syntax error in './gsk-4.0/path_point.cr:122:13': can't use variable name 'center' inside assignment to variable 'center'
fatal - Error formating generated files at '/home/conner/git-projects/gtk4.cr/lib/gi-crystal/src/auto'.`

I'm not sure if I have improper versions of programs or what, I can provide extra information as needed!

crystal: 1.9.2 gtk+4: 4.13.0 gobject-introspection: 1.72.0

hugopl commented 1 year ago

GTK4 on ArchLinux still on 4.12, I'll wait 4.13 land there to fix this, so I don't need to compile gtk4 myself or install gtk4 4.13 from test repository.

BTW I good thing to do when reporting these kind of bugs is to paste the code for the generated function that had problems... maybe I should create some issue template on github, anyway, thanks for reporting!

xenanthropy commented 1 year ago

GTK4 on ArchLinux still on 4.12, I'll wait 4.13 land there to fix this, so I don't need to compile gtk4 myself or install gtk4 4.13 from test repository.

BTW I good thing to do when reporting these kind of bugs is to paste the code for the generated function that had problems... maybe I should create some issue template on github, anyway, thanks for reporting!

Ah sorry, I wasn't fully aware that the code was generated! I'll do that now - this is the issue in question:

# Generator::NullableArrayPlan
center = if center.nil?
Void.null
else
center.to_unsafe
end

center = if center.nil? being the problem line

hugopl commented 1 year ago

Better copy the whole method declaration with annotation comments, etc. Usually it's possible to identify what's wrong with just that. Then I can try to reproduce the issue in the lib used on gi-crystal tests.

GskPath is a new API from GSK, so I don't have it here in my system yet. The weird thins is that the docs says "since 4.14", however you seems to have it on 4.13.

xenanthropy commented 1 year ago

Ah, of course, here is the entire method:

def curvature(path : Gsk::Path,direction : Gsk::PathDirection,) : Graphene::Point
  # gsk_path_point_get_curvature: (Method)
# @path: 
# @direction: 
# @center: (out) (nullable) (caller-allocates) 
# Returns: (transfer none) 

  # Generator::NullableArrayPlan
center = if center.nil?
Void.null
else
center.to_unsafe
end
# Generator::CallerAllocatesPlan
center=Graphene::Point.new
  # C call
  _retval = LibGsk.gsk_path_point_get_curvature(to_unsafe, path, direction, center)

  # Return value handling
  center

end

i'll go ahead and attach the whole file as well, in case any extra details are needed from it! path_point.txt

hugopl commented 1 year ago

Hmmm... it's a well known problem related to how to handle these out/nullable/optimal parameters in bindings.

BTW, if you don't need this method you can unblock yourself by changing GSK binding.yml file to:

namespace: Gsk
version: "4.0"
require_after:
- gi_crystal.cr
- render_node.cr

types:
  RenderNode:
    ignore_methods:
    - ref
    - unref
  PathPoint:
    ignore_methods:
    - get_curvature
xenanthropy commented 1 year ago

Hmmm... it's a well known problem related to how to handle these out/nullable/optimal parameters in bindings.

BTW, if you don't need this method you can unblock yourself by changing GSK binding.yml file to:

namespace: Gsk
version: "4.0"
require_after:
- gi_crystal.cr
- render_node.cr

types:
  RenderNode:
    ignore_methods:
    - ref
    - unref
  PathPoint:
    ignore_methods:
    - get_curvature

Yeah I don't think i'm needing that method so thanks, that got me past it and thankfully no other methods had issues! Shall I close this or do you want me to leave it open as a reminder to look into when your GTK gets updated?

hugopl commented 1 year ago

No, keep it open, the bug still exists. Even the fix need to be made on gi-crystal, IMO is ok the bug to be filed here since it's a bug in GSK bindings that are provided by this repository.

hugopl commented 11 months ago

I just pushed these changes while this isn't proper fixed in gi-crystal. They will be available in next release.

kojix2 commented 7 months ago

I am using macOS and am getting the same error.

kojix2 commented 7 months ago

No, no, forget it. I updated shard.lock and all is well. Have a nice day.