0

This function will create the file choosers. When I open the first file chooser and select a file everything works fine. When I open any other file chooser afterward the program crashes with a segmentation fault.

void createfilechoosers()
{
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
gint res;
GtkWindow *new_window;
new_window = gtk_window_new(GTK_WINDOW_POPUP);
gwidget.filechoosers = gtk_file_chooser_dialog_new ("Open File", new_window, action, ("_Cancel"), GTK_RESPONSE_CANCEL, ("_Open"), GTK_RESPONSE_ACCEPT, NULL);

res = gtk_dialog_run (GTK_DIALOG (gwidget.filechoosers));
if (res == GTK_RESPONSE_ACCEPT)
  {
   GtkFileChooser *chooser = GTK_FILE_CHOOSER (gwidget.filechoosers);
    location.filenames[location.placement] =  gtk_file_chooser_get_filename (chooser);
  }

gtk_widget_destroy (gwidget.filechoosers);
}

  • Welcome to SO. You should run your program in a debugger. It should show you where the segmentation fault happens. – Gerhardh Apr 21 '20 at 07:26
  • That showed me where it's getting a segmentation fault but doesn't tell me why. i'ts getting a segmentation fault on the line. location.filenames[location.placement] = gtk_file_chooser_get_filename(chooser) – MyLifeIsInYourHands Apr 21 '20 at 09:09
  • That did lead me to figuring it out, thank you, i'll remember to run my programs through the debugger when getting issues like this. – MyLifeIsInYourHands Apr 21 '20 at 09:12
  • Good. You should always do this and tell us where it happened. Also check all variables for valid content when your debugger stops there... – Gerhardh Apr 21 '20 at 09:13

0 Answers0