Index: /branches/1.3/gui/scripts/flowvisviewer.tcl
===================================================================
--- /branches/1.3/gui/scripts/flowvisviewer.tcl	(revision 5176)
+++ /branches/1.3/gui/scripts/flowvisviewer.tcl	(revision 5177)
@@ -2250,23 +2250,5 @@
     }
 
-    $inner.colormap choices insert end \
-        "BCGYR"              "BCGYR"            \
-        "BGYOR"              "BGYOR"            \
-        "blue"               "blue"             \
-        "blue-to-brown"      "blue-to-brown"    \
-        "blue-to-orange"     "blue-to-orange"   \
-        "blue-to-grey"       "blue-to-grey"     \
-        "green-to-magenta"   "green-to-magenta" \
-        "greyscale"          "greyscale"        \
-        "nanohub"            "nanohub"          \
-        "rainbow"            "rainbow"          \
-        "spectral"           "spectral"         \
-        "ROYGB"              "ROYGB"            \
-        "RYGCB"              "RYGCB"            \
-        "brown-to-blue"      "brown-to-blue"    \
-        "grey-to-blue"       "grey-to-blue"     \
-        "orange-to-blue"     "orange-to-blue"   \
-        "none"               "none"
-
+    $inner.colormap choices insert end [GetColormapList -includeNone]
     $itk_component(colormap) value "BCGYR"
     bind $inner.colormap <<Value>> \
Index: /branches/1.3/gui/scripts/nanovisviewer.tcl
===================================================================
--- /branches/1.3/gui/scripts/nanovisviewer.tcl	(revision 5176)
+++ /branches/1.3/gui/scripts/nanovisviewer.tcl	(revision 5177)
@@ -1771,23 +1771,5 @@
     }
 
-    $inner.colormap choices insert end \
-        "BCGYR"              "BCGYR"            \
-        "BGYOR"              "BGYOR"            \
-        "blue"               "blue"             \
-        "blue-to-brown"      "blue-to-brown"    \
-        "blue-to-orange"     "blue-to-orange"   \
-        "blue-to-grey"       "blue-to-grey"     \
-        "green-to-magenta"   "green-to-magenta" \
-        "greyscale"          "greyscale"        \
-        "nanohub"            "nanohub"          \
-        "rainbow"            "rainbow"          \
-        "spectral"           "spectral"         \
-        "ROYGB"              "ROYGB"            \
-        "RYGCB"              "RYGCB"            \
-        "brown-to-blue"      "brown-to-blue"    \
-        "grey-to-blue"       "grey-to-blue"     \
-        "orange-to-blue"     "orange-to-blue"   \
-        "none"               "none"
-
+    $inner.colormap choices insert end [GetColormapList -includeNone]
     $itk_component(colormap) value "BCGYR"
     bind $inner.colormap <<Value>> \
Index: /branches/1.3/gui/scripts/transferfunctioneditor.tcl
===================================================================
--- /branches/1.3/gui/scripts/transferfunctioneditor.tcl	(revision 5176)
+++ /branches/1.3/gui/scripts/transferfunctioneditor.tcl	(revision 5177)
@@ -146,5 +146,7 @@
 
 itcl::body Rappture::TransferFunctionEditor::destructor {} {
-    $_canvas delete $_name
+    if { [winfo exists $_canvas] } {
+        $_canvas delete $_name
+    }
 }
 
Index: /branches/1.3/gui/scripts/visviewer.tcl
===================================================================
--- /branches/1.3/gui/scripts/visviewer.tcl	(revision 5176)
+++ /branches/1.3/gui/scripts/visviewer.tcl	(revision 5177)
@@ -27,13 +27,13 @@
     set _servers(vtkvis)  "localhost:2010"
 
-    protected variable _serverType "???";# Type of server.
-    protected variable _sid ""      ;   # socket connection to server
     private common _done            ;   # Used to indicate status of send.
     private variable _buffer        ;   # buffer for incoming/outgoing commands
+    private variable _blockOnWrite 0;   # Should writes to socket block?
     private variable _initialized
     private variable _isOpen 0
     private variable _afterId -1
     private variable _icon 0
