GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Feb 09, 2016 9:57 am

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: gtk2yarzee game
PostPosted: Sat Jan 02, 2016 5:12 pm 
Offline
Familiar Face

Joined: Sat Jan 31, 2015 4:16 pm
Posts: 15
Location: Plymouth, Devon
Here's a little game I wrote as my first go with GTK2.
Attachment:
gtk2yarzee-1.0.34.tar.gz [122.79 KiB]
Downloaded 15 times

_________________
RickTee

Distro: Centos 7 Lang: C IDE: NetBeans Desktop: KDE


Top
 Profile  
 
 Post subject: Re: gtk2yarzee game
PostPosted: Sun Jan 10, 2016 9:33 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 971
Location: UK
Hi,

Having a quick look at your code.

If you can it would be better to use GTK+ version 3. :) Personally I would only use GTK+ version 2 for continued support for older products or for use on weird stuff that for some reason will not support version 3.

configure.ac -
You are using the macros AM_PATH_GLIB_2_0 and AM_PATH_GTK_2_0. These tend not to be used much with a preference for the pkg-config auto tools macros.
You are also checking for version 2.0.0 or greater. but use API functions that are higher than 2.0.0. Not that much of a major problem as most people will now have 2.24, but you may want to be more explicit.

main.c-
You seed the C library’s random number generator which is not necessary as you are using GLib's much better random number generator. The C library srand()/rand() is not very random when the range is expanded or reduced.

prefs.c-
I got a warning when compiling on line 408. warning: logical not is only applied to the left hand side of comparison.

In a number of places you have used deprecated API functions and widgets. These have been replaced with better solutions. With your menus "About" and "Configure" generally do not have keyboard accelerators. <Control>C is used for Copy and <Control>A is used for selecting all (for example all text). Using these might cause some confusion when switching between applications. An alternative to "Configure" is "Preferences" again without a keyboard accelerator.

Over all the same looks good, not that I have any clue how to play yarzee.

As a tip do not make the rules of the game too similar to the (tm) Hasbro version of the game ;), they may not like that. There are older versions of the game which you could emulate such as Yacht which is in the public domain.

The nearest game of this type for Gnome/GTK+ is Tali.

_________________
E.


Top
 Profile  
 
 Post subject: Re: gtk2yarzee game
PostPosted: Sun Jan 10, 2016 3:34 pm 
Offline
Familiar Face

Joined: Sat Jan 31, 2015 4:16 pm
Posts: 15
Location: Plymouth, Devon
Thanx for the feedback. The random number seed was left in by mistake after changing over to using the glib function. There is a lot of bad coding and errors in the way I have used the Gtk libs, and lots of memory leaks (as far as I can tell). Now learning the right way or at least trying to. lol I wrote that version of the game 12 months or so ago before my distro included Gtk3. Having sorted the menus for Gtk3 I've ported the whole thing as is, now a work in progress to sort it out. Originally written for the Amiga using the MUI library some 20+ years ago.

PS. I might be getting to old for this. :D

_________________
RickTee

Distro: Centos 7 Lang: C IDE: NetBeans Desktop: KDE


Top
 Profile  
 
 Post subject: Re: gtk2yarzee game
PostPosted: Sun Jan 10, 2016 4:17 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 971
Location: UK
Age should not be a problem :) You should see the age of some of the software out there. One comes to mind is the software on Voyager 1 & 2. Still running since 1977.

There are tools out there to help analyse your code for correctness and to check for resource leaks. It can be a little tricky with GLib as it allocates memory pools so this is a point to watch out for.

_________________
E.


Top
 Profile  
 
 Post subject: Re: gtk2yarzee game
PostPosted: Thu Jan 14, 2016 6:02 pm 
Offline
Familiar Face

Joined: Sat Jan 31, 2015 4:16 pm
Posts: 15
Location: Plymouth, Devon
To answer another part of your post: AM_PATH_GLIB_2_0 and AM_PATH_GTK_2_0 used them as using pkg-config when compiling under windows resulted in a linking error, don't remember the exact error but it was to do with linking in the wrong order libs last instead of first or something like that. Using AM_PATH_GLIB_2_0 and AM_PATH_GTK_2_0 solved the problem, maybe there is another way?

Been using valgrind to locate memory leaks but the output is huge and most of it does not seem to be my program, looks like many (and I do mean many) leaks from the gtk libs.

_________________
RickTee

Distro: Centos 7 Lang: C IDE: NetBeans Desktop: KDE


Top
 Profile  
 
 Post subject: Re: gtk2yarzee game
PostPosted: Thu Jan 14, 2016 6:43 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 971
Location: UK
The pkg-config macro for auto tools is PKG_CHECK_MODULES.. You do not need to use pkg-config directly in your autoconf.ac file or in the makefiles if you use the macro and the generated variables.

valgrind will spit out lots of warning that there are memory leaks with GTK+ applications. GTK Glib and other libraries allocate memory pools for internal memory allocation, buffers and other things. They are not leaks as such as they do not grow over time in the application. When the application exits GTK, GLib and others do not free the allocated memory as the operating system will do that for it. This is the warnings that valgrind is reporting.

