Float 2D Array Data Limit

I have a problem with my code where I added 2.25 million numbers to a float 2D array, and depending on the computer the program either does not run or gives a string of errors. I was wondering if there is a way to either fix this problem or find the limit to a 2D float array. Here the errors are:

Exception in thread "ECS" 



java.lang.OutOfMemoryError: GC overhead limit exceeded



	at org.eclipse.jdt.internal.compiler.ast.IntLiteral.buildIntLiteral(IntLiteral.java:54)


	at org.eclipse.jdt.internal.compiler.parser.Parser.consumeToken(Parser.java:9012)


	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:11074)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:11461)
	at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.parseStatements(MethodDeclaration.java:194)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.parseMethods(TypeDeclaration.java:874)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.parse(CompilationUnitResolver.java:550)
	at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1209)
	at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:812)
	at processing.mode.java.pdex.PreprocessingService.makeAST(PreprocessingService.java:644)
	at processing.mode.java.pdex.PreprocessingService.preprocessSketch(PreprocessingService.java:405)
	at processing.mode.java.pdex.PreprocessingService.mainLoop(PreprocessingService.java:130)
	at processing.mode.java.pdex.PreprocessingService$$Lambda$27/807528644.run(Unknown Source)
	at java.lang.Thread.run(Thread.java:748)
Exception in thread "Thread-6" java.lang.OutOfMemoryError: Java heap space
	at processing.mode.java.preproc.PdeLexer.mWS(PdeLexer.java:475)
	at processing.mode.java.preproc.PdeLexer.nextToken(PdeLexer.java:127)
	at antlr.TokenStreamHiddenTokenFilter.consume(TokenStreamHiddenTokenFilter.java:38)
	at antlr.TokenStreamCopyingHiddenTokenFilter.nextToken(TokenStreamCopyingHiddenTokenFilter.java:165)
	at antlr.TokenBuffer.fill(TokenBuffer.java:69)
	at antlr.TokenBuffer.LA(TokenBuffer.java:80)
	at antlr.LLkParser.LA(LLkParser.java:52)
	at processing.mode.java.preproc.PdeRecognizer.unaryExpressionNotPlusMinus(PdeRecognizer.java:7266)
	at processing.mode.java.preproc.PdeRecognizer.unaryExpression(PdeRecognizer.java:7125)
	at processing.mode.java.preproc.PdeRecognizer.multiplicativeExpression(PdeRecognizer.java:6988)
	at processing.mode.java.preproc.PdeRecognizer.additiveExpression(PdeRecognizer.java:6939)
	at processing.mode.java.preproc.PdeRecognizer.shiftExpression(PdeRecognizer.java:6882)
	at processing.mode.java.preproc.PdeRecognizer.relationalExpression(PdeRecognizer.java:6765)
	at processing.mode.java.preproc.PdeRecognizer.equalityExpression(PdeRecognizer.java:6716)
	at processing.mode.java.preproc.PdeRecognizer.andExpression(PdeRecognizer.java:6687)
	at processing.mode.java.preproc.PdeRecognizer.exclusiveOrExpression(PdeRecognizer.java:6658)
	at processing.mode.java.preproc.PdeRecognizer.inclusiveOrExpression(PdeRecognizer.java:6629)
	at processing.mode.java.preproc.PdeRecognizer.logicalAndExpression(PdeRecognizer.java:6600)
	at processing.mode.java.preproc.PdeRecognizer.logicalOrExpression(PdeRecognizer.java:6571)
	at processing.mode.java.preproc.PdeRecognizer.conditionalExpression(PdeRecognizer.java:4209)
	at processing.mode.java.preproc.PdeRecognizer.assignmentExpression(PdeRecognizer.java:1974)
	at processing.mode.java.preproc.PdeRecognizer.expression(PdeRecognizer.java:1302)
	at processing.mode.java.preproc.PdeRecognizer.initializer(PdeRecognizer.java:5743)
	at processing.mode.java.preproc.PdeRecognizer.arrayInitializer(PdeRecognizer.java:5821)
	at processing.mode.java.preproc.PdeRecognizer.initializer(PdeRecognizer.java:5750)
	at processing.mode.java.preproc.PdeRecognizer.arrayInitializer(PdeRecognizer.java:5821)
	at processing.mode.java.preproc.PdeRecognizer.initializer(PdeRecognizer.java:5750)
	at processing.mode.java.preproc.PdeRecognizer.varInitializer(PdeRecognizer.java:2230)
	at processing.mode.java.preproc.PdeRecognizer.variableDeclarator(PdeRecognizer.java:2183)
	at processing.mode.java.preproc.PdeRecognizer.variableDefinitions(PdeRecognizer.java:2128)
	at processing.mode.java.preproc.PdeRecognizer.declaration(PdeRecognizer.java:3251)
	at processing.mode.java.preproc.PdeRecognizer.statement(PdeRecognizer.java:672)
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
	at java.lang.Object.clone(Native Method)
	at sun.java2d.SunGraphics2D.clone(SunGraphics2D.java:309)
	at sun.java2d.SunGraphics2D.create(SunGraphics2D.java:343)
	at javax.swing.JComponent.paint(JComponent.java:1002)
	at javax.swing.JViewport.paint(JViewport.java:728)
	at javax.swing.JComponent.paintChildren(JComponent.java:889)
	at javax.swing.JComponent.paint(JComponent.java:1065)
	at javax.swing.JComponent.paintChildren(JComponent.java:889)
	at javax.swing.JComponent.paint(JComponent.java:1065)
	at javax.swing.JComponent.paintChildren(JComponent.java:889)
	at javax.swing.JComponent.paint(JComponent.java:1065)
	at javax.swing.JComponent.paintChildren(JComponent.java:889)
	at javax.swing.JSplitPane.paintChildren(JSplitPane.java:1047)
	at javax.swing.JComponent.paint(JComponent.java:1065)
	at javax.swing.JComponent.paintToOffscreen(JComponent.java:5210)
	at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1579)
	at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1502)
	at javax.swing.RepaintManager.paint(RepaintManager.java:1272)
	at javax.swing.JComponent._paintImmediately(JComponent.java:5158)
	at javax.swing.JComponent.paintImmediately(JComponent.java:4969)
	at javax.swing.RepaintManager$4.run(RepaintManager.java:831)
	at javax.swing.RepaintManager$4.run(RepaintManager.java:814)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
	at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
	at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:789)
	at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:738)
	at javax.swing.RepaintManager.access$1200(RepaintManager.java:64)
	at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1732)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