-
+    private variable _trace 0        ;    # Protocol tracing for console
+    private variable _logging 0      ;    # Command logging to file
     # Number of milliseconds to wait before idle timeout.  If greater than 0,
     # automatically disconnect from the visualization server when idle timeout
@@ -43,10 +43,10 @@
     #private variable _idleTimeout 0;       # No timeout
 
+    protected variable _serverType "???";# Type of server.
+    protected variable _sid ""      ;   # socket connection to server
     protected variable _maxConnects 100
     protected variable _outbuf       ;    # buffer for outgoing commands
     protected variable _buffering 0
-
-    private variable _logging 0
-
+    protected variable _cmdSeq 0     ;    # Command sequence number
     protected variable _dispatcher "";  # dispatcher for !events
     protected variable _hosts ""    ;   # list of hosts for server
@@ -68,17 +68,16 @@
     }
     # Used internally only.
-    private method Shuffle { servers }
+    private method BuildConsole {}
+    private method DebugConsole {}
+    private method HideConsole {}
     private method ReceiveHelper {}
-    private method ServerDown {}
+    private method SendDebugCommand {}
     private method SendHelper {}
     private method SendHelper.old {}
+    private method ServerDown {}
+    private method Shuffle { servers }
+    private method TraceComm { channel {data {}} }
     private method WaitDialog { state }
-
-    protected method ToggleConsole {}
-    private method DebugConsole {}
-    private method BuildConsole {}
-    private method HideConsole {}
-    private method TraceComm { channel {data {}} }
-    private method SendDebugCommand {}
+    private method Waiting { option widget }
 
     protected method CheckConnection {}
@@ -86,4 +85,5 @@
     protected method ColorsToColormap { colors }
     protected method Connect { servers }
+    protected method DisableWaitDialog {}
     protected method Disconnect {}
     protected method EnableWaitDialog { timeout }
@@ -97,5 +97,6 @@
     protected method ReceiveEcho { channel {data ""} }
     protected method SendBytes { bytes }
-    protected method SendCmd {string}
+    protected method SendCmd { string }
+    protected method SendData { bytes }
     protected method SendEcho { channel {data ""} }
     protected method StartBufferingCommands {}
@@ -103,6 +104,5 @@
     protected method StopBufferingCommands {}
     protected method StopWaiting {}
-
-    private method Waiting { option widget }
+    protected method ToggleConsole {}
 
     private proc CheckNameList { namelist }  {
@@ -203,4 +203,7 @@
         }
     }
+    if { [info exists env(VISTRACE)] } {
+        set _trace 1
+    }
     eval itk_initialize $args
 }
@@ -284,5 +287,5 @@
         if { [gets $_sid data] <= 0 } {
             set _sid ""
-            puts stderr "reading from server"
+            puts stderr "ERORR reading from server data=($data)"
             RemoveServerFromList $_serverType $server
             continue
@@ -320,4 +323,5 @@
     set _buffer(in) ""
     set _outbuf ""
+    set _cmdSeq 0
 }
 
@@ -400,4 +404,5 @@
     puts -nonewline $_sid $_buffer(out)
     flush $_sid
+    set _buffer(out) ""
     set _done($this) 1;                 # Success
 }
@@ -453,6 +458,9 @@
     # before sending anything.
     set _done($this) 1
+    if {$_trace && $_buffer(out) != ""} {
+        puts stderr "ERROR: re-entered SendBytes: buffer=([string range $_buffer(out) 0 70]...)"
+        puts stderr "New cmd $_cmdSeq: [string range $bytes 0 70]..."
+    }
     set _buffer(out) $bytes
-
     # There's problem when the user is interacting with the GUI at the
     # same time we're trying to write to the server.  Don't want to
@@ -460,10 +468,20 @@
     # by putting a busy window over plot so that inadvertent things like
     # mouse movements aren't received.
