1
\$\begingroup\$

When drawing a circle using the ShapeRenderer and using a really big radius (in millions, planet/sun size, given in metres) libgdx throws an exception

Exception in thread "LWJGL Application" java.lang.ArrayIndexOutOfBoundsException: 20003
    at com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20.color(ImmediateModeRenderer20.java:116)
    at com.badlogic.gdx.graphics.glutils.ShapeRenderer.circle(ShapeRenderer.java:880)
    at com.badlogic.gdx.graphics.glutils.ShapeRenderer.circle(ShapeRenderer.java:844)
    at com.kacpr.solar.system.Planet.draw(Planet.java:74)
    at com.kacpr.solar.system.SolarSystem.render(SolarSystem.java:66)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:223)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)

This didn't happen when I used smaller values. The question I have is whether I'm doing something wrong using such high numbers for a radius and should scale this down before drawing (I use this radius for some other calculations) or is this a bug?

\$\endgroup\$
2
\$\begingroup\$

The number of segments used to draw a circle is something like 6 × cube root (radius). This means for a sufficiently large radius you will break the number of allocated vertices in the ShapeRenderer, which is defaulted to 5000 I think.

One approach could be to scale everything down by some factor before drawing it. Another approach would be to use the other overload of circle that accept an argument that indicates the number of segments to use and tweak that value.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.