1. EuGTK - Segmentation fault, GtkCheckMenuItem
- Posted by Jerry_Story Oct 19, 2010
- 1115 views
What causes the segmentation fault?
global procedure setReqs(integer r) atom ctl -- r is getting correct numbers. for i = 1 to length(MenuReqs) do set(MenuReqs[i],"active",0) end for -- Each MenuReqs[i] is a GtkCheckMenuItem. -- All these show up in the menu bar and are clickable. ctl = MenuReqs[r] printf(1,"after ctl ctl=%d \n",{ctl}) -- (1) -- This prints a large number, as it should. -- But this line is executed many times, (2) below never. How? -- ctl is the same number each time. set(ctl,"active",1) -- Segmentation fault happens here. -- When I comment this statement out, the segmentation fault does not happen. -- set(ctl,"active",TRUE) makes no difference. printf(1,"after ctl 1 r=%d \n\n",{r}) -- (2) -- It never gets here. -- How can line (1) be executed many times and line (2) never? -- more code end procedure -- setReqs()
This is what happens.
after ctl ctl=327386248 after ctl ctl=327386248 after ctl ctl=327386248 after ctl ctl=327386248 after ctl ctl=327386248 after ctl ctl=327386248 after ctl ctl=327386248 after ctl ctl=327386248 after ctl ctl=327386248 ... etc ... Segmentation faultThe error is invoked when I click on any of the MenuReqs[r] in the menu bar.
I've been hung up on this bug for days with zero progress. How can I make some progress with this bug?
2. Re: EuGTK - Segmentation fault, GtkCheckMenuItem
- Posted by petelomax Oct 19, 2010
- 1111 views
What causes the segmentation fault?
I've been hung up on this bug for days with zero progress. How can I make some progress with this bug?
It looks like every time you call set() it is finding its way to call setReqs() again, causing an infinite loop and eventually running out of stack space.
Try something like this:
integer setting=0 global procedure setReqs(integer r) atom ctl if not setting then setting = 1 for i = 1 to length(MenuReqs) do set(MenuReqs[i],"active",0) end for ctl = MenuReqs[r] set(ctl,"active",1) setting = 0 end if end procedure -- setReqs()
Alternatively, this would probably fix the problem as well:
for i = 1 to length(MenuReqs) do if i!=r then set(MenuReqs[i],"active",0) end if end for
Regards, Pete
3. Re: EuGTK - Segmentation fault, GtkCheckMenuItem
- Posted by Jerry_Story Oct 19, 2010
- 1118 views
What causes the segmentation fault?
I've been hung up on this bug for days with zero progress. How can I make some progress with this bug?
It looks like every time you call set() it is finding its way to call setReqs() again, causing an infinite loop and eventually running out of stack space.
Try something like this:
integer setting=0 global procedure setReqs(integer r) atom ctl if not setting then setting = 1 for i = 1 to length(MenuReqs) do set(MenuReqs[i],"active",0) end for ctl = MenuReqs[r] set(ctl,"active",1) setting = 0 end if end procedure -- setReqs()
Alternatively, this would probably fix the problem as well:
for i = 1 to length(MenuReqs) do if i!=r then set(MenuReqs[i],"active",0) end if end for
Regards, Pete
The first one stops the segmentation fault. But how can set(), part of EuGTK, call setReqs()?
The second one goes into an endless loop without the segmentation fault, and alternating between 2 numbers.
after ctl 1 r=3 after ctl ctl=170814224 after ctl ctl=170814224 after ctl ctl=170814224 after ctl 1 r=2 after ctl 1 r=2 after ctl ctl=331504664 after ctl ctl=331504664 after ctl ctl=331504664 after ctl 1 r=3 after ctl 1 r=3 after ctl ctl=170814224 after ctl ctl=170814224 after ctl ctl=170814224 after ctl 1 r=2 after ctl 1 r=2
4. Re: EuGTK - Segmentation fault, GtkCheckMenuItem
- Posted by irv Oct 19, 2010
- 1033 views
Looks to me like you should be finding out what is calling setReqs() repeatedly. You need to look to see what signal you have connected to those menu items, and what function they call when changed or toggled. I'll bet that the function they call then calls setReq(), which changes the state of the menu item, thus calling the function again. An endless loop.
I think the problem lies elsewhere in your code, and without seeing it all, there's no way to help.
5. Re: EuGTK - Segmentation fault, GtkCheckMenuItem
- Posted by irv Oct 19, 2010
- 1033 views
Hmm... let me rephrase that so it's clearer:
When you toggle a check button from active to inactive, or vice-versa, it's the same as clicking on it to change the state.
So, if you have connected any signal to that button so that it responds to changes in state, that routine (or any routine it calls) can't also change the state, else your routine will just sit there in a loop.
Here's a simple demo:
include GtkEngine.e function Foo(atom x) ? x set(x,"active",0) set(x,"active",1) return 1 end function load_xml(builder,"cktest1.glade") connect("window1","destroy",quit) connect("checkbutton1","clicked",call_back(routine_id("Foo"))) show_all("window1") main()
The above code will loop until you get a seg fault. Note that it isn't necessary to directly call the offending routine from the connect signal. You may be connecting to some other function that calls the endless loop proc().
BTW, it's normally not a good idea to connect any action to clicking on a check button/box. Suppose the page has 2 or more check items. Do you really want to go do something each time one is clicked, or do you want to wait until the user has finished and has them all set the way he wants? IOW, set up the check buttons/boxes, etc, and then put an OK button to be clicked when the selections are finished.
If you feel you MUST do something the moment a checkbox is clicked, then use the "pressed" or "released" signal rather than the "clicked" signal. This way, you won't get into an endless loop, 'cause your response will be to a mouse action rather than a state change. This works well for a checkmenu item.
However, looking at your code, I wonder if you are trying to use checkmenuitems as radiomenuitems - turning off all the others when one is clicked?