-
-    blt::busy hold $itk_component(main)
-    fileevent $_sid writable [itcl::code $this SendHelper]
-    tkwait variable ::Rappture::VisViewer::_done($this)
-    blt::busy release $itk_component(main)
-
+    if {$_blockOnWrite} {
+        # Let's try this approach: allow a write to block so we don't
+        # re-enter SendBytes
+        SendHelper
+    } else {
+        # This can cause us to re-enter SendBytes during the tkwait, which
+        # is not safe because the _buffer will be clobbered
+        if { [info exists itk_component(main)] } {
+            blt::busy hold $itk_component(main) -cursor ""
+        }
+        fileevent $_sid writable [itcl::code $this SendHelper]
+        tkwait variable ::Rappture::VisViewer::_done($this)
+        if { [info exists itk_component(main)] } {
+            blt::busy release $itk_component(main)
+        }
+    }
     set _buffer(out) ""
     if { [IsConnected] } {
@@ -503,4 +521,8 @@
 }
 
+itcl::body Rappture::VisViewer::DisableWaitDialog {} {
+    set _waitTimeout 0
+}
+
 #
 # ReceiveBytes --
@@ -553,4 +575,7 @@
     if { [string compare -length 3 $line "nv>"] == 0 } {
         ReceiveEcho <<line $line
+        if ($_trace) {
+            puts stderr "<<[string range $line 0 70]"
+        }
         append _buffer(in) [string range $line 3 end]
         append _buffer(in) "\n"
@@ -815,6 +840,10 @@
 # ----------------------------------------------------------------------
 itcl::body Rappture::VisViewer::SendDebugCommand {} {
+    incr _cmdSeq
     set cmd [$itk_component(command) get]
     append cmd "\n"
+    if {$_trace} {
+        puts stderr "$_cmdSeq>>[string range $cmd 0 70]"
+    }
     SendBytes $cmd
     $itk_component(command) delete 0 end
@@ -1178,9 +1207,12 @@
 # SendCmd
 #
-#       Send commands off to the rendering server.  If we're currently
-#       sending data objects to the server, buffer the commands to be
-#       sent later.
+#       Send command off to the rendering server.  If we're currently
+#       buffering, the command is queued to be sent later.
 #
 itcl::body Rappture::VisViewer::SendCmd {string} {
+    incr _cmdSeq
+    if {$_trace} {
+        puts stderr "$_cmdSeq>>[string range $string 0 70]"
+    }
     if { $_buffering } {
         append _outbuf $string "\n"
@@ -1189,2 +1221,19 @@
     }
 }
+
+#
+# SendData
+#
+#       Send data off to the rendering server.  If we're currently
+#       buffering, the data is queued to be sent later.
+#
+itcl::body Rappture::VisViewer::SendData {bytes} {
+    if {$_trace} {
+        puts stderr "$_cmdSeq>>data payload"
+    }
+    if { $_buffering } {
+        append _outbuf $bytes
+    } else {
+        SendBytes $bytes
+    }
+}
Index: /branches/1.3/gui/scripts/vtkglyphviewer.tcl
===================================================================
--- /branches/1.3/gui/scripts/vtkglyphviewer.tcl	(revision 5176)
+++ /branches/1.3/gui/scripts/vtkglyphviewer.tcl	(revision 5177)
@@ -1565,5 +1565,10 @@
     if { $_currentColormap != ""  } {
         set cmap $_currentColormap
-        SendCmd "legend $cmap $_colorMode $_curFldName {} $w $h 0"
+        if { ![info exists _colormaps($cmap)] } {
+            BuildColormap $cmap
+            set _colormaps($cmap) 1
+        }
+        #SendCmd "legend $cmap $_colorMode $_curFldName {} $w $h 0"
+        SendCmd "legend2 $cmap $w $h"
     }
 }
Index: /branches/1.3/gui/scripts/vtkheightmapviewer.tcl
===================================================================
--- /branches/1.3/gui/scripts/vtkheightmapviewer.tcl	(revision 5176)
+++ /branches/1.3/gui/scripts/vtkheightmapviewer.tcl	(revision 5177)
@@ -139,8 +139,8 @@
     private variable _changed
     private variable _initialStyle "";  # First found style in dataobjects.
-    private variable _reset 1;          # Indicates if camera needs to be reset
-                                        # to starting position.
-    private variable _beforeConnect 1;  # Indicates if camera needs to be reset
-                                        # to starting position.
+    private variable _reset 1;          # Indicates if the connection to the 
+                                        # render server was reset
+    private variable _beforeConnect 1;  # Indicates if we are in the constructor
+                                        # before the server connection is made
 
     private variable _first ""     ;    # This is the topmost dataset.
@@ -1019,5 +1019,5 @@
         }
     }
