You are not logged in.

#1 2021-12-30 18:32:05

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

[Solved] Struggling with C and GTK

Hi guys,

I maintain the AUR package for lightspeed, a nice little tool which simulates and visualizes the effects of special relativity: https://aur.archlinux.org/packages/lightspeed/ It is very old (last release in 2001) and is based on GTK+. So, as I had some free time, I thought, I try and see how hard it is to port this to at least GTK2 or even GTK3.

Luckily, it required just a few modifications to compile it against GTK2. However, there is one thing, which doesn't work as expected. In a function which is resoponsible for recalculating the variable values for the simulation and also updating the OpenGL output there is an if clause checking if there is some GTK event still pending, it uses the method

gtk_events_pending()

Now the strange thing is that in the original GTK+ version, when doing nothing with the mouse, this is always FALSE, so the code proceeds with updating stuff. But in the GTK2 version this gives TRUE for some unexplainable reason. This results in no OpenGL output being shown at all. If I revert the check, the app works as expected but uses up 100% of one core's CPU time and also some animations are only shown while moving the mouse. Obviously, not a good idea to rerun the loop while some event is still pending.

So I tried to find out which event it is:

if (gtk_events_pending( ) == 0) {
  fprintf(stderr, "gtk_events_pending=0\n");
} else {
  fprintf(stderr, "gtk_events_pending=1\n");
  if ( gtk_get_current_event () == NULL ) {
    fprintf(stderr, "current event is NULL\n");
  }
}

In the GTK+ version (working) this outputs

gtk_events_pending=0

but in the GTK2 version (broken) it outputs

gtk_events_pending=1
current event is NULL

So an event is pending but it is NULL which, according to the docs, means that there is none. And now I am really stuck and don't know what is going on.

Please let me know if you need any further input, like some part of the code or anything else, to further analyze the problem. Thanks for any hints!

Merry Christmas and a happy new year!
PhotonX

Last edited by PhotonX (2022-01-06 17:30:16)


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#2 2021-12-30 18:52:51

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [Solved] Struggling with C and GTK

gtk_get_current_event() is supposed to return "a copy of the event currently being processed by GTK+" (according to the GTK 3 documentation), not the next event to be processed.
So I would say that there is no contradiction in that it returns NULL while gtk_events_pending() returns TRUE.
Maybe you should try playing with gtk_main_iteration() and gtk_main_iteration_do() instead.

Last edited by lambdarch (2021-12-30 18:56:20)

Offline

#3 2021-12-30 18:59:54

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Thanks for the fast and helpful reply! smile But, stupid question: If there is no event currently being processed, why would there be a pending event? Like, figurally speaking, why is an event waiting in the queue, if no event is at the counter making guys in the queue wait?

Last edited by PhotonX (2021-12-30 19:00:47)


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#4 2021-12-30 19:05:04

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [Solved] Struggling with C and GTK

Maybe because the main loop doesn't run as it should, due to the migration from one version of GTK to another. This is just a guess though...

Offline

#5 2021-12-30 19:19:27

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Yep, obviously, it is hard to tell anything without seeing the code... I can just state that the changes I made are very small and I am about 95% sure that they don't cause the trouble. So the alternative is to assume that the same code leads to different behaviour in GTK+ and GTK2 which is also rather strange...

By the way, regarding the methods you proposed, the problem is that I have no experience with C, let alone GTK, I only know some (very little) JS and PHP. So I am very surprised that I got this far and could figure out what to change to make the app compile and run with GTK2.

This being said, the documentation proposes the construction

// computation going on...

 while (gtk_events_pending ())
   gtk_main_iteration ();

 // ...computation continued

but the code in lightspeed looks differently:

        /* Code taken from animation.c in lightspeed 1.2a */

	/* Do pending redraws (if any) ONLY if event queue is empty */
	if (gtk_events_pending( ) == 0) {
		for (i = 0; i < num_cams; i++)
			if (usr_cams[i]->redraw) {
				camera_calc_xyz( CAM_POSITION, usr_cams[i] );
				ogl_draw( i );
				redraw_occurred = TRUE;
			}

#if VELOCITY_SLIDER
		/* Update velocity slider */
		velocity_slider( NULL, MESG_(RESET) );
#endif
	}
	else
		redraw_deferred = TRUE;

