hi, i am new here, I am using JPTC for android, its working good, but when i load the second another model and Add it to a view, it makes it behave weirdly, can you please help me
"It behaves weirdly" doesn't really mean much. I can't possibly help based on this alone. Can you provide more details about what's going on exactly?
I will attach a screen recording of it in 10 mins.
Here is the link to the video uploaded in Google Drive:
https://drive.google.com/file/d/1PGnwLQDILIysXZe89jL-w-wKuhy6AkYd/view?usp=sharing
When I click button 2 to load the second model, it moves by itself and sometimes i also crashes
here by loading model I mean, the model is loaded correctly from the file (3ds object) but adding it to view using GLSurfaceView creates this behaviour
Hi can you please help me with this?
I see. jPCT-AE isn't thread safe in a way that it can render into multiple views from different threads at the same time. The reason for this dates back to the early days of Android where performance was largely hindered by the JIT-less Dalvik VM and it's awful garbage collection behaviour. You might want to try to add a static sync object to your class, like
private final static Object SYNC = new Object();
and then wrap your rendering code into a synchronized block like so:
synchronized(SYNC) {
if (touchTurn != 0) {
object3D.rotateY(touchTurn);
touchTurn = 0;
}
if (touchTurnUp != 0) {
object3D.rotateX(touchTurnUp);
touchTurnUp = 0;
}
buffer.clear(back);
world.renderScene(buffer);
world.draw(buffer);
buffer.display();
}
Yes, that's an awful hack and it might not even work properly, but there's no other chance to make jPCT-AE behave when you are doing the rendering in parallel. Another option is to use one view and either only display one model at a time or render them both into a texture and blit the result onto the screen to simulate the two different views. But that leaves you with managing touch events and such for both simulated views and such annoyances.
thanks, I will try that out!
This works perfectly, thank you very much :)