From dec3b6c05d21e9c673cc1d266dac1ea06f217e03 Mon Sep 17 00:00:00 2001 From: Jonathan Wilkes <jon.w.wilkes@gmail.com> Date: Thu, 15 Sep 2016 18:19:33 -0400 Subject: [PATCH] fix #116: segfault after applying preferences change --- pd/src/m_glob.c | 6 +++--- pd/src/s_file.c | 11 ++++++++--- pd/src/s_main.c | 6 ++++-- pd/src/s_stuff.h | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/pd/src/m_glob.c b/pd/src/m_glob.c index dcb2aaefa..d5d411eb7 100644 --- a/pd/src/m_glob.c +++ b/pd/src/m_glob.c @@ -71,16 +71,16 @@ static void glob_perf(t_pd *dummy, float f) sys_perf = (f != 0); } -extern char *sys_gui_preset; +extern t_symbol *sys_gui_preset; static void glob_gui_preset(t_pd *dummy, t_symbol *s) { - sys_gui_preset = s->s_name; + sys_gui_preset = s; } /* just the gui-preset for now */ static void glob_gui_properties(t_pd *dummy) { - gui_vmess("gui_gui_properties", "xs", 0, sys_gui_preset); + gui_vmess("gui_gui_properties", "xs", 0, sys_gui_preset->s_name); } // ths one lives inside g_editor so that it can access the clipboard diff --git a/pd/src/s_file.c b/pd/src/s_file.c index dc4e51e35..a3c46cc10 100644 --- a/pd/src/s_file.c +++ b/pd/src/s_file.c @@ -212,7 +212,8 @@ static void sys_putpreference(const char *key, const char *value) NULL, &hkey, NULL); if (err != ERROR_SUCCESS) { - post("unable to create registry entry: %s\n", key); + post("unable to create registry entry: %s: error %lx\n", key, + (long unsigned int)err); return; } err = RegSetValueEx(hkey, key, 0, REG_EXPAND_SZ, value, strlen(value)+1); @@ -438,7 +439,11 @@ void sys_loadpreferences( void) if (sys_getpreference("defeatrt", prefbuf, MAXPDSTRING)) sscanf(prefbuf, "%d", &sys_defeatrt); if (sys_getpreference("guipreset", prefbuf, MAXPDSTRING)) - sscanf(prefbuf, "%s", &sys_gui_preset); + { + char preset_buf[MAXPDSTRING]; + sscanf(prefbuf, "%s", preset_buf); + sys_gui_preset = gensym(preset_buf); + } if (sys_getpreference("flags", prefbuf, MAXPDSTRING)) { if (strcmp(prefbuf, ".")) @@ -553,7 +558,7 @@ void glob_savepreferences(t_pd *dummy) sys_putpreference("nloadlib", buf1); sprintf(buf1, "%d", sys_defeatrt); sys_putpreference("defeatrt", buf1); - sys_putpreference("guipreset", sys_gui_preset); + sys_putpreference("guipreset", sys_gui_preset->s_name); sys_putpreference("flags", (sys_flags ? sys_flags->s_name : "")); sys_donesavepreferences(); diff --git a/pd/src/s_main.c b/pd/src/s_main.c index 81b4acad1..e6f503167 100644 --- a/pd/src/s_main.c +++ b/pd/src/s_main.c @@ -55,7 +55,7 @@ int sys_unique = 0; /* by default off, prevents multiple instances int sys_legacy = 0; /* by default off, used to enable legacy features, such as offsets in iemgui object positioning */ char *sys_guicmd; -char *sys_gui_preset = "default"; /* name of the gui theme to be used */ +t_symbol *sys_gui_preset; /* name of gui theme to be used */ t_symbol *sys_libdir; t_symbol *sys_guidir; static t_namelist *sys_openlist; @@ -264,6 +264,7 @@ int sys_main(int argc, char **argv) int i, noprefs; sys_externalschedlib = 0; sys_extraflags = 0; + sys_gui_preset = gensym("default"); #ifdef PD_DEBUG fprintf(stderr, "Pd-L2Ork: COMPILED FOR DEBUGGING\n"); #endif @@ -292,7 +293,8 @@ int sys_main(int argc, char **argv) /* send the libdir to the GUI */ gui_vmess("gui_set_lib_dir", "s", sys_libdir->s_name); /* send the name of the gui preset */ - gui_vmess("gui_set_gui_preset", "s", sys_gui_preset); + gui_vmess("gui_set_gui_preset", "s", sys_gui_preset->s_name); + if (sys_openlist) { // send the files to be opened to the GUI. We send them one diff --git a/pd/src/s_stuff.h b/pd/src/s_stuff.h index e8f6881ed..0547f5726 100644 --- a/pd/src/s_stuff.h +++ b/pd/src/s_stuff.h @@ -39,7 +39,7 @@ t_symbol *sys_decodedialog(t_symbol *s); void sys_loadpreferences( void); void sys_savepreferences( void); extern int sys_defeatrt; -extern char *sys_gui_preset; +extern t_symbol *sys_gui_preset; extern t_symbol *sys_flags; /* s_main.c */ -- GitLab