-    if { $_first != ""  } {
+    if { $_first != "" } {
         $itk_component(field) choices delete 0 end
         $itk_component(fieldmenu) delete 0 end
@@ -1055,8 +1055,11 @@
 
         foreach axis { x y z } {
-            if { $axis == "z" } {
-                set label [$_first hints label]
-            } else {
-                set label [$_first hints ${axis}label]
+            set label ""
+            if { $_first != "" } {
+                if { $axis == "z" } {
+                    set label [$_first hints label]
+                } else {
+                    set label [$_first hints ${axis}label]
+                }
             }
             if { $label == "" } {
@@ -1075,15 +1078,20 @@
 
             set units ""
-            if {$axis == "z" && [$_first hints ${axis}units] == ""} {
-                if {$_curFldName != ""} {
+            if { $_first != "" } {
+                if { $axis == "z" } {
+                    set units [$_first hints units]
+                } else {
+                    set units [$_first hints ${axis}units]
+                }
+            }
+            if { $units == "" && $axis == "z" } {
+                if { $_first != "" && [$_first hints zunits] != "" } {
+                    set units [$_first hints zunits]
+                } elseif { [info exists _fields($_curFldName)] } {
                     set units [lindex $_fields($_curFldName) 1]
                 }
-            } else {
-                set units [$_first hints ${axis}units]
-            }
-            if { $units != "" } {
-                # May be a space in the axis units.
-                SendCmd [list axis units $axis $units]
-            }
+            }
+            # May be a space in the axis units.
+            SendCmd [list axis units $axis $units]
         }
         #
@@ -1462,5 +1470,8 @@
                 return
             }
-            set label [$_first hints label]
+            set label ""
+            if { $_first != "" } {
+                set label [$_first hints label]
+            }
             if { $label == "" } {
                 if { [string match "component*" $_curFldName] } {
@@ -1473,13 +1484,17 @@
             SendCmd [list axis name z $label]
 
-            if { [$_first hints zunits] == "" } {
-                set units [lindex $_fields($_curFldName) 1]
-            } else {
-                set units [$_first hints zunits]
-            }
-            if { $units != "" } {
-                # May be a space in the axis units.
-                SendCmd [list axis units z $units]
-            }
+            set units ""
+            if { $_first != "" } {
+                set units [$_first hints units]
+            }
+            if { $units == "" } {
+                if { $_first != "" && [$_first hints zunits] != "" } {
+                    set units [$_first hints zunits]
+                } elseif { [info exists _fields($_curFldName)] } {
+                    set units [lindex $_fields($_curFldName) 1]
+                }
+            }
+            # May be a space in the axis units.
+            SendCmd [list axis units z $units]
             # Get the new limits because the field changed.
             ResetAxes
@@ -1721,4 +1736,8 @@
     if { $_currentColormap != ""  } {
         set cmap $_currentColormap
+        if { ![info exists _colormaps($cmap)] } {
+           BuildColormap $cmap
+           set _colormaps($cmap) 1
+        }
         #SendCmd "legend $cmap scalar $_curFldName {} $w $h 0"
         SendCmd "legend2 $cmap $w $h"
Index: /branches/1.3/gui/scripts/vtkimageviewer.tcl
===================================================================
--- /branches/1.3/gui/scripts/vtkimageviewer.tcl	(revision 5176)
+++ /branches/1.3/gui/scripts/vtkimageviewer.tcl	(revision 5177)
@@ -1558,6 +1558,11 @@
     # Set the legend on the first image dataset.
     if { $_currentColormap != "" && $_currentColormap != "none" } {
-        #SendCmd "legend $_currentColormap scalar $_curFldName {} $w $h 0"
-        SendCmd "legend2 $_currentColormap $w $h"
+        set cmap $_currentColormap
+        if { ![info exists _colormaps($cmap)] } {
+            BuildColormap $cmap
+            set _colormaps($cmap) 1
+        }
+        #SendCmd "legend $cmap scalar $_curFldName {} $w $h 0"
+        SendCmd "legend2 $cmap $w $h"
     }
 }
Index: /branches/1.3/gui/scripts/vtkisosurfaceviewer.tcl
===================================================================
--- /branches/1.3/gui/scripts/vtkisosurfaceviewer.tcl	(revision 5176)
+++ /branches/1.3/gui/scripts/vtkisosurfaceviewer.tcl	(revision 5177)
@@ -1690,5 +1690,10 @@
     if { $_currentColormap != ""  } {
         set cmap $_currentColormap
-        SendCmd "legend $cmap scalar $_curFldName {} $w $h 0"
+        if { ![info exists _colormaps($cmap)] } {
+            BuildColormap $cmap
+            set _colormaps($cmap) 1
+        }
+        #SendCmd "legend $cmap scalar $_curFldName {} $w $h 0"
+        SendCmd "legend2 $cmap $w $h"
     }
 }
Index: /branches/1.3/gui/scripts/vtksurfaceviewer.tcl
===================================================================
--- /branches/1.3/gui/scripts/vtksurfaceviewer.tcl	(revision 5176)
+++ /branches/1.3/gui/scripts/vtksurfaceviewer.tcl	(revision 5177)
@@ -1476,5 +1476,10 @@
     if { $_currentColormap != ""  } {
         set cmap $_currentColormap
-        SendCmd "legend $cmap scalar $_curFldName {} $w $h 0"
+        if { ![info exists _colormaps($cmap)] } {
+            BuildColormap $cmap
+            set _colormaps($cmap) 1
+        }
+        #SendCmd "legend $cmap scalar $_curFldName {} $w $h 0"
+        SendCmd "legend2 $cmap $w $h"
     }
 }
Index: /branches/1.3/gui/scripts/vtkviewer.tcl
===================================================================
--- /branches/1.3/gui/scripts/vtkviewer.tcl	(revision 5176)
+++ /branches/1.3/gui/scripts/vtkviewer.tcl	(revision 5177)
@@ -1788,5 +1788,6 @@
         foreach {dataobj comp} [split $dataset -] break
         if { [info exists _dataset2style($dataset)] } {
-            SendCmd "legend $_dataset2style($dataset) vmag {} {} $w $h 0"
+            #SendCmd "legend $_dataset2style($dataset) vmag {} {} $w $h 0"
+            SendCmd "legend2 $_dataset2style($dataset) $w $h"
             break;
         }
Index: /branches/1.3/gui/scripts/vtkvolumeviewer.tcl
===================================================================
--- /branches/1.3/gui/scripts/vtkvolumeviewer.tcl	(revision 5176)
+++ /branches/1.3/gui/scripts/vtkvolumeviewer.tcl	(revision 5177)
@@ -1465,6 +1465,6 @@
         foreach {dataobj comp} [split $dataset -] break
         if { [info exists _dataset2style($dataset)] } {
-            SendCmd \
-                "legend $_dataset2style($dataset) $_colorMode $_curFldName {} $w $h 0"
+            #SendCmd "legend $_dataset2style($dataset) $_colorMode $_curFldName {} $w $h 0"
+            SendCmd "legend2 $_dataset2style($dataset) $w $h"
             break;
         }
@@ -1623,21 +1623,5 @@
         Rappture::Combobox $inner.palette -width 10 -editable no
     }
-    $inner.palette choices insert end \
-        "BCGYR"              "BCGYR"            \
-        "BGYOR"              "BGYOR"            \
-        "blue"               "blue"             \
-        "blue-to-brown"      "blue-to-brown"    \
-        "blue-to-orange"     "blue-to-orange"   \
-        "blue-to-grey"       "blue-to-grey"     \
-        "green-to-magenta"   "green-to-magenta" \
-        "greyscale"          "greyscale"        \
-        "nanohub"            "nanohub"          \
-        "rainbow"            "rainbow"          \
-        "spectral"           "spectral"         \
-        "ROYGB"              "ROYGB"            \
-        "RYGCB"              "RYGCB"            \
-        "brown-to-blue"      "brown-to-blue"    \
-        "grey-to-blue"       "grey-to-blue"     \
-        "orange-to-blue"     "orange-to-blue"   
+    $inner.colormap choices insert end [GetColormapList]
 
     $itk_component(palette) value "BCGYR"
