From bc12591449d491a2ad2105c8549082e4087d08e3 Mon Sep 17 00:00:00 2001
From: Seth Hillbrand <seth@kipro-pcb.com>
Date: Thu, 16 Jan 2025 20:24:14 -0800
Subject: [PATCH] Use proper indexing for board poly

In rare cases the fracture call will reduce the outline count, leading
to crashes when we dereference them.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/19664
---
 3d-viewer/3d_rendering/raytracing/create_scene.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/3d-viewer/3d_rendering/raytracing/create_scene.cpp b/3d-viewer/3d_rendering/raytracing/create_scene.cpp
index abee264f61..4fbef0dea3 100644
--- a/3d-viewer/3d_rendering/raytracing/create_scene.cpp
+++ b/3d-viewer/3d_rendering/raytracing/create_scene.cpp
@@ -433,7 +433,7 @@ void RENDER_3D_RAYTRACE_BASE::Reload( REPORTER* aStatusReporter, REPORTER* aWarn
 
             boardPolyCopy.Fracture();
 
-            for( int ii = 0; ii < outlineCount; ii++ )
+            for( int ii = 0; ii < boardPolyCopy.OutlineCount(); ii++ )
             {
                 ConvertPolygonToBlocks( boardPolyCopy, *m_outlineBoard2dObjects,
                                         m_boardAdapter.BiuTo3dUnits(), divFactor,