Rendering into two different view at the same time

Started by Kumaraswamy, October 16, 2021, 11:41:40 AM

Previous topic - Next topic

Kumaraswamy

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

EgonOlsen

"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?

Kumaraswamy

I will attach a screen recording of it in 10 mins.


Kumaraswamy

When I click button 2 to load the second model, it moves by itself and sometimes i also crashes

Kumaraswamy

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

Kumaraswamy


EgonOlsen

#7
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.


Kumaraswamy