Skip to content

Commit 8d2672b

Browse files
committed
feat: warning on environment leak
1 parent ead7aa7 commit 8d2672b

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/Modules/VPhysics.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,20 @@ ON_EVENT(SESSION_START) {
2323
if (!env) break;
2424
vphysEnvironments.push_back(env);
2525
}
26-
27-
switch (vphysEnvironments.size()) {
28-
default:
29-
lastWasFast = false;
30-
break;
31-
case 3:
32-
// Fast load, destroy one unused environment
33-
// The first env is unused, and the second one persists through
34-
// fast load(s). That means on the first fast load we'll destroy
35-
// the first environment, and subsequent fast loads we'll destroy
36-
// the second environment. (since it's now using the first one)
37-
int *env = vphysEnvironments[lastWasFast ? 1 : 0];
38-
vphysics->DestroyPhysicsEnvironment(env);
39-
lastWasFast = true;
40-
break;
26+
if (vphysEnvironments.size() == 3) {
27+
// Fast load, destroy one unused environment
28+
// The first env is unused, and the second one persists through
29+
// fast load(s). That means on the first fast load we'll destroy
30+
// the first environment, and subsequent fast loads we'll destroy
31+
// the second environment. (since it's now using the first one)
32+
int *env = vphysEnvironments[lastWasFast ? 1 : 0];
33+
vphysics->DestroyPhysicsEnvironment(env);
34+
lastWasFast = true;
35+
} else {
36+
lastWasFast = false;
37+
if (vphysEnvironments.size() > 3) {
38+
console->Warning("VPhysics: Detected more than 3 physics environments (%zu), this is unexpected!\n", vphysEnvironments.size());
39+
}
4140
}
4241
}
4342

0 commit comments

Comments
 (0)