ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Ok I have been trying to figure out this issue for a couple of days now and I can't seam to figure it out on my own. Below is the code for a simple image viewer that I am working on. It works alright on my LFS box but when I attempt to use it on my Arch system it gives a segfault. The only diffrence that I can see is that somehow on my LFS system its getting the entire path to the file and on Arch it is only getting the file name for the file being loaded. Also in arch if i supply the full file name path it works correctly. The part in red is where I think the problem is.
Note: Below is not the entire code here is a link to the full source files.
Code:
/* Simple gtk program for displaying images from most formats *
* My goal for this software is to be something very simmilar *
* to the windows image viewer in windows xp. I like how its *
* very minimal disallowing you to make any kind of changes *
* the image. I don't like to immate stuff from windows as *
* much as possible but I found that a simple image viewer *
* was not really around other then iv which allows you to do *
* too much and does not use the GTK libary. *
* I hope this software will become usefull to somone other *
* then me. I welcome any suggestions,feedback,suggestions, or*
* whatever you think may be relevant. *
* Some code is derived from the gtk+ widgest II tutorial *
* located at http://zetcode.com/tutorials *
* *
* You can contact me at treah.blade@gmail.com *
* NOTE: This software is covered under the GPLv3 licence *
* You can obtain a copy of the licence at *
* http://www.gnu.org/licenses/gpl-3.0.txt *
*/
#include"main.h"
#include"functions.h"
int main ( int argc, char *argv[])
{
char buffer[MAX_NAME_SIZE];
GtkWidget *window;
GtkWidget *image;
GError *err = NULL;
GdkPixbuf *prescale;
GdkPixbuf *postscale;
unsigned int width, highth = 0;
gtk_init(&argc, &argv);
/*printf("Number of agurments is %i\n",argc); */
prescale = gdk_pixbuf_new_from_file(argv[1],&err);
if (err != NULL) {
fprintf(stderr,"ERROR: %s\n",err->message);
g_error_free (err);
return 1;
}
memset(buffer,'\0',MAX_NAME_SIZE);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_resizable(GTK_WINDOW(window),1);
width = gdk_pixbuf_get_width (prescale);
highth = gdk_pixbuf_get_height (prescale);
processbarmessage(argv[1],width,highth,buffer);
setsize(&width,&highth);
gtk_window_set_default_size(GTK_WINDOW(window), DEFAULT_WIDTH, DEFAULT_HIGHTH);
/* The below code will check to see if a valid image is loaded
however the error is displayed in the standar error not in
the window manager this needs fixing in the future so errors
are shown properly. This is also why there is a return here
in the future I am hoping to use a dialog */
if ( err != NULL )
{
fprintf(stderr,"ERROR: %s\n",err->message);
g_error_free (err);
return 1;
}
else
{
/* Scale our image to the defined limits */
postscale = gdk_pixbuf_scale_simple(prescale,
width, highth, GDK_INTERP_BILINEAR);
image = gtk_image_new_from_pixbuf(postscale);
gtk_container_add(GTK_CONTAINER(window), image);
gtk_window_set_title(GTK_WINDOW(window),buffer);
}
g_signal_connect_swapped(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), G_OBJECT(window));
gtk_widget_show_all(window);
gtk_main();
return 0;
}
The whole reason I created the function was to deal with having the whole location of the file returned to the title of the window. Seams strange why one system would return the whole file name and another one would not.
Ohh well thank you for tracking down the problem I really do aprciate it, and for making the make file a little more sane. I really should learn a bit more about making proper make files.
I fixed it by adding in a null check. I am not fully happy with the solution that i devised and there is still some dirty hacks to work out but at least its working for now
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.