1 Like

2.25 million numbers is quite a lot. Do you really need them all in the array at the same time?

Well I’m making a large open world game… I might be able to lower the number, but it would still be large.

What do the numbers represent?

2 Likes

Each number represents a different tile. I know it’s probably not the easiest way, but that’s what I’ve gone with so far.

So you’ve got an ~1600x1600 tile open world? How many tiles fill a screen?

1 Like

Depends, because it’s fullscreen, but each number represents 40*40 pixels.

Hey There!

You could only render / make parts of the array ‘filled’ based where the player is in the world ! I am also assuming you don’t have a way to not draw elements which are not on the screen ? This would down turn a-lot of memory ! As only drawing tiles which are on screen makes it super effective.

A note to add:
I have a drawing technique equipped in my game ( I am also making a tile based game too ! ) and I am only able to max out for a good frame rate at around (100 * 100) tiles which are 32 * 32 pixels big. Using P2D can help out a-lot too.

  • Your map is 64000x64000 pixels, 1600x1600 tiles, 160x160 xtiles, 16x16 regions.
  • A tile is 40x40 pixels.
  • An xtile is a group of 10x10 tiles, or 400x400 pixels. You can use those for deciding what to draw.
  • If your screen is 1600x1200 pixels, then it is 40x30 tiles, or 4x3 xtiles.
  • A region is 100x100 tiles, 10x10xtiles, or 4000x4000 pixels.
  • Your map data is stored in 256 files e.g. region_00x00, region_01x01… region_15x15.

Your loader loads and unloads regions from disk as you move around your map. Because a region is larger than a screen you can have up to 4 regions loaded at once by standing on a corner between them – but no more. Four regions is 40,000 tiles – significantly less than 2.5 million.

Are you using the ptmx or Sprites libraries? You don’t have to roll your own everything unless it is interesting / fun.

Also potentially of interest:

1 Like

Wow! Thanks for the idea!

1 Like

Also I’m not using any libraries, which might not be a good idea… I’ll look at those.

1 Like

I figured I would make my repository public for a while so have a look at my game and maybe my source code parts can help you out best of luck !

HiScapes