From bb0af344413b545654b4e1e1c6c5a3335f4eff83 Mon Sep 17 00:00:00 2001 From: Tim Edwards Date: Tue, 23 Oct 2018 08:44:04 -0400 Subject: [PATCH] Corrected an obscure error that causes the background of the layout window to change after hiding a layer using the toolbar and then refreshing the layout. Fixed by saving and restoring the graphics state around the routine that configures the toolbar image. Also added a check to CifPaintCurrent to guard against using an unassigned ClientData record as a pointer (causes a crash), and added braces around "expr" values in the Tcl wrapper, which reportedly results in faster execution of the expression. --- cif/CIFrdcl.c | 8 +++++++- graphics/grTkCommon.c | 11 ++++++++++- tcltk/wrapper.tcl | 12 ++++++------ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/cif/CIFrdcl.c b/cif/CIFrdcl.c index 249db5de..9654af0a 100644 --- a/cif/CIFrdcl.c +++ b/cif/CIFrdcl.c @@ -599,7 +599,13 @@ CIFPaintCurrent() Plane **parray; extern char *(cifReadLayers[MAXCIFRLAYERS]); - if (cifReadCellDef->cd_flags & CDFLATGDS) + /* NOTE: There should be no need to check for cd_client + * here as cd_client should not be CLIENTDEFAULT if CDFLATGDS + * is set in flags. This condition has occurred, though, and + * needs to be debugged. + */ + if ((cifReadCellDef->cd_flags & CDFLATGDS) && + (cifReadCellDef->cd_client != (ClientData)CLIENTDEFAULT)) parray = (Plane **)cifReadCellDef->cd_client; else { diff --git a/graphics/grTkCommon.c b/graphics/grTkCommon.c index 448a1c2b..00850f22 100644 --- a/graphics/grTkCommon.c +++ b/graphics/grTkCommon.c @@ -984,6 +984,8 @@ ImgLayerConfigureInstance(instancePtr) Tk_Window tkwind = instancePtr->tkwin; MagWindow *mw, tmpmw; + int saveStyle; + if (Tk_WindowId(tkwind) == 0) Tk_MakeWindowExist(tkwind); @@ -1106,6 +1108,9 @@ ImgLayerConfigureInstance(instancePtr) GrLock(&tmpmw, FALSE); + /* Save the current state */ + saveStyle = grCurDStyle; + /* First fill with background style */ GrSetStuff(STYLE_ERASEALL); grInformDriver(); @@ -1156,9 +1161,13 @@ ImgLayerConfigureInstance(instancePtr) grInformDriver(); GrDrawGlyphNum(masterPtr->layerLock, 0, 0); } + + /* Restore the original state */ + GrSetStuff(saveStyle); + grInformDriver(); + GrUnlock(&tmpmw); } - return; error: diff --git a/tcltk/wrapper.tcl b/tcltk/wrapper.tcl index 41a1ce5c..cb1f1e73 100644 --- a/tcltk/wrapper.tcl +++ b/tcltk/wrapper.tcl @@ -553,8 +553,8 @@ proc magic::mgrupdate {win {cmdstr ""}} { # Set default width and height to be 3/4 of the screen size. set Opts(geometry) \ -"[expr 3 * [winfo screenwidth .] / 4]x[expr 3 * [winfo screenheight .] \ -/ 4]+100+100" +"[expr {3 * [winfo screenwidth .] / 4}]x[expr {3 * [winfo screenheight .] \ +/ 4}]+100+100" # Procedures for the layout scrollbars, which are made from canvas # objects to avoid the problems associated with Tk's stupid scrollbar @@ -629,8 +629,8 @@ proc magic::cursorview {win} { if {$cr == 0} {return} set olst [${win} cursor internal] - set olstx [expr [lindex $olst 0]] - set olsty [expr [lindex $olst 1]] + set olstx [lindex $olst 0] + set olsty [lindex $olst 1] if {$Opts(crosshair)} { *bypass crosshair ${olstx}i ${olsty}i @@ -638,8 +638,8 @@ proc magic::cursorview {win} { # Use catch, because occasionally this fails on startup if {[catch { - set olstx [expr $olstx * $cr] - set olsty [expr $olsty * $cr] + set olstx [expr {$olstx * $cr}] + set olsty [expr {$olsty * $cr}] }]} {return} if {[${win} box exists]} {