The information at Gnome developer may help https://developer.gnome.org/programming-guidelines/stable/memory-management.html.en
https://developer.gnome.org/programming-guidelines/stable/tooling.html.en

_________________
E.


Top
 Profile  
 
 Post subject: Re: gtk2yarzee game
PostPosted: Fri Jan 15, 2016 4:26 pm 
Offline
Familiar Face

Joined: Sat Jan 31, 2015 4:16 pm
Posts: 15
Location: Plymouth, Devon
I have re-coded the dice class so internal widgets and data are now in a private struct and changed all Makefiles to use the PKG_CHECK_MODULES macro.

Running valgrind on it gives a huge amount of output:
Code:
valgrind --tool=memcheck \
   --suppressions=/home/rick/GNOME.supp/src/gtk+/3.x/GtkWidget.supp \
   --suppressions=/home/rick/GNOME.supp/src/glib/glib-Random-Numbers.supp \
   --suppressions=/home/rick/GNOME.supp/src/gdk/GdkDisplay.supp \
   --suppressions=/home/rick/GNOME.supp/src/gdk/GdkDisplayManager.supp \
   --suppressions=/home/rick/GNOME.supp/src/system.supp \
   --suppressions=/home/rick/GNOME.supp/src/glibc.supp \
   --leak-check=full --show-leak-kinds=all ./rgt_dice a.out > log.txt 2>&1

Sample of the output where its marked definitely lost:
Code:
==31078== 4,835 (1,536 direct, 3,299 indirect) bytes in 2 blocks are definitely lost in loss record 7,678 of 7,730
==31078==    at 0x4C2BB4A: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==31078==    by 0x83E2FE9: ??? (in /usr/lib64/libfontconfig.so.1.7.0)
==31078==    by 0x83E3681: ??? (in /usr/lib64/libfontconfig.so.1.7.0)
==31078==    by 0x83E081A: FcFontRenderPrepare (in /usr/lib64/libfontconfig.so.1.7.0)
==31078==    by 0x83E0D2F: FcFontMatch (in /usr/lib64/libfontconfig.so.1.7.0)
==31078==    by 0x81BD06C: ??? (in /usr/lib64/libpangoft2-1.0.so.0.3600.8)
==31078==    by 0x81BD1CC: ??? (in /usr/lib64/libpangoft2-1.0.so.0.3600.8)
==31078==    by 0x6570B27: ??? (in /usr/lib64/libpango-1.0.so.0.3600.8)
==31078==    by 0x6570F69: ??? (in /usr/lib64/libpango-1.0.so.0.3600.8)
==31078==    by 0x65722D7: pango_itemize_with_base_dir (in /usr/lib64/libpango-1.0.so.0.3600.8)
==31078==    by 0x6579489: ??? (in /usr/lib64/libpango-1.0.so.0.3600.8)
==31078==    by 0x657B277: ??? (in /usr/lib64/libpango-1.0.so.0.3600.8)

==31078== 5,942 (512 direct, 5,430 indirect) bytes in 1 blocks are definitely lost in loss record 7,684 of 7,730
==31078==    at 0x4C2BB4A: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==31078==    by 0x83E2FE9: ??? (in /usr/lib64/libfontconfig.so.1.7.0)
==31078==    by 0x83E37B4: ??? (in /usr/lib64/libfontconfig.so.1.7.0)
==31078==    by 0x83E3BEB: ??? (in /usr/lib64/libfontconfig.so.1.7.0)
==31078==    by 0x83D6F5D: FcDefaultSubstitute (in /usr/lib64/libfontconfig.so.1.7.0)
==31078==    by 0x81BC955: ??? (in /usr/lib64/libpangoft2-1.0.so.0.3600.8)
==31078==    by 0x65710C8: ??? (in /usr/lib64/libpango-1.0.so.0.3600.8)
==31078==    by 0x65722D7: pango_itemize_with_base_dir (in /usr/lib64/libpango-1.0.so.0.3600.8)
==31078==    by 0x6579489: ??? (in /usr/lib64/libpango-1.0.so.0.3600.8)
==31078==    by 0x657B277: ??? (in /usr/lib64/libpango-1.0.so.0.3600.8)
==31078==    by 0x50106DA: ??? (in /usr/lib64/libgtk-3.so.0.1400.13)
==31078==    by 0x5010BD7: ??? (in /usr/lib64/libgtk-3.so.0.1400.13)

