A
A
Andrey Andryushchenko2015-03-10 13:48:05
Java
Andrey Andryushchenko, 2015-03-10 13:48:05

How to change body weight in libGDX?

I make it so that by clicking on the screen some body is divided into two bodies. By clicking on the screen, some divide() function is called, in which I perform the manipulations with particles that I need, including changing the mass, which looks like this:

...
        MassData newMassData=new MassData();
        newMassData.mass=this.body.getMass()-mass;// mass-это масса второго тела, которое отделяется от главного
        this.body.setMassData(newMassData);
...

In the line this.body.setMassData(newMassData);SOMETIMES , an error occurs due to which the Java Platform SE binary is shutting down. The following is written in the logs:
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Assertion failed!

Program: C:\Program Files\Java\jdk1.8.0_05\bin\java.exe
File: /var/lib/jenkins/workspace/libgdx/extensions/gdx-box2d/gdx-box2d/jni/Box2D/Dynamics/b2Body.cpp, Line 355

Expression: m_world->IsLocked() == false

It would be interesting to at least know what this means and why the application crashes sometimes. And most importantly, I would like to know how to competently implement the division of the body into two parts and change in body weight.
PS The application crashes exactly in this line and nothing else. the application can crash only with this line of code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Petrov, 2015-03-12
@delphikettle

You cannot change the properties of bodies when the world is locked (read step is being executed).
I'm almost certain that your divide and world steps are running on different threads. Try calling in one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question