Skip to content

Commit d8f3a20

Browse files
authored
fix: dispose physic's natives, stop threads. (#4299)
* perf(dispose-stop-resources): dispose physic's natives, stop threads. * chore(reduce-ram-eats): remove commented lines
1 parent 24e4cdf commit d8f3a20

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

engine/src/main/java/org/terasology/network/internal/ClientConnectionHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void run() {
8181
logger.error("Server timeout threshold of {} ms exceeded.", timeoutThreshold);
8282
}
8383
}
84+
Thread.currentThread().stop();
8485
}
8586
}, timeoutThreshold + 200);
8687
}

engine/src/main/java/org/terasology/physics/bullet/BulletPhysics.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
/*
2-
* Copyright 2016 MovingBlocks
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright 2020 The Terasology Foundation
2+
// SPDX-License-Identifier: Apache-2.0
163
package org.terasology.physics.bullet;
174

185
import com.badlogic.gdx.physics.bullet.collision.ClosestRayResultCallback;
@@ -158,6 +145,10 @@ public List<PhysicsSystem.CollisionPair> getCollisionPairs() {
158145
public void dispose() {
159146
this.discreteDynamicsWorld.dispose();
160147
this.dispatcher.dispose();
148+
this.defaultCollisionConfiguration.dispose();
149+
this.entityTriggers.forEach((k,v) -> v.dispose());
150+
this.entityRigidBodies.forEach((k,v)-> v.dispose());
151+
this.ghostPairCallback.dispose();
161152
}
162153

163154
@Override
@@ -588,8 +579,7 @@ private RigidBody newRigidBody(EntityRef entity) {
588579

589580
private void removeCollider(btCollisionObject collider) {
590581
discreteDynamicsWorld.removeCollisionObject(collider);
591-
// collider.getCollisionShape().dispose();
592-
// collider.dispose();
582+
collider.dispose();
593583
}
594584

595585
/**

engine/src/main/java/org/terasology/world/chunks/pipeline/ChunkProcessingPipeline.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ private void chunkTaskHandler() {
108108
onStageDone(future, chunkProcessingInfo);
109109
}
110110
} catch (InterruptedException e) {
111-
logger.error("Reactor thread was interrupted", e);
111+
if (!executor.isTerminated()) {
112+
logger.error("Reactor thread was interrupted", e);
113+
}
112114
reactor.interrupt();
113115
}
114116
}
@@ -237,10 +239,10 @@ public Future<Chunk> invokePipeline(Chunk chunk) {
237239

238240
public void shutdown() {
239241
executor.shutdown();
240-
241242
chunkProcessingInfoMap.keySet().forEach(this::stopProcessingAt);
242243
chunkProcessingInfoMap.clear();
243244
executor.getQueue().clear();
245+
reactor.interrupt();
244246
}
245247

246248
public void restart() {

0 commit comments

Comments
 (0)