Problem with reinitializing

Started by miron123, April 25, 2014, 11:01:27 AM

Previous topic - Next topic

miron123

Hallo I have a problem if I want to run my jpct world two times. My initializiation looks like this:
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:
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.

EgonOlsen

No, jPCT doesn't spawn any threads for this. Looks like a missing context or display. Try to add a Display.destroy(); at the end of the run method. If that doesn't help, please post the complete log.

miron123

After I used Display.destroy() the Exception changed:

java.lang.IllegalStateException: Only one LWJGL context may be instantiated at any one time.
   at org.lwjgl.opengl.Display.create(Display.java:819)
   at org.lwjgl.opengl.Display.create(Display.java:757)
   at com.threed.jpct.GLHelper.init(GLHelper.java:208)
   at com.threed.jpct.GLRenderer.init(GLRenderer.java:24)
   at com.threed.jpct.FrameBuffer.enableRenderer(FrameBuffer.java:1134)
   at com.threed.jpct.FrameBuffer.enableRenderer(FrameBuffer.java:753)
   at com.threed.jpct.FrameBuffer.enableRenderer(FrameBuffer.java:700)
   at at.fhhooe.mc.trafficsim.threeDPerspective.DDDInit$2.run(DDDInit.java:234)
   at java.lang.Thread.run(Unknown Source)

But still no clue why

EgonOlsen

As said, please post the complete log and not just the exception.

miron123

Which logs do you mean? The jpct console statments or a specific exception log or ...?

EgonOlsen


miron123

Sorry for the delay.

First time:
Loading Texture...from Image
Loading Texture...car.jpg
[ Sat Apr 26 15:01:22 CEST 2014 ] - WARNING: Unsupported Texture width (400)...resizing to a width of 256 pixels!
Loading Texture...carGreen.jpg
[ Sat Apr 26 15:01:22 CEST 2014 ] - WARNING: Unsupported Texture width (400)...resizing to a width of 256 pixels!
Loading Texture...carBlue.jpg
[ Sat Apr 26 15:01:22 CEST 2014 ] - WARNING: Unsupported Texture width (400)...resizing to a width of 256 pixels!
Loading Texture...carYellow.jpg
[ Sat Apr 26 15:01:22 CEST 2014 ] - WARNING: Unsupported Texture width (400)...resizing to a width of 256 pixels!
Loading Texture...carRed.jpg
[ Sat Apr 26 15:01:22 CEST 2014 ] - WARNING: Unsupported Texture width (400)...resizing to a width of 256 pixels!
Loading file car.3ds
File car.3ds loaded...10251 bytes
Processing new material carcar.jpg!
Processing object from 3DS-file: Car
Object 'Car_jPCT0' created using 362 polygons and 316 vertices.
could not load 'loading.png'
[ Sat Apr 26 15:01:34 CEST 2014 ] - ERROR: A texture with the name 'skyDome' has been declared twice!
Loading Texture...car.jpg
[ Sat Apr 26 15:01:34 CEST 2014 ] - WARNING: Unsupported Texture width (400)...resizing to a width of 256 pixels!
[ Sat Apr 26 15:01:34 CEST 2014 ] - ERROR: A texture with the name 'car.jpg' has been declared twice!
Loading Texture...carGreen.jpg
[ Sat Apr 26 15:01:34 CEST 2014 ] - WARNING: Unsupported Texture width (400)...resizing to a width of 256 pixels!
[ Sat Apr 26 15:01:34 CEST 2014 ] - ERROR: A texture with the name 'carGreen' has been declared twice!
Loading Texture...carBlue.jpg
[ Sat Apr 26 15:01:34 CEST 2014 ] - WARNING: Unsupported Texture width (400)...resizing to a width of 256 pixels!
[ Sat Apr 26 15:01:34 CEST 2014 ] - ERROR: A texture with the name 'carBlue' has been declared twice!
Loading Texture...carYellow.jpg
[ Sat Apr 26 15:01:34 CEST 2014 ] - WARNING: Unsupported Texture width (400)...resizing to a width of 256 pixels!
[ Sat Apr 26 15:01:34 CEST 2014 ] - ERROR: A texture with the name 'carYellow' has been declared twice!
Loading Texture...carRed.jpg
[ Sat Apr 26 15:01:34 CEST 2014 ] - WARNING: Unsupported Texture width (400)...resizing to a width of 256 pixels!
[ Sat Apr 26 15:01:34 CEST 2014 ] - ERROR: A texture with the name 'carRed' has been declared twice!
[ Sat Apr 26 15:01:34 CEST 2014 ] - ERROR: A texture with the name 'White' has been declared twice!
[ Sat Apr 26 15:01:34 CEST 2014 ] - ERROR: A texture with the name 'Gray' has been declared twice!
[ Sat Apr 26 15:01:34 CEST 2014 ] - ERROR: A texture with the name 'Black' has been declared twice!
[ Sat Apr 26 15:01:34 CEST 2014 ] - ERROR: A texture with the name 'Blue' has been declared twice!
[ Sat Apr 26 15:01:34 CEST 2014 ] - ERROR: A texture with the name 'Underlay' has been declared twice!
Loading file car.3ds
File car.3ds loaded...10251 bytes
Processing new material carcar.jpg!
Processing object from 3DS-file: Car
Object 'Car_jPCT3' created using 362 polygons and 316 vertices.
Java version is: 1.7.0_17
-> support for BufferedImage
Version helper for 1.5+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Software renderer disposed
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Created new Object3D 8
Created new Object3D 18
Created new Object3D 28
Created new Object3D 39
Created new Object3D 42
Created new Object3D 45
Created new Object3D 51
Created new Object3D 78
Created new Object3D 109
Created new Object3D 131
Created new Object3D 153
Created new Object3D 177
Created new Object3D 180
Created new Object3D 185
Created new Object3D 191
Created new Object3D 199
Created new Object3D 202
Created new Object3D 207
Created new Object3D 215
Created new Object3D 227
Created new Object3D 244
Created new Object3D 264
Created new Object3D 268
Created new Object3D 273
Created new Object3D 278
Created new Object3D 286
Created new Object3D 294
Created new Object3D 302
Software renderer disposed
Current mode:800 x 600 x 32 @30Hz
Driver is: igdumdim64/10.18.10.3412 on Intel / Intel(R) HD Graphics 4000
GL_ARB_texture_env_combine supported and used!
FBO supported and used!
VBO supported and used!
OpenGL renderer initialized (using 4 texture stages)
New WorldProcessor created using 1 thread(s) and granularity of 1!
Creating new world processor buffer for thread Thread-7

