Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

self is null in notify signal #218

Open
dexterdy opened this issue Feb 12, 2023 · 3 comments
Open

self is null in notify signal #218

dexterdy opened this issue Feb 12, 2023 · 3 comments

Comments

@dexterdy
Copy link

Strange bug that I encountered when connecting to the notify signal. Self is null and thus gives a runtime error when trying to access properties.

  proc makeEditableOnSelect(self: gtk4.ListItem, param: gobject.ParamSpec, label: gtk4.EditableLabel) =
    if self.selected:
      label.setEditable(true)
    else:
      label.setEditable(false)
  item.connect("notify::selected", makeEditableOnSelect, label)

Throws runtime error:

Traceback (most recent call last)
/home/dexterdy/Documents/repos/relmnotes/src/realmnotes.nim(53) realmnotes
/home/dexterdy/Documents/repos/relmnotes/src/realmnotes.nim(51) main
/home/dexterdy/.nimble/pkgs/gintro-#head/gintro/gio.nim(31998) run
/home/dexterdy/.choosenim/toolchains/nim-1.6.10/lib/core/macros.nim(542) connect_for_signal_cdecl_response6
/home/dexterdy/Documents/repos/relmnotes/src/types/observer.nim(25) on_reponse
/home/dexterdy/Documents/repos/relmnotes/src/types/observer.nim(26) =destroy
/home/dexterdy/Documents/repos/relmnotes/src/components/treeView.nim(22) update
/home/dexterdy/.nimble/pkgs/gintro-#head/gintro/gio.nim(24365) append
/home/dexterdy/.choosenim/toolchains/nim-1.6.10/lib/core/macros.nim(548) connect_for_signal_cdecl_notify1
/home/dexterdy/Documents/repos/relmnotes/src/components/treeView.nim(46) makeEditableOnSelect
/home/dexterdy/.nimble/pkgs/gintro-#head/gintro/gtk4.nim(50256) selected
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

I checked with a debugger and a null check. It is null in all cases, without exception

@StefanSalewski
Copy link
Owner

Thanks for reporting. Notify signal support was indeed added very late, maybe two years ago, and I think it was working still one year ago. But maybe our latest fixes broke it, I will check soon.

@StefanSalewski
Copy link
Owner

We have an example for the use of notify signal with GtkDropDown in the Nim GTK4 book, and that works fine for me, see https://ssalewski.de/gtkprogramming.html#_listview_columnview_gridview_and_dropdown, DropDown1.nim. GtkDropDown is closely related to GtkListView.

So I assume that you are doing something wrong. For other ListView variants, use of notify::selected may be not that simple, due to the involved bind and setup procs. For further investigations, you may send a minimal working C example, or a minimal Nim example from which you thinks that it may work.

@StefanSalewski
Copy link
Owner

Actually my guess is, that

item.connect("notify::selected", makeEditableOnSelect, label)

is wrong. I guess connecting to notify::selected should not be done to items, but for the container like a ListView.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants