Anyway, thanks a ton to both of you guys, I learned a lot about C, GTK and coding in general and had a lot of fun with this little project in my Christmas break. I think, the initial GTK related issues are all solved, we even have a completely functional GTK2 version now, so I'd rather mark this thread as solved and open a new one about the OpenGL related stuff. Maybe it will catch the attention of some GL specialist.
]]>I am wondering, whether there is some kind of migration guide, which of course won't be a one-to-one dictionary of old and new functions, but at least gives some hints for people that need to do such a migration?
GTK provides a migration guide when moving from one major version to another.
You've probably already seen it, but I give the links just in case:
* GTK to GTK 2: https://developer-old.gnome.org/gtk2/2. … ating.html
* GTK 2 to GTK 3: https://developer-old.gnome.org/gtk3/st … ating.html
But there doesn't seem to be much about OpenGL, and for your specific problem I don't know, sorry
(lightspeed:26482): Gdk-WARNING **: 15:44:40.894: gdk_gl_context_set_required_version - GL context versions less than 3.2 are not supported.
with some hints I could make OpenGL debugging work and now see that all the GL related code doesn't work in OpenGL versions later than 3.1 (currently we are at 4.6 so I am a bit late to the party...). It looks like this time the strategy of exchanging some function calls with newer ones, which are mostly doing the same and just have a different name, won't work any more because OpenGL now seems to work with a completely different approach.
So the worst case scenario is that it is necessary to learn the old version's API to understand how the current code is working, the new version's API to understand what possibilities there are now, and try to completely reimplement what the old code was doing. I am wondering, whether there is some kind of migration guide, which of course won't be a one-to-one dictionary of old and new functions, but at least gives some hints for people that need to do such a migration? I mean, how hard can it be to understand and reimplement around 500 code lines!
]]>I attempted to port this thing further, to GTK3: https://github.com/Photon89/lightspeed/pull/8 It already compiles, links and runs. But the OpenGL output is all black. I have removed some things to make it compile, in particular all the text overlay stuff, which is implemented in a completely different way in GTK3 (no GdkFont, Pango stuff instead). But I left all the non-text related OpenGL code, besides of
gtk_gl_area_swap_buffers()
calls. The ogl_draw() function is executed and uses the correct "camera" widget, that is the only thing I know, but I I don't know how to find out where it breaks inside this function. Maybe it's really just this gtk_gl_area_swap_buffers() call which is missing for a proper output.
But even if so, according to https://www.bassi.io/articles/2015/02/1 … -with-gtk/ this is quite a biggie and would require to really understand big portions of the code to be able to rewrite them. In this case, I fear, I'm out... But maybe something can be done to make OpenGL output work in GTK3 with less effort?
]]>I deactivated the snapshot export functionality for the moment (we have screenshot tools nowadays anyway) and created an AUR package for the current progress: https://aur.archlinux.org/packages/lightspeed-git/
]]>it's me again. I now ran into X errors and try to debug them:
$ gdb
GNU gdb (GDB) 11.1
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) file src/lightspeed
Reading symbols from src/lightspeed...
(gdb) break gdk_x_error
Function "gdk_x_error" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (gdk_x_error) pending.
(gdb) run --sync
Starting program: /home/photon/github/lightspeed2/src/lightspeed --sync
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
/home/photon/github/lightspeed2/src/lightspeed: unrecognized option '--sync'
[New Thread 0x7ffff6287640 (LWP 39981)]
[Thread 0x7ffff6287640 (LWP 39981) exited]
[New Thread 0x7ffff6287640 (LWP 39982)]
[New Thread 0x7ffff5762640 (LWP 39983)]
[New Thread 0x7ffff6287640 (LWP 39984)]
[Thread 0x7ffff6287640 (LWP 39982) exited]
[New Thread 0x7ffff4e31640 (LWP 39985)]
[Thread 0x7ffff5762640 (LWP 39983) exited]
[New Thread 0x7ffff5762640 (LWP 39986)]
[Thread 0x7ffff6287640 (LWP 39984) exited]
[New Thread 0x7ffff6287640 (LWP 39987)]
[Thread 0x7ffff5762640 (LWP 39986) exited]
[Thread 0x7ffff4e31640 (LWP 39985) exited]
[Thread 0x7ffff6287640 (LWP 39987) exited]
(lightspeed:39977): Gdk-CRITICAL **: 12:49:57.143: IA__gdk_string_width: assertion 'font != NULL' failed
[New Thread 0x7ffff6287640 (LWP 39988)]
[New Thread 0x7ffff4e31640 (LWP 39989)]
[New Thread 0x7ffff5762640 (LWP 39990)]
[New Thread 0x7fffe4af4640 (LWP 39991)]
[New Thread 0x7fffdffff640 (LWP 39992)]
[Thread 0x7fffe4af4640 (LWP 39991) exited]
[New Thread 0x7fffe4af4640 (LWP 39993)]
[Thread 0x7fffdffff640 (LWP 39992) exited]
[New Thread 0x7fffe4af4640 (LWP 39994)]
[Thread 0x7fffe4af4640 (LWP 39993) exited]
[Thread 0x7fffe4af4640 (LWP 39994) exited]
The program 'lightspeed' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadValue (integer parameter out of range for operation)'.
(Details: serial 7625 error_code 2 request_code 151 minor_code 3)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the --sync command line
option to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)
^C
Thread 1 "lightspeed" received signal SIGINT, Interrupt.
0x00007ffff6c68740 in _XReply () from /usr/lib/libX11.so.6
(gdb) bt
#0 0x00007ffff6c68740 in _XReply () at /usr/lib/libX11.so.6
#1 0x00007ffff6c63fbd in XSync () at /usr/lib/libX11.so.6
#2 0x00007ffff6c6405c in () at /usr/lib/libX11.so.6
#3 0x00007ffff42d9626 in () at /usr/lib/libGLX_nvidia.so.0
#4 0x00007ffff427c060 in () at /usr/lib/libGLX_nvidia.so.0
#5 0x00007ffff42b6fae in () at /usr/lib/libGLX_nvidia.so.0
#6 0x00007ffff42ba711 in () at /usr/lib/libGLX_nvidia.so.0
#7 0x00007ffff4279990 in () at /usr/lib/libGLX_nvidia.so.0
#8 0x00007ffff427a19f in () at /usr/lib/libGLX_nvidia.so.0
#9 0x00007fffffffc698 in ()
#10 0x00007ffff62c6338 in () at /usr/lib/gtk-2.0/2.10.0/engines/libmurrine.so
#11 0x00007fffffffc910 in ()
#12 0x00007ffff4315009 in () at /usr/lib/libGLX_nvidia.so.0
#13 0x00007fffffffc910 in ()
#14 0x00007ffff7fdd1c5 in _dl_fini () at /lib64/ld-linux-x86-64.so.2
(gdb) quit
A debugging session is active.
Inferior 1 [process 39977] will be killed.
Quit anyway? (y or n) y
As you see, the "--sync" option is not being recognized and the backtrace comes too late, after I Ctrl+C the crashed process. What do I do wrong?
I assume that the errors are due to g_object_unref() and gdk_gl_pixmap_unref() calls in https://github.com/Photon89/lightspeed/ … shot.c#L89 which I had to remove (I also tried to substitute them with g_object_unref() but it doesn't make a difference). But maybe the problem is somewhere else...
addendum: I fear, my guess is wrong, the X error also appears in the GTK+ version, which I didn't touch...
]]>____________
edit:
Sorry, please disregard what comes below, I solved it just after posting... I had to add
active = FALSE;
before the
gtk_widget_hide (about_window_w);
call!
____________
However, now I am stuck with closing the dialog. Previously in the function
dialog_Help_About( GtkWidget *widget, int *message )
there was a
add_button( main_vbox_w, STR_DLG_Okay_btn, dialog_Help_About, MESG_(DIALOG_CLOSE) );
call which sent a DIALOG_CLOSE message and used the function itself as callback. It would check, what the message is, and hide the dialog:
switch (*message) {
case DIALOG_OPEN:
if (active)
return;
active = TRUE;
break;
case DIALOG_CLOSE:
if (!active)
return;
active = FALSE;
gtk_widget_hide( about_window_w );
return;
default:
#ifdef DEBUG
crash( "dialog_Help_About( ): invalid message" );
#endif
return;
}
However, now the dialog object allows to create a button automatically. So now I have two OK buttons: One added via add_button as explained above, one created automatically via
about_window_w = gtk_dialog_new_with_buttons(STR_DLG_About,
GTK_WINDOW(parent_window),
GTK_DIALOG_MODAL,
GTK_STOCK_OK
);
To make this latter OK button do something I added
gint result = gtk_dialog_run (GTK_DIALOG (about_window_w));
gtk_widget_hide (about_window_w);
This does not work as expected, however, to be more precise, it works only once, if clicked the default OK button once, the dialog is hidden and then never shown again when the menu entry is clicked.
Here is the complete function: https://gist.github.com/Photon89/513478 … 51dc1c8526
Here is how it looks like (upper OK button is added by hand and works, lower OK button is added automatically on dialog creation and works only once):
]]>
But gtk_signal_connect() accepts only one callback_data argument which is already used for something else, and thus I cannot pass the parent window object to the scope where I need it to be...
Probably what @progandy says is enough in this case, otherwise in general you have to define and allocate (and then release) a structure to put the data you want to pass to the callback.
This gives you a pointer that you pass as the only data.
Otherwise, when one of the data to be passed is a GObject (as is very often the case in this context), you can attach temporary data to it using the g_object_set_data() function family.
You should not abuse it as the doc says, but it is very convenient.
Stupid question: Is it possible to define a "global" variable inside a function, such that it is available in all functions called inside our function without being explicitly passed as argument?
]]>diff --git a/src/gtkwidgets.c b/src/gtkwidgets.c
index c7d9c02..31a85f8 100644
--- a/src/gtkwidgets.c
+++ b/src/gtkwidgets.c
@@ -64,7 +64,7 @@ make_dialog_window( const char *title, void *callback_close )
{
GtkWidget *dialog_window_w;
- dialog_window_w = gtk_window_new( GDK_WINDOW_DIALOG );
+ dialog_window_w = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_window_set_title( GTK_WINDOW(dialog_window_w), title );
gtk_container_set_border_width( GTK_CONTAINER(dialog_window_w), 0 );
if (callback_close != NULL) {
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
For this, you have at least the location of the previous calls: menu_cbs.c:1541 and menu_cbs.c:1502.
How can I learn the magic of interpreting this debugging information?
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.