We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there, i'm coding a simple OBJ viewer using PShape. It is fine with models up to 165K polygons, but if I try loading an OBJ with more tha 300K polygons it crashes. Is there any way to handle this? BTW here's the code:
import processing.opengl.*;
import peasy.*;
PeasyCam cam;
PShape model;
float ry;
public void setup() {
size(1280, 720, OPENGL);
model = loadShape("lowResGeo165.obj");
cam = new PeasyCam(this, width);
model.scale(20.0);
}
public void draw() {
background(0);
ambientLight(102, 102, 102);
directionalLight(126, 126, 126, 0, 0, -1);
directionalLight(126, 126, 126, 0, 0, 1);
translate(width/2, height/2 + 100, 0);
rotateZ(PI);
rotateY(ry);
shape(model);
ry = 0;
}
Answers
add after line 11
this will show you whether the loadShape has worked - if it's null then you can check for that. if it throws an exception you can catch that.
we can't test your code - the problem is the obj file which you don't supply...
I'm using the same obj, the lowres one loads fine the hires crashes. Here's the error I'm getting:
java.lang.OutOfMemoryError: GC overhead limit excedeed
java.lang.RuntimeException: java.lang.OutOfMemoryError: GC overhead limit exceeded at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58) at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:103) at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:206) at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172) at javax.media.opengl.Threading.invoke(Threading.java:191) at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:541) at processing.opengl.PJOGL.requestDraw(PJOGL.java:688) at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1651) at processing.core.PApplet.run(PApplet.java:2256) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded at processing.opengl.PGraphicsOpenGL$InGeometry.allocate(PGraphicsOpenGL.java:7164) at processing.opengl.PGraphicsOpenGL$InGeometry.(PGraphicsOpenGL.java:7136) at processing.opengl.PGraphicsOpenGL.newInGeometry(PGraphicsOpenGL.java:6855) at processing.opengl.PShapeOpenGL.(PShapeOpenGL.java:325) at processing.opengl.PGraphics3D.createShapeImpl(PGraphics3D.java:192) at processing.opengl.PShapeOpenGL.createShape3D(PShapeOpenGL.java:580) at processing.opengl.PShapeOpenGL.copyGroup3D(PShapeOpenGL.java:622) at processing.opengl.PShapeOpenGL.createShape3D(PShapeOpenGL.java:575) at processing.opengl.PGraphics3D.loadShapeImpl(PGraphics3D.java:147) at processing.opengl.PGraphicsOpenGL.loadShape(PGraphicsOpenGL.java:3501) at processing.core.PApplet.loadShape(PApplet.java:11651) at obj_viewer_003.setup(obj_viewer_003.java:30) at processing.core.PApplet.handleDraw(PApplet.java:2361) at processing.opengl.PJOGL$PGLListener.display(PJOGL.java:862) at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:665) at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:649) at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1289) at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1119) at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:994) at javax.media.opengl.awt.GLCanvas$11.run(GLCanvas.java:1300) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$200(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
If you need I can provide the obj
Try going to File > Preferences and increasing your maximum available memory.
@amnon, thanks, that worked