==31078== 6,029 (512 direct, 5,517 indirect) bytes in 1 blocks are definitely lost in loss record 7,685 of 7,730
==31078==    at 0x4C2BB4A: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==31078==    by 0x83E2FE9: ??? (in /usr/lib64/libfontconfig.so.1.7.0)
==31078==    by 0x83E37B4: ??? (in /usr/lib64/libfontconfig.so.1.7.0)
==31078==    by 0x83E3BEB: ??? (in /usr/lib64/libfontconfig.so.1.7.0)
==31078==    by 0x83D6F5D: FcDefaultSubstitute (in /usr/lib64/libfontconfig.so.1.7.0)
==31078==    by 0x81BC955: ??? (in /usr/lib64/libpangoft2-1.0.so.0.3600.8)
==31078==    by 0x65710C8: ??? (in /usr/lib64/libpango-1.0.so.0.3600.8)
==31078==    by 0x65722D7: pango_itemize_with_base_dir (in /usr/lib64/libpango-1.0.so.0.3600.8)
==31078==    by 0x6579489: ??? (in /usr/lib64/libpango-1.0.so.0.3600.8)
==31078==    by 0x657B277: ??? (in /usr/lib64/libpango-1.0.so.0.3600.8)
==31078==    by 0x5F22FC3: ??? (in /usr/lib64/libpangocairo-1.0.so.0.3600.8)
==31078==    by 0x6576BBF: ??? (in /usr/lib64/libpango-1.0.so.0.3600.8)

==31078== 6,029 (512 direct, 5,517 indirect) bytes in 1 blocks are definitely lost in loss record 7,685 of 7,730
==31078==    at 0x4C2BB4A: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==31078==    by 0x83E2FE9: ??? (in /usr/lib64/libfontconfig.so.1.7.0)
==31078==    by 0x83E37B4: ??? (in /usr/lib64/libfontconfig.so.1.7.0)
==31078==    by 0x83E3BEB: ??? (in /usr/lib64/libfontconfig.so.1.7.0)
==31078==    by 0x83D6F5D: FcDefaultSubstitute (in /usr/lib64/libfontconfig.so.1.7.0)
==31078==    by 0x81BC955: ??? (in /usr/lib64/libpangoft2-1.0.so.0.3600.8)
==31078==    by 0x65710C8: ??? (in /usr/lib64/libpango-1.0.so.0.3600.8)
==31078==    by 0x65722D7: pango_itemize_with_base_dir (in /usr/lib64/libpango-1.0.so.0.3600.8)
==31078==    by 0x6579489: ??? (in /usr/lib64/libpango-1.0.so.0.3600.8)
==31078==    by 0x657B277: ??? (in /usr/lib64/libpango-1.0.so.0.3600.8)
==31078==    by 0x5F22FC3: ??? (in /usr/lib64/libpangocairo-1.0.so.0.3600.8)
==31078==    by 0x6576BBF: ??? (in /usr/lib64/libpango-1.0.so.0.3600.8)

==31078== LEAK SUMMARY:
==31078==    definitely lost: 2,560 bytes in 4 blocks
==31078==    indirectly lost: 14,246 bytes in 587 blocks
==31078==      possibly lost: 65,575 bytes in 958 blocks
==31078==    still reachable: 1,500,670 bytes in 17,881 blocks
==31078==         suppressed: 42,632 bytes in 687 blocks
==31078==
==31078== For counts of detected and suppressed errors, rerun with: -v
==31078== ERROR SUMMARY: 672 errors from 672 contexts (suppressed: 15 from 15)

I'm guessing my program does not leak memory, but it looks like pango does or is missing from the suppression files?

Also compiled with Clang and used the scan-build command no errors reported. Tried to build tartan but seems like an error in the configure some place as it bugs out with: configure: error: LLVM version 3.4 or later needed, the version I have installed is: clang version 3.4.2 (tags/RELEASE_34/dot2-final).

Btw I notice compiling with Clang resulted in a smaller binary 64208 vs 73676 with gcc. Insignificant in my little program but if that's consistent for larger projects hmm.

Thanx for the help.

_________________
RickTee

Distro: Centos 7 Lang: C IDE: NetBeans Desktop: KDE


Top
 Profile  
 
 Post subject: Re: gtk2yarzee game
PostPosted: Fri Jan 15, 2016 7:25 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 971
Location: UK
Yepp, that is the sort of output I would expect from valgrind. If you had a suppression file for Pango that would be almost nothing.

Good to hear that you managed to use the PKG_CHECK_MODULES macro to work. It can do more than just gtk stuff. Anything that would work with pkg-config will work with that macro.

As for the difference between Clang and GCC, there will be some differences. For now GCC tends to produce slightly quicker code than Clang although the difference is small and depends on many conditions.

As for the difference in binary size. Is that the size of the file? what you should measure is the size of the text and data segments. You would you the command on the terminal
Code:
size my_executable
The rest of the file will be symbol tables, debugging information etc. which can be striped if needed. This may be the biggest difference in size.

_________________
E.


Top
 Profile  
 
 Post subject: Re: gtk2yarzee game
PostPosted: Tue Jan 26, 2016 5:07 pm 
Offline
Familiar Face

Joined: Sat Jan 31, 2015 4:16 pm
Posts: 15
Location: Plymouth, Devon
Have ported the game to Gtk3, got rid of all deprecated warnings and i think all the errors errol pointed out, thanx for that. Have added CSS to clarify when a dice is held, trying not to break theming. There is no desktop file or icon, for it to work you will need to run it from the src directory or it won't find the style sheet.


Attachments:
gtkyarzee-1.1.5.tar.gz [158.52 KiB]
Downloaded 7 times

_________________
RickTee

Distro: Centos 7 Lang: C IDE: NetBeans Desktop: KDE
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group