@@ -39,9 +39,15 @@ public int uploadReplaceSection(int oldId, BuiltSection section) {
3939 this .removeSection (oldId );
4040 }
4141 int newId = this .allocation .allocateNext ();
42+ if (newId == -1 ) {
43+ Logger .error ("Allocator full: " +this .allocation .getCount ()+" " +section , new Throwable ());
44+ section .free ();
45+ return -1 ;
46+ }
4247 var entry = new Entry (section .position , section .geometryBuffer .size );
43- if (this .sections .put (newId , entry ) != null ) {
44- throw new IllegalStateException ();
48+ var old = this .sections .put (newId , entry );
49+ if (old != null ) {
50+ throw new IllegalStateException (oldId + "," +newId +" " +old +"," +entry );
4551 }
4652 this .memoryInUse += entry .size ;
4753 section .free ();
@@ -282,22 +288,24 @@ public static void main(String[] args) {
282288 int ITER_COUNT = 5_000 ;
283289 int INNER_ITER_COUNT = 1_000_000 ;
284290 boolean GEO_REM = true ;
291+ boolean LIMIT_REQUEST_SEC_ALLOCATION = true ;
285292
286293 AtomicInteger finished = new AtomicInteger ();
287294 HashSet <List <StackTraceElement >> seenTraces = new HashSet <>();
288295
296+ Logger .SHUTUP_INFO = true ;
289297 Logger .SHUTUP = true ;
290298
291- if (true ) {
299+ if (false ) {
292300 for (int q = 0 ; q < ITER_COUNT ; q ++) {
293301 //Logger.info("Iteration "+ q);
294- if (runTest (INNER_ITER_COUNT , q , seenTraces , GEO_REM )) {
302+ if (runTest (INNER_ITER_COUNT , q , seenTraces , GEO_REM , LIMIT_REQUEST_SEC_ALLOCATION )) {
295303 finished .incrementAndGet ();
296304 }
297305 }
298306 } else {
299307 IntStream .range (0 , ITER_COUNT ).parallel ().forEach (i ->{
300- if (runTest (INNER_ITER_COUNT , i , seenTraces , GEO_REM )) {
308+ if (runTest (INNER_ITER_COUNT , i , seenTraces , GEO_REM , LIMIT_REQUEST_SEC_ALLOCATION )) {
301309 finished .incrementAndGet ();
302310 }
303311 });
@@ -314,7 +322,7 @@ private static long rPos(Random r, LongList tops) {
314322 return WorldEngine .getWorldSectionId (lvl , r .nextInt (bound )+(WorldEngine .getX (top )<<4 ), r .nextInt (bound )+(WorldEngine .getY (top )<<4 ), r .nextInt (bound )+(WorldEngine .getZ (top )<<4 ));
315323 }
316324
317- private static boolean runTest (int ITERS , int testIdx , Set <List <StackTraceElement >> traces , boolean geoRemoval ) {
325+ private static boolean runTest (int ITERS , int testIdx , Set <List <StackTraceElement >> traces , boolean geoRemoval , boolean requestLimiter ) {
318326 Random r = new Random (testIdx * 1234L );
319327 try {
320328 var test = new TestBase ();
@@ -334,7 +342,7 @@ private static boolean runTest(int ITERS, int testIdx, Set<List<StackTraceElemen
334342 //Fuzzy bruteforce everything
335343 for (int x = -R ; x <=R ; x ++) {
336344 for (int z = -R ; z <=R ; z ++) {
337- for (int y = -8 ; y <=7 ; y ++) {
345+ for (int y = -1 ; y <=0 ; y ++) {
338346 tops .add (WorldEngine .getWorldSectionId (4 , x , y , z ));
339347 }
340348 }
@@ -351,28 +359,29 @@ private static boolean runTest(int ITERS, int testIdx, Set<List<StackTraceElemen
351359 long pos = rPos (r , tops );
352360 int op = r .nextInt (5 );
353361 int extra = r .nextInt (256 );
362+ boolean geoAddOk = ((!requestLimiter )||(test .geometryManager .allocation .getLimit ()-test .geometryManager .allocation .getCount ())>1000 );
354363 boolean hasGeometry = r .nextBoolean ();
355364 boolean addRemTLN = r .nextInt (64 ) == 0 ;
356365 boolean extraBool = r .nextBoolean ();
357366 if (op == 0 && addRemTLN ) {
358- pos = WorldEngine .getWorldSectionId (4 , r .nextInt (5 )-2 , r .nextInt (32 )- 16 , r .nextInt (5 )-2 );
367+ pos = WorldEngine .getWorldSectionId (4 , r .nextInt (5 )-2 , r .nextInt (2 )- 1 , r .nextInt (5 )-2 );//r.nextInt(16)-8//for y
359368 boolean cont = tops .contains (pos );
360369 if (cont &&extraBool &&tops .size ()>1 ) {
361370 extraBool = true ;
362371 test .remTopPos (pos );
363372 tops .rem (pos );
364- } else if (!cont ) {
373+ } else if (( !cont )&& geoAddOk ) {
365374 extraBool = false ;
366375 test .putTopPos (pos );
367376 tops .add (pos );
368377 }
369- } else if (op == 0 ) {
378+ } else if (op == 0 && geoAddOk ) {
370379 test .request (pos );
371380 }
372381 if (op == 1 ) {
373382 test .childUpdate (pos , extra );
374383 }
375- if (op == 2 ) {
384+ if (op == 2 &&((! hasGeometry )|| geoAddOk ) ) {
376385 test .meshUpdate (pos , extra , hasGeometry ? 100 : 0 );
377386 }
378387 if (op == 3 && geoRemoval ) {
0 commit comments