So it is an if/else clause rather than a while loop. I fear, I don't have enough experience to further analyze and better understand how this works... I tried making it look more like the while loop but it didn't work well.

Last edited by PhotonX (2021-12-30 19:22:34)


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#6 2021-12-30 19:32:52

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [Solved] Struggling with C and GTK

PhotonX wrote:

So the alternative is to assume that the same code leads to different behaviour in GTK+ and GTK2 which is also rather strange...

Not so much smile

I downloaded the code to have a look at it, but it doesn't tell me much more: the construction with gtk_main() in main() seems "normal", but I'm rather used to GTK 3, maybe there is something special to see here...

Did you try to insert

 while (gtk_events_pending ())
   gtk_main_iteration ();

before

if (gtk_events_pending( ) == 0) {

?

---
Remark:

if (! gtk_events_pending ()) {

would be better, by the way

Last edited by lambdarch (2021-12-30 19:36:12)

Offline

#7 2021-12-30 19:35:10

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: [Solved] Struggling with C and GTK

I'm not sure why there is even a check for pending events. It is run through the gtk main loop as an idle function. So please do not add the gtk_main_iteration call.

Last edited by progandy (2021-12-30 19:35:51)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#8 2021-12-30 19:37:52

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Nope, but I assume that it won't do much, as gtk_events_pending () always returns 0, so the loop would at best be run once, wouldn't it?

If you are interested, I can provide the ported version (as a tarball or as a patch), so you can play around with it and reproduce the problem. It's not a critical project, I'm just playing around, so no worries, if you don't want to dive into it any deeper!

edit:

I tried

if (! gtk_events_pending ())

and this way it works in principle, but it eats up 100% CPU and animations only work when the screen content is updated, say, by moving the mouse pointer or using Alt+Tab. This happens in both GTK+ and GTK2.

@progandy: Basically, since gtk_events_pending gives 1 in the GTK2 version, reverting the if condition is equivalent to dropping it completely, which leads to the 100% CPU usage problem described in the edit above... I even ran gprof on it and see that it spawns a function over a million of times (can provide gprof graph if it helps).

Last edited by PhotonX (2021-12-30 19:42:55)


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#9 2021-12-30 20:00:02

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [Solved] Struggling with C and GTK

PhotonX wrote:

If you are interested, I can provide the ported version (as a tarball or as a patch), so you can play around with it and reproduce the problem. It's not a critical project, I'm just playing around, so no worries, if you don't want to dive into it any deeper!

Why not, go ahead. I'm not going to have time to play with this right away, but I think I'll be able to dabble in it a bit in the next few days.

Offline

#10 2021-12-30 20:20:48

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Sure, no hurry! It's a bit ugly, some stuff just removed to make it compile but it works in principle, besides of the problem in question: https://gist.github.com/Photon89/b1f312 … 2413a2cb33


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#11 2021-12-31 09:37:37

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [Solved] Struggling with C and GTK

I'm having problems building lightspeed with your patch:
* I had to add the definition of AM_PATH_GTK_2_0 to aclocal.m4 to be able to run autoconf;
* configure then runs correctly (although ending with "WARNING:  'Makefile.in' seems to ignore the --datarootdir setting"), but:
* make terminates immediately with this error: "error: your implementation of AM_INIT_AUTOMAKE comes from an old Automake version. You should recreate aclocal.m4 with aclocal and run automake again".

Recreating aclocal.m4 with aclocal doesn't help, I then get other errors...

Did you encounter the same problem, do you have any indications to give me? Thanks!

Last edited by lambdarch (2021-12-31 09:39:07)

Offline

#12 2021-12-31 10:50:03

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Thanks for checking it out!

I don't know why, but the following worked for me:

patch -s -p0 < lightspeed-gtk2.patch
cd lightspeed-1.2a-old/
aclocal
automake --add-missing
./configure # this will still not pick up the changes and check for GTK+ instead of GTK2
make clean # this will for some reason rerun configure and pick up the changes
make

Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#13 2021-12-31 11:14:46

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: [Solved] Struggling with C and GTK

./configure # this will still not pick up the changes and check for GTK+ instead of GTK2

You probably need to regenerate the configure script with autoconf. Most likely the makefile detects that and does it automatically.

Last edited by progandy (2021-12-31 11:15:11)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#14 2021-12-31 11:19:37

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Thanks for the explanation! I'm not familiar with autoconf/automake, so I'm kind of poking about in a fog, searching the net, trying this and that...

So, if I understand correctly, autoconf generates configure and automake generates the Makefile, then configure and make do the actual building?


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#15 2021-12-31 11:28:36

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: [Solved] Struggling with C and GTK

automake generates Makefile.in from Makefile.am.
autoconf generate the ./configure script from configure.ac (or the old configure.in name)
The ./configure script then generates the Makefile from Makefile.in
Now you can build with make which reads the Makefile.

Last edited by progandy (2021-12-31 11:29:39)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#16 2021-12-31 12:12:53

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

I see, thanks! Glad that I started playing around with this, now I'm learning usefull stuff from you guys! smile


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#17 2021-12-31 15:28:10

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [Solved] Struggling with C and GTK

progandy wrote:

automake generates Makefile.in from Makefile.am.

I forgot about this step: I got a little too used to an autogen.sh script doing all this for me smile

So here are the steps to build it for me :

aclocal
automake --add-missing
autoconf
./configure
make

@PhotonX: if you remove all traces of the old version of lightspeed on your system (so in particular gtkglarea1), make should crash on including <gtkgl/gtkglarea.h> in lightspeed.h.
For some reason I don't know (I'm not an autoconf/automake expert as you can see), the definition of CFLAGS in configure.in is not enough.
To make it compile, I added by hand

lightspeed_CFLAGS = -I/usr/include/gtkgl-2.0

in Makefile.am (to be done before all the steps of the build above).

Then the compilation goes on. If you now purge the events with

 while (gtk_events_pending ())
   gtk_main_iteration ();

before the test on gtk_events_pending() in animation.c, and comment out what you had added underneath and your additions of gtk_widget_queue_draw() in ogl.c, I think "it's ok" (it's still tinkering, but the application seems functional, without infinite loop).
I haven't done very thorough testing though.

Here is the diff compared to your patched version:

 src/Makefile.am |  2 ++
 src/animation.c | 12 +++++-------
 src/ogl.c       |  4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index a739da2..7fecbed 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -33,6 +33,8 @@ lightspeed_SOURCES = \
         trackmem.c \
         warp.c
 
+lightspeed_CFLAGS = -I/usr/include/gtkgl-2.0
+
 EXTRA_DIST = \
 	icon.xpm \
 	title.xpm
diff --git a/src/animation.c b/src/animation.c
index ffa1cc8..1bbd01c 100644
--- a/src/animation.c
+++ b/src/animation.c
@@ -88,9 +88,11 @@ update( int message )
 	state_change = transition_engine( NULL );
 
 	/* Do pending redraws (if any) ONLY if event queue is empty */
+	fprintf(stderr, "gtk_events_pending(): %d\n", gtk_events_pending());
+	fprintf(stderr, "state_change: %d\n", state_change);
+	while (gtk_events_pending ())
+   gtk_main_iteration ();
 	if (gtk_events_pending( ) == 0) {
-	//if (!g_main_context_pending(NULL)) {
-		fprintf(stderr, "gtk_events_pending=0\n");
 		for (i = 0; i < num_cams; i++)
 			if (usr_cams[i]->redraw) {
 				camera_calc_xyz( CAM_POSITION, usr_cams[i] );
@@ -104,11 +106,6 @@ update( int message )
 #endif
 	}
 	else
-		fprintf(stderr, "gtk_events_pending=1\n");
-		if ( gtk_get_current_event () == NULL ) {
-			fprintf(stderr, "current event is NULL\n");
-			fflush( stderr );
-		}
 		redraw_deferred = TRUE;
 
 	/* Semi-BUG: Framerate goes artificially high if only spawned cameras are moved
@@ -121,6 +118,7 @@ update( int message )
 		profile( PROFILE_IDLE );
 	}
 
+	fprintf(stderr, "active: %d\n", active);
 	return active;
 }
 
diff --git a/src/ogl.c b/src/ogl.c
index 64d5187..27aa81c 100644
--- a/src/ogl.c
+++ b/src/ogl.c
@@ -296,7 +296,7 @@ ogl_draw( int cam_id )
 //		GTKGL_TEMP_endgl( GTK_GL_AREA(cam->ogl_w) );
 //		glFlush();
 		gtk_gl_area_swap_buffers( GTK_GL_AREA(cam->ogl_w) );
-		gtk_widget_queue_draw( GTK_GL_AREA(cam->ogl_w) );
+		//gtk_widget_queue_draw( cam->ogl_w );
 		profile( PROFILE_OGLDRAW_DONE );
 		cam->redraw = FALSE;
 	}
@@ -524,7 +524,7 @@ ogl_blank( int cam_id, const char *blank_message )
 	}
 
 	// GTKGL_TEMP_endgl( GTK_GL_AREA(cam->ogl_w) );
-	gtk_widget_queue_draw( GTK_GL_AREA(cam->ogl_w) );
+	//gtk_widget_queue_draw( cam->ogl_w );
 	gtk_gl_area_swap_buffers( GTK_GL_AREA(cam->ogl_w) );
 }

Offline

#18 2021-12-31 15:59:42

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [Solved] Struggling with C and GTK

A little less tinkering (to avoid the justified admonitions of @progandy above smile ): replace the purging of pending events by a lowering of the priority of idle_loop():

 src/animation.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/animation.c b/src/animation.c
index ffa1cc8..a782d2e 100644
--- a/src/animation.c
+++ b/src/animation.c
@@ -27,7 +27,7 @@
 
 
 /* Forward declarations */
-static int idle_loop( void );
+static int idle_loop( gpointer );
 static int transition_engine( trans_var *new_tvar );
 
 
@@ -70,7 +70,7 @@ update( int message )
 			return FALSE; /* already running */
 		active = TRUE;
 		/* Hook our idle loop in */
-		gtk_idle_add( (GtkFunction)idle_loop, NULL );
+		g_idle_add_full(G_PRIORITY_LOW, idle_loop, NULL ,NULL);
 		return TRUE;
 
 	default:
@@ -88,9 +88,9 @@ update( int message )
 	state_change = transition_engine( NULL );
 
 	/* Do pending redraws (if any) ONLY if event queue is empty */
+	fprintf(stderr, "gtk_events_pending(): %d\n", gtk_events_pending());
+	fprintf(stderr, "state_change: %d\n", state_change);
 	if (gtk_events_pending( ) == 0) {
-	//if (!g_main_context_pending(NULL)) {
-		fprintf(stderr, "gtk_events_pending=0\n");
 		for (i = 0; i < num_cams; i++)
 			if (usr_cams[i]->redraw) {
 				camera_calc_xyz( CAM_POSITION, usr_cams[i] );
@@ -104,11 +104,6 @@ update( int message )
 #endif
 	}
 	else
-		fprintf(stderr, "gtk_events_pending=1\n");
-		if ( gtk_get_current_event () == NULL ) {
-			fprintf(stderr, "current event is NULL\n");
-			fflush( stderr );
-		}
 		redraw_deferred = TRUE;
 
 	/* Semi-BUG: Framerate goes artificially high if only spawned cameras are moved
@@ -121,6 +116,7 @@ update( int message )
 		profile( PROFILE_IDLE );
 	}
 
+	fprintf(stderr, "active: %d\n", active);
 	return active;
 }
 
@@ -128,7 +124,7 @@ update( int message )
 /* "Lackey" idle loop for update( )
  * Remember, returning TRUE makes loop run again, returning FALSE stops it... */
 static int
-idle_loop( void )
+idle_loop( gpointer )
 {
 	return update( ITERATION );
 }

Offline

#19 2021-12-31 17:49:49

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Great, I tried this second patch and it works!

What do you guys think, how should we go about this now? Contact the original developer so he can release an update? Or create a repo for it, say, on Github as a fork? I'd like to have a GTK2 version in the AUR and get rid of the ancient GTK+ version -- it's the only package requiring the old GTK+ libs on my machine.


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#20 2021-12-31 18:05:21

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [Solved] Struggling with C and GTK

There are still two critical warnings at startup:

(lightspeed:44861): Gdk-CRITICAL **: 18:53:09.606: IA__gdk_string_width: assertion 'font != NULL' failed

(lightspeed:44861): Gtk-CRITICAL **: 18:53:13.649: IA__gtk_window_add_accel_group: assertion 'GTK_IS_WINDOW (window)' failed

And Objects -> Animation seems to be broken, also with warnings:

(lightspeed:44861): Gtk-CRITICAL **: 18:53:34.620: IA__gtk_window_new: assertion 'type >= GTK_WINDOW_TOPLEVEL && type <= GTK_WINDOW_POPUP' failed

(lightspeed:44861): Gtk-CRITICAL **: 18:53:34.620: IA__gtk_window_set_title: assertion 'GTK_IS_WINDOW (window)' failed

(lightspeed:44861): Gtk-CRITICAL **: 18:53:34.620: IA__gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed

(lightspeed:44861): Gtk-CRITICAL **: 18:53:34.620: IA__gtk_signal_connect_full: assertion 'GTK_IS_OBJECT (object)' failed

(lightspeed:44861): Gtk-CRITICAL **: 18:53:34.620: IA__gtk_window_set_position: assertion 'GTK_IS_WINDOW (window)' failed

(lightspeed:44861): Gtk-CRITICAL **: 18:53:34.620: IA__gtk_container_add: assertion 'GTK_IS_CONTAINER (container)' failed

(lightspeed:44861): Gdk-CRITICAL **: 18:53:34.621: IA__gdk_string_width: assertion 'font != NULL' failed

(lightspeed:44861): Gdk-CRITICAL **: 18:53:34.622: IA__gdk_string_width: assertion 'font != NULL' failed

(lightspeed:44861): Gtk-CRITICAL **: 18:53:34.630: IA__gtk_widget_show: assertion 'GTK_IS_WIDGET (widget)' failed

And I haven't tested everything. So personally, I wouldn't consider this finished.
For the rest, I guess the best thing is to try to contact the author of the software, or the current maintainer, before creating a fork?

Last edited by lambdarch (2021-12-31 18:10:12)

Offline

#21 2021-12-31 18:17:08

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

I fear, I have too little experience to continue working on it. I tried to research how to go about such warnings a few days ago already, but couldn't figure it out so far. Also, the winter break will end soon and then the job stress will kick in again. So I'd like to finish it off in one way or another. If you, or anybody else, would like to continue working on it and fix up the things that are still broken, I would be very happy though. If not, I'd contact the author and see what he says. Probably he also won't have much time to deal with his 20 year old project. But I think, better an unfinished GTK2 port than a GTK+ version which is essentially not usable as most distros don't offer these ancient libraries in their repos.


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#22 2021-12-31 18:28:56

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [Solved] Struggling with C and GTK

Sorry, but I won't have time to deal with this any further either.
I just wanted to give a hand in passing because I had a free moment smile

To help you debug these warnings, you can do

G_DEBUG=fatal-criticals gdb -ex run -ex bt lightspeed

which should take you to where they come from.

PhotonX wrote:

But I think, better an unfinished GTK2 port than a GTK+ version which is essentially not usable as most distros don't offer these ancient libraries in their repos.

You are probably right.

Offline

#23 2021-12-31 19:41:57

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Thanks for the hint, and also for all the other help! I might give it another go, if time permits.

I wrote a mail to the developer, let's see what he prefers. If he doesn't reply, I'd put it into a Github repo and then leave it there, then everybody interested (including myself) can do PRs to tackle the remaining issues whenever time permits. The repo can then be used to make an AUR -git package already.

Last edited by PhotonX (2021-12-31 19:42:55)


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#24 2022-01-02 23:10:03

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Hi guys,

since I didn't get a reply from the original developer, I just went ahead and set up a repo at Github: https://github.com/Photon89/lightspeed

I tried debugging the Gtk-CRITICAL messages and segfaults but to be honest, I don't really know how to interpret the debugging output. For example, when trying to open the About dialog, I get a segmentation fault and gdb reports

Thread 1 "lightspeed" received signal SIGSEGV, Segmentation fault.
add_pixmap (parent_w=parent_w@entry=0x555555c66410, parent_window_w=0x0, xpm_data=xpm_data@entry=0x555555580fa0 <lightspeed_title_xpm>) at gtkwidgets.c:641
641		pixmap = gdk_pixmap_create_from_xpm_d( parent_window_w->window, &mask,
#0  add_pixmap (parent_w=parent_w@entry=0x555555c66410, parent_window_w=0x0, xpm_data=xpm_data@entry=0x555555580fa0 <lightspeed_title_xpm>) at gtkwidgets.c:641
#1  0x000055555556a81c in dialog_Help_About (widget=<optimized out>, message=<optimized out>) at menu_cbs.c:1541
#2  dialog_Help_About (widget=<optimized out>, message=<optimized out>) at menu_cbs.c:1502
#3  0x00007ffff75b2d8f in g_closure_invoke () at /usr/lib/libgobject-2.0.so.0
#4  0x00007ffff75ce718 in  () at /usr/lib/libgobject-2.0.so.0
#5  0x00007ffff75cfdd9 in g_signal_emit_valist () at /usr/lib/libgobject-2.0.so.0
#6  0x00007ffff75d0330 in g_signal_emit () at /usr/lib/libgobject-2.0.so.0
#7  0x00007ffff7cf6fb5 in gtk_widget_activate () at /usr/lib/libgtk-x11-2.0.so.0
#8  0x00007ffff7be5df1 in gtk_menu_shell_activate_item () at /usr/lib/libgtk-x11-2.0.so.0
#9  0x00007ffff7be610f in  () at /usr/lib/libgtk-x11-2.0.so.0
#10 0x00007ffff7bd30a8 in  () at /usr/lib/libgtk-x11-2.0.so.0
#11 0x00007ffff75b2d8f in g_closure_invoke () at /usr/lib/libgobject-2.0.so.0
#12 0x00007ffff75ce0ee in  () at /usr/lib/libgobject-2.0.so.0
#13 0x00007ffff75cf40b in g_signal_emit_valist () at /usr/lib/libgobject-2.0.so.0
#14 0x00007ffff75d0330 in g_signal_emit () at /usr/lib/libgobject-2.0.so.0
#15 0x00007ffff7cf8275 in  () at /usr/lib/libgtk-x11-2.0.so.0
#16 0x00007ffff7bd16d6 in gtk_propagate_event () at /usr/lib/libgtk-x11-2.0.so.0
#17 0x00007ffff7bd1b4b in gtk_main_do_event () at /usr/lib/libgtk-x11-2.0.so.0
#18 0x00007ffff7a403be in  () at /usr/lib/libgdk-x11-2.0.so.0
#19 0x00007ffff74bc52c in g_main_context_dispatch () at /usr/lib/libglib-2.0.so.0
#20 0x00007ffff75107b9 in  () at /usr/lib/libglib-2.0.so.0
#21 0x00007ffff74bbab3 in g_main_loop_run () at /usr/lib/libglib-2.0.so.0
#22 0x00007ffff7bd09fe in gtk_main () at /usr/lib/libgtk-x11-2.0.so.0
#23 0x000055555555cf0c in main (argc=<optimized out>, argv=<optimized out>) at lightspeed.c:169
 

So now I know that the problem is in the

pixmap = gdk_pixmap_create_from_xpm_d( parent_window_w->window, &mask,  &style->bg[GTK_STATE_NORMAL], xpm_data );

call but I still don't really know what goes wrong and leads to the segmentation fault. How can I learn the magic of interpreting this debugging information? smile

Last edited by PhotonX (2022-01-02 23:10:35)


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#25 2022-01-03 09:35:09

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [Solved] Struggling with C and GTK

As you can see in

add_pixmap (parent_w=parent_w@entry=0x555555c66410, parent_window_w=0x0, xpm_data=xpm_data@entry=0x555555580fa0 <lightspeed_title_xpm>) at gtkwidgets.c:641

parent_window_w is NULL, so in

pixmap = gdk_pixmap_create_from_xpm_d( parent_window_w->window, &mask,  &style->bg[GTK_STATE_NORMAL], xpm_data );

you try to dereference a NULL pointer (parent_window_w->window): that is the cause of the segfault.
Now you have to find out why parent_window_w is NULL smile
For this, you have at least the location of the previous calls: menu_cbs.c:1541 and menu_cbs.c:1502.

PhotonX wrote:

How can I learn the magic of interpreting this debugging information? smile

There is not much more to interpret: in general the relevant information is at the top, as here, with all the symbols if they have been included during the build.
It tells you where the problem is, the value of some variables, and that's it.

Last edited by lambdarch (2022-01-03 09:40:06)

Offline

Board footer

Powered by FluxBB