Question

While I was starting to build up a 3D model using Netlogo, firstly I changed the 3D model settings to 2000*2000*500, the size I need. Then I wrote a very simple code for testing.

breed [airs air]

to setup
  clear-all
  create-airs 1 [
    set color pink
    setxyz 1000 1000 250
    set heading 0
    set pitch 0
  ]
end  

Then I tried to run the setup command, runtime error came out.

error (ArrayIndexOutOfBoundsException)
 while observer running CREATE-AIRS
  called by procedure SETUP
  called by Button 'setup'

NetLogo is unable to supply you with more details about this error.  Please report the problem
at https://github.com/NetLogo/NetLogo/issues, or to bugs@ccl.northwestern.edu, and paste the
contents of this window into your report.

java.lang.ArrayIndexOutOfBoundsException: 2006002500
 at org.nlogo.agent.World3D.getPatchAtWrap(World3D.java:159)
 at org.nlogo.agent.Turtle3D.getPatchHere(Turtle3D.java:183)
 at org.nlogo.agent.Turtle3D.<init>(Turtle3D.java:88)
 at org.nlogo.agent.Turtle3D.<init>(Turtle3D.java:62)
 at org.nlogo.agent.World3D.createTurtle(World3D.java:401)
 at org.nlogo.prim._createturtles.perform(_createturtles.java:51)
 at org.nlogo.nvm.Context.stepConcurrent(Context.java:91)
 at org.nlogo.nvm.ConcurrentJob.step(ConcurrentJob.java:82)
 at org.nlogo.job.JobThread.org$nlogo$job$JobThread$$runPrimaryJobs(JobThread.scala:143)
 at org.nlogo.job.JobThread$$anonfun$run$1.apply$mcV$sp(JobThread.scala:78)
 at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76)
 at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76)
 at scala.util.control.Exception$Catch.apply(Exception.scala:88)
 at org.nlogo.util.Exceptions$.handling(Exceptions.scala:41)
 at org.nlogo.job.JobThread.run(JobThread.scala:75)

NetLogo 3D 5.0.5
main: org.nlogo.app.AppFrame
thread: JobThread
Java HotSpot(TM) Server VM 1.6.0_45 (Sun Microsystems Inc.; 1.6.0_45-b06)
operating system: Windows 8 6.2 (x86 processor)
Scala version 2.9.2
JOGL: 1.1.1
OpenGL graphics: Intel(R) HD Graphics 4400
OpenGL version: 4.2.0 - Build 10.18.10.3316
OpenGL vendor: Intel
model: airsimul

03:53:42.404 SwitchedTabsEvent (org.nlogo.app.Tabs) AWT-EventQueue-0
03:53:42.400 RuntimeErrorEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
03:53:42.392 JobRemovedEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) JobThread
03:53:42.391 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
03:53:42.391 TickStateChangeEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) JobThread
03:53:42.391 OutputEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
03:53:42.386 AddJobEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0
03:53:42.261 InputBoxLoseFocusEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0
03:53:42.212 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
03:53:42.011 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0

Can anyone please tell me what this is about?

Was it helpful?

Solution

See How to model a very large world in NetLogo?, http://ccl.northwestern.edu/netlogo/docs/faq.html#howbig, and re: Windows specifically, https://github.com/NetLogo/NetLogo/issues/423.

(Though I'm unable to account for why you're getting ArrayIndexOutOfBoundsException rather than the OutOfMemoryError I would expect. Did you get the latter before you got the former?)

Memory usage in NetLogo is proportional to the number of agents. How many patches are in your world? Your statement about your world size is a bit ambiguous. If you fire up NetLogo and type in 2000, 2000, and 500 into the dialog, the resulting world is 4001 * 4001 * 1001, since the numbers you enter are maximums but patch coordinates can be negative, too.

4001 * 4001 * 1001 is 16 billion patches. By default, NetLogo's heap size is 1 GB. I experimented just now and found I can have roughly 2 million patches in that amount of memory. (And that's not trying to do anything with the patches but create them in the first place; actually doing anything with them would require additional memory. How much would depend on what I was doing.)

If one gigabyte of RAM holds roughly 2 million patches, then to have 16 billion patches, you're going to need eight terabytes of RAM. In other words, the size you are trying for is wildly unrealistic.

Update:

On the question of why you got ArrayIndexOutOfBoundsException instead of OutOfMemoryError, I have a theory now.

In NetLogo the patches are stored in a big array. On the JVM, an array can't have more than 2147483647 (~2.1 billion) elements, because array indices are signed 32-bit integers. When NetLogo 3D creates the patches array, it does new Patch[worldWidth * worldHeight * worldDepth]. Because the JVM doesn't detect overflow on integer operations, you can get a wrong answer, for example in Java 2000 * 2000 * 8000 equals 1935228928 (?!). If the world dimensions you're trying to create are huge enough, integer overflow could cause NetLogo to compute an incorrect size for the patch array. Creation of the patch array could then succeed, but some attempts to access patches would fail with ArrayIndexOutOfBoundsException, since the array is too small for the provided world dimensions.

Note that this will only happen if the world size you are trying for is way beyond the realm of the possible, though. 2.1 billion patches would require roughly a terabyte of RAM, and that's not going to work regardless of whether you're using a 32-bit or 64-bit launcher.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top