1
Support / Problem with reinitializing
« on: April 25, 2014, 11:01:27 am »
Hallo I have a problem if I want to run my jpct world two times. My initializiation looks like this:
and my jpct class looks like this:
Exception:
Exception in thread "Thread-9" java.lang.NullPointerException
at org.lwjgl.util.glu.MipMap.gluScaleImage(MipMap.java:235)
at org.lwjgl.util.glu.MipMap.gluBuild2DMipmaps(MipMap.java:142)
at org.lwjgl.util.glu.GLU.gluBuild2DMipmaps(GLU.java:384)
at com.threed.jpct.GLBase.convertTexture(GLBase.java:1738)
at com.threed.jpct.GLRenderer.setTextures(GLRenderer.java:1438)
at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:1051)
at com.threed.jpct.World.draw(World.java:2100)
at com.threed.jpct.World.draw(World.java:2011)
at com.threed.jpct.World.draw(World.java:1607)
at at.fhhooe.mc.trafficsim.threeDPerspective.DDDInit$2.run(DDDInit.java:238)
at java.lang.Thread.run(Unknown Source)
I dont know why this is happening because I initialize each time a completely new Instance of the DDDInit class. Or does jpct use a seperate thread which doesn t close?
Please help.
Code: [Select]
public class TestCommand implements IHandler {
DDDInit window = new DDDInit();
@Override
public void addHandlerListener(IHandlerListener handlerListener) {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (!window.isRunning()) {
window.init3D();
}
return null;
}
@Override
public boolean isEnabled() {
return true;
}
@Override
public boolean isHandled() {
return true;
}
@Override
public void removeHandlerListener(IHandlerListener handlerListener) {
// TODO Auto-generated method stub
}
}
and my jpct class looks like this:
Code: [Select]
private void Config() {
// window name
Config.glWindowName = "3D Perspective";
Config.glAvoidTextureCopies = true;
// Config.useMultipleThreads = true;
}
public DDDInit() {
Config();
// is camera positioned
cameraSet = false;
world = new World();
// world light values
world.setAmbientLight(255, 255, 255);
// set init postion of camera
world.getCamera().setPosition(0, 0, distance);
// set fogging
world.setFogging(World.FOGGING_ENABLED);
// fog distance
world.setFogParameters(FOGGING_DISTANCE, FOG_COLOR.getRed(),
FOG_COLOR.getGreen(), FOG_COLOR.getBlue());
// render objects which are within 10000 range
world.setClippingPlanes(0, CLIPPING_DISTANCE);
camera = world.getCamera();
Bundle bundle = FrameworkUtil.getBundle(SimulationView.class);
URL url = FileLocator.find(bundle, new Path("texture"), null);
// load textures
TextureManager.getInstance().addTexture("skyDome",
new Texture(10, 10, Color.blue));
TextureManager.getInstance().addTexture("car.jpg",
new Texture(url, "car.jpg"));
TextureManager.getInstance().addTexture("carGreen",
new Texture(url, "carGreen.jpg"));
TextureManager.getInstance().addTexture("carBlue",
new Texture(url, "carBlue.jpg"));
TextureManager.getInstance().addTexture("carYellow",
new Texture(url, "carYellow.jpg"));
TextureManager.getInstance().addTexture("carRed",
new Texture(url, "carRed.jpg"));
TextureManager.getInstance().addTexture("White",
new Texture(8, 8, Color.white));
TextureManager.getInstance().addTexture("Gray",
new Texture(8, 8, new Color(200, 200, 200)));
TextureManager.getInstance().addTexture("Black",
new Texture(8, 8, Color.BLACK));
TextureManager.getInstance().addTexture("Blue",
new Texture(8, 8, Color.BLUE));
TextureManager.getInstance().addTexture("Underlay",
new Texture(8, 8, Color.GREEN));
// load 3ds file once
url = FileLocator.find(bundle, new Path("3dsObjects"), null);
ThreedsObjects = Loader.load3DS(url, "car.3ds", 1);
SimulationKernel.getInstance().addInputChangedListener(
new ModelInputChangedListener() {
@Override
public void inputChanged(SimulationModel newModel) {
world.removeAllObjects();
listOfRoadSegments = new Vector<RoadSegment>();
listOfAbstractJunctions = new Vector<AbstractJunction>();
vehicleMapping = new TreeMap<Vehicle, Object3D>();
firstTime = true;
worldOffsetX = 0;
worldOffsetY = 0;
underlayPlane = null;
}
});
}
/**
* Initialize the 3D world
*/
public void init3D() {
// app is running
isRunning = true;
// run in seperate thread
try {
Thread run = new Thread(new Runnable() {
@Override
public void run() {
// window size
buffer = new FrameBuffer(800, 600,
FrameBuffer.SAMPLINGMODE_NORMAL);
// hardware renderer
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL);
// draw loop
while (!org.lwjgl.opengl.Display.isCloseRequested()) {
// background color
buffer.clear(java.awt.Color.WHITE);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
// draw HUD
blitString();
buffer.displayGLOnly();
// check for mouse or key event
move();
poll();
if (world != null) {
updateRoadnetwork();
updateVehicles();
}
}
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.dispose();
}
}
If I run my code for the first time I have no Problems but if I close my window and want to reinitialize the same way I get a NullPointerException at world.draw(buffer).Exception:
Exception in thread "Thread-9" java.lang.NullPointerException
at org.lwjgl.util.glu.MipMap.gluScaleImage(MipMap.java:235)
at org.lwjgl.util.glu.MipMap.gluBuild2DMipmaps(MipMap.java:142)
at org.lwjgl.util.glu.GLU.gluBuild2DMipmaps(GLU.java:384)
at com.threed.jpct.GLBase.convertTexture(GLBase.java:1738)
at com.threed.jpct.GLRenderer.setTextures(GLRenderer.java:1438)
at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:1051)
at com.threed.jpct.World.draw(World.java:2100)
at com.threed.jpct.World.draw(World.java:2011)
at com.threed.jpct.World.draw(World.java:1607)
at at.fhhooe.mc.trafficsim.threeDPerspective.DDDInit$2.run(DDDInit.java:238)
at java.lang.Thread.run(Unknown Source)
I dont know why this is happening because I initialize each time a completely new Instance of the DDDInit class. Or does jpct use a seperate thread which doesn t close?
Please help.