From 9aa10a6daae17a989aeed90028f9f89db5418c86 Mon Sep 17 00:00:00 2001
From: Eric Mehl <eric@thinkhypothetical.com>
Date: Mon, 16 Dec 2024 16:18:38 -0500
Subject: [PATCH] VisualiserTool : Fix OpenGL buffer creation

When conforming the `VisualiserTool` code, we moved to using Cortex's
OpenGL buffer creation. This was done before checking the data type
of the primitive variable being visualised. This meant that we could
ask OpenGL to convert incompatible data to a buffer, such as string
data.
---
 Changes.md                           |  5 +++--
 src/GafferSceneUI/VisualiserTool.cpp | 12 ++++++------
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/Changes.md b/Changes.md
index 1e14d66dc3..04ab9c9048 100644
--- a/Changes.md
+++ b/Changes.md
@@ -9,8 +9,9 @@ Improvements
 Fixes
 -----
 
-- VisualiserTool : Fixed bug where the value dragged from the visualiser would be slightly different from the initial value on button press. (#6191)
-
+- VisualiserTool :
+  - Fixed bug where the value dragged from the visualiser would be slightly different from the initial value on button press. (#6191)
+  - Fixed error when trying to visualise data unsupported data.
 
 1.5.2.0 (relative to 1.5.1.0)
 =======
diff --git a/src/GafferSceneUI/VisualiserTool.cpp b/src/GafferSceneUI/VisualiserTool.cpp
index ce24671ff3..68f647c785 100644
--- a/src/GafferSceneUI/VisualiserTool.cpp
+++ b/src/GafferSceneUI/VisualiserTool.cpp
@@ -413,12 +413,6 @@ class VisualiserGadget : public Gadget
 						continue;
 					}
 
-					IECoreGL::ConstBufferPtr vBuffer = meshGL->getVertexBuffer( name );
-					if( !vBuffer )
-					{
-						continue;
-					}
-
 					ConstDataPtr vData = vIt->second.data;
 					GLsizei stride = 0;
 					GLenum type = GL_FLOAT;
@@ -452,6 +446,12 @@ class VisualiserGadget : public Gadget
 							continue;
 					}
 
+					IECoreGL::ConstBufferPtr vBuffer = meshGL->getVertexBuffer( name );
+					if( !vBuffer )
+					{
+						continue;
+					}
+
 					// Get the object to world transform
 
 					M44f o2w;