From: Darren Eisenzimmer Newsgroups: comp.os.msdos.djgpp Subject: Allegro GUI routines produces a General Protection Fault Date: Wed, 03 May 2000 01:34:54 -0500 Organization: NULL Lines: 138 Message-ID: <390FC88D.99A6B5FF@operamail.com> NNTP-Posting-Host: dial34-113.d.umn.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.d.umn.edu 957335857 12786 131.212.34.113 (3 May 2000 06:37:37 GMT) X-Complaints-To: usenet AT news DOT d DOT umn DOT edu NNTP-Posting-Date: 3 May 2000 06:37:37 GMT X-Mailer: Mozilla 4.05 [en] (Win95; I) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com If there's a more appropriate place to ask allegro questions please let me know. I'm having trouble with the GUI routines. Following is the source I'm having problems with. Specifically, the get_csv_files() function of mine seems to cause the problem. However, it alone is not the problem. Somehow it's not compatible with allegro. I compile with the -Wall -O3 -g switches. The code that I'm posting produces a General Protection Fault on my computer. However, commenting out the get_csv_files() call and it works OK. Any help would be appreciated. Darren ------------- my_gui.c ------------------ #include "allegro.h" #include #include #include #include /* linked list of strings */ struct CSV_LIST { char *file_name; struct CSV_LIST *next; } CSV_LIST; /* recursively destroys linked list */ void destroy_list(struct CSV_LIST *csv_list ) { if( csv_list == NULL ) return; else if( csv_list->next ) destroy_list( csv_list->next ); else { free( csv_list->file_name ); free( csv_list ); } } int num_csv_files; struct CSV_LIST *csv_list; /* Get all .csv files in the current directory and put them in the * linked list structure. Ultimately, these will be displayed to * the user through the GUI dialog procedure list */ void get_csv_files() { DIR *current_dir = opendir("."); struct dirent *dir_entry; char filename[10]; char *token = NULL; struct CSV_LIST *list_trav = NULL; while( (dir_entry = readdir(current_dir)) ) { strcpy(filename, dir_entry->d_name); token = strtok(filename,"."); token = strtok(NULL,"."); if( token ) { if( strcmp(token, "csv") == 0 || strcmp(token, "CSV") == 0 ) { if( csv_list == NULL ) { csv_list = malloc( sizeof(void *) ); list_trav = csv_list; } else { list_trav->next = malloc( sizeof(void *) ); list_trav = list_trav->next; } list_trav->file_name = malloc( sizeof(dir_entry->d_name) ); strcpy( list_trav->file_name, dir_entry->d_name); list_trav->next = NULL; num_csv_files++; } } } closedir(current_dir); } /* Dialog procedure to display all .csv files. Currently the filenames * are hard coded, eventually they will be read from the csv_list structure. */ char *csv_listbox(int index, int *list_size) { char *csv_files[] = { "test1.csv", "test2.csv", "test3.csv" }; if (index < 0) { *list_size = 3; return NULL; } else { return csv_files[index]; } } int main( int argc, char *argv[] ) { struct CSV_LIST *list_trav; DIALOG my_dialog[] = { /* PROCEDURE x y w h fg bg key flags d1 d2 dp dp2 dp3 */ { d_list_proc, 200, 100, 200, 200, 255, 0, 0, 0, 0, 0, csv_listbox, NULL, NULL }, { d_button_proc, 250, 350, 100, 50, 255, 0, 0, D_EXIT, 0, 0, "Exit", NULL, NULL }, { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL } }; /* Initialize global variables */ num_csv_files = 0; csv_list = NULL; get_csv_files(); printf("num_csv_files = %d\n", num_csv_files); for( list_trav = csv_list ; list_trav ; list_trav = list_trav->next ) puts( list_trav->file_name ); getchar(); allegro_init(); install_keyboard(); install_mouse(); install_timer(); set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); set_pallete(desktop_pallete); do_dialog(my_dialog, -1); allegro_exit(); destroy_list( csv_list ); return 1; }