diff --git a/src/scheduler.c b/src/scheduler.c index 590c4140..191b2fa4 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -3361,8 +3361,8 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(!strcmp(argv[1], "preview_window")) { if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;} - if(argc == 3) preview_window(argv[2], "{}", "{}"); - else if(argc == 4) preview_window(argv[2], argv[3], "{}"); + if(argc == 3) preview_window(argv[2], "", NULL); + else if(argc == 4) preview_window(argv[2], argv[3], NULL); else if(argc == 5) { char f[PATH_MAX + 100]; my_snprintf(f, S(f),"regsub {^~/} {%s} {%s/}", argv[4], home_dir); diff --git a/src/xinit.c b/src/xinit.c index b330eed5..1058d531 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -1206,7 +1206,7 @@ void preview_window(const char *what, const char *win_path, const char *fname) dbg(1, "preview_window() draw\n"); save_xctx = xctx; /* save current schematic */ xctx = preview_xctx; - if(!current_file || strcmp(fname, current_file) ) { + if(fname && fname[0] && (!current_file || strcmp(fname, current_file)) ) { if(current_file) { delete_schematic_data(1); } @@ -1229,21 +1229,23 @@ void preview_window(const char *what, const char *win_path, const char *fname) xctx = save_xctx; } else if(!strcmp(what, "destroy") || !strcmp(what, "close")) { - dbg(1, "preview_window() destroy\n"); - save_xctx = xctx; /* save current schematic */ - xctx = preview_xctx; - if(current_file) { - delete_schematic_data(1); - preview_xctx = NULL; + dbg(1, "preview_window(): %s\n", what); + if(preview_xctx) { + save_xctx = xctx; /* save current schematic */ + xctx = preview_xctx; + if(current_file) { + delete_schematic_data(1); + preview_xctx = NULL; + } + my_free(_ALLOC_ID_, ¤t_file); + xctx = save_xctx; /* restore schematic */ + save_xctx = NULL; + set_modify(-1); } if(!strcmp(what, "destroy")) { Tk_DestroyWindow(tkpre_window); tkpre_window = NULL; } - my_free(_ALLOC_ID_, ¤t_file); - xctx = save_xctx; /* restore schematic */ - save_xctx = NULL; - set_modify(-1); } tclvareval("restore_ctx ", xctx->current_win_path, NULL); semaphore--;