@@ -13,8 +13,8 @@ namespace RenderEngine
1313{
1414 public sealed class RenderBatch
1515 {
16- public readonly List < float > SolidLineVertices = new ( ) ;
17- public readonly List < float > SolidTriangleVertices = new ( ) ;
16+ public readonly List < float > SolidLineVertices = new ( 8192 ) ;
17+ public readonly List < float > SolidTriangleVertices = new ( 8192 ) ;
1818 public readonly Dictionary < int , List < float > > TexturedBatches = new ( ) ;
1919
2020 public readonly List < Action > HostActions = new ( ) ;
@@ -71,7 +71,8 @@ public void AddTexturedTriangle(
7171 // Grab the list for this specific texture, or create it if it doesn't exist
7272 if ( ! TexturedBatches . TryGetValue ( textureId , out var list ) )
7373 {
74- list = new List < float > ( ) ;
74+ // Pre-allocate the new list!
75+ list = new List < float > ( 4096 ) ;
7576 TexturedBatches [ textureId ] = list ;
7677 }
7778
@@ -104,7 +105,14 @@ public void Clear()
104105 {
105106 SolidLineVertices . Clear ( ) ;
106107 SolidTriangleVertices . Clear ( ) ;
107- TexturedBatches . Clear ( ) ; // Clear the dictionary here
108+
109+ // FIX: Clear the inner lists instead of destroying the dictionary items
110+ foreach ( var list in TexturedBatches . Values )
111+ {
112+ list . Clear ( ) ;
113+ }
114+ // Note: We leave the dictionary keys intact for the next frame!
115+
108116 HostActions . Clear ( ) ;
109117 }
110118
0 commit comments