Second time:

[ Sat Apr 26 15:03:18 CEST 2014 ] - ERROR: A texture with the name 'skyDome' has been declared twice!
Loading Texture...car.jpg
[ Sat Apr 26 15:03:18 CEST 2014 ] - WARNING: Unsupported Texture width (400)...resizing to a width of 256 pixels!
[ Sat Apr 26 15:03:18 CEST 2014 ] - ERROR: A texture with the name 'car.jpg' has been declared twice!
Loading Texture...carGreen.jpg
[ Sat Apr 26 15:03:18 CEST 2014 ] - WARNING: Unsupported Texture width (400)...resizing to a width of 256 pixels!
[ Sat Apr 26 15:03:18 CEST 2014 ] - ERROR: A texture with the name 'carGreen' has been declared twice!
Loading Texture...carBlue.jpg
[ Sat Apr 26 15:03:18 CEST 2014 ] - WARNING: Unsupported Texture width (400)...resizing to a width of 256 pixels!
[ Sat Apr 26 15:03:18 CEST 2014 ] - ERROR: A texture with the name 'carBlue' has been declared twice!
Loading Texture...carYellow.jpg
[ Sat Apr 26 15:03:18 CEST 2014 ] - WARNING: Unsupported Texture width (400)...resizing to a width of 256 pixels!
[ Sat Apr 26 15:03:18 CEST 2014 ] - ERROR: A texture with the name 'carYellow' has been declared twice!
Loading Texture...carRed.jpg
[ Sat Apr 26 15:03:18 CEST 2014 ] - WARNING: Unsupported Texture width (400)...resizing to a width of 256 pixels!
[ Sat Apr 26 15:03:18 CEST 2014 ] - ERROR: A texture with the name 'carRed' has been declared twice!
[ Sat Apr 26 15:03:18 CEST 2014 ] - ERROR: A texture with the name 'White' has been declared twice!
[ Sat Apr 26 15:03:18 CEST 2014 ] - ERROR: A texture with the name 'Gray' has been declared twice!
[ Sat Apr 26 15:03:18 CEST 2014 ] - ERROR: A texture with the name 'Black' has been declared twice!
[ Sat Apr 26 15:03:18 CEST 2014 ] - ERROR: A texture with the name 'Blue' has been declared twice!
[ Sat Apr 26 15:03:18 CEST 2014 ] - ERROR: A texture with the name 'Underlay' has been declared twice!
Loading file car.3ds
File car.3ds loaded...10251 bytes
Processing new material carcar.jpg!
Processing object from 3DS-file: Car
Object 'Car_jPCT313' created using 362 polygons and 316 vertices.
Java version is: 1.7.0_17
-> support for BufferedImage
Version helper for 1.5+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Software renderer disposed
Created new Object3D 318
Created new Object3D 328
Created new Object3D 338
Created new Object3D 349
Created new Object3D 352
Created new Object3D 355
Created new Object3D 361
Created new Object3D 388
Created new Object3D 419
Created new Object3D 441
Created new Object3D 463
Created new Object3D 487
Created new Object3D 490
Created new Object3D 495
Created new Object3D 501
Created new Object3D 509
Created new Object3D 512
Created new Object3D 517
Created new Object3D 525
Created new Object3D 537
Created new Object3D 554
Created new Object3D 574
Created new Object3D 578
Created new Object3D 583
Created new Object3D 588
Created new Object3D 596
Created new Object3D 604
Created new Object3D 612
Visibility lists disposed!
Software renderer disposed
Current mode:800 x 600 x 32 @30Hz
Driver is: igdumdim64/10.18.10.3412 on Intel / Intel(R) HD Graphics 4000
GL_ARB_texture_env_combine supported and used!
FBO supported and used!
VBO supported and used!
OpenGL renderer initialized (using 4 texture stages)
New WorldProcessor created using 1 thread(s) and granularity of 1!
Creating new world processor buffer for thread Thread-8
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:247)
   at java.lang.Thread.run(Unknown Source)

miron123

I solved the problem. Thanks
The Config was the Problem

EgonOlsen