Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random freezes in Mineclone 2 0.77 #12621

Closed
x2048 opened this issue Jul 31, 2022 · 6 comments
Closed

Random freezes in Mineclone 2 0.77 #12621

x2048 opened this issue Jul 31, 2022 · 6 comments
Labels
Bug Issues that were confirmed to be a bug @ Client / Audiovisuals @ Client / Controls / Input Regression Something that used to work no longer does
Milestone

Comments

@x2048
Copy link
Contributor

x2048 commented Jul 31, 2022

Minetest version
Minetest 5.6.0-dev-debug-a2bf3a2aa (Linux)
Using Irrlicht 1.9.0mt7
Using LuaJIT 2.1.0-beta3
BUILD_TYPE=Debug
RUN_IN_PLACE=1
USE_CURL=1
USE_GETTEXT=0
USE_SOUND=1
STATIC_SHAREDIR="."
OS / Hardware

Operating system: KDE Neon / Ubuntu 20.04
CPU: AMD Ryzen 7

GPU model: AMD Renoir
OpenGL version: 4.5

Summary

When running Mineclone 2 version 0.77, the rendering thread randomly freezes.

Steps to reproduce
  1. Install Mineclone 2 version 0.77
  2. Start a new survival world, mapgen v7
  3. Hold AUX1 (Run) and keep pressing and releasing forward
  4. At some point the game will freeze for a few seconds.
    Notice Time-non-rendering below:
    image
@x2048 x2048 added Unconfirmed bug Bug report that has not been confirmed to exist/be reproducible @ Client / Audiovisuals @ Client / Controls / Input labels Jul 31, 2022
@x2048
Copy link
Contributor Author

x2048 commented Aug 2, 2022

Narrowed down to ParticleManager::step():
image

Patch:

diff --git a/src/client/game.cpp b/src/client/game.cpp
index c34e3a415..93a10d308 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -3837,7 +3837,10 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
 	/*
 		Update particles
 	*/
-	client->getParticleManager()->step(dtime);
+	{
+		ScopeProfiler particles(g_profiler, "Particles step", SPT_ADD);
+		client->getParticleManager()->step(dtime);
+	}
 
 	/*
 		Fog

To trigger, hold AUX1 and keep pressing and releasing forward - Mineclone2 will generate 'drift dust' particles at the player's feet.

@x2048
Copy link
Contributor Author

x2048 commented Aug 2, 2022

Collected logs of collisionMoveSimple:

2022-08-02 22:17:21: INFO[Main]:   A_PARTICLES::# collision_infos nodes  . . .   2148x  536.497
2022-08-02 22:17:21: INFO[Main]:   A_PARTICLES::# collision_infos total  . . .   2148x  536.497
2022-08-02 22:17:21: INFO[Main]:   A_PARTICLES::collision [ms]  . . . . . . . .    1x  981
2022-08-02 22:17:21: INFO[Main]:   A_PARTICLES::step [ms]  . . . . . . . . . .     1x  982
2022-08-02 22:17:27: INFO[Main]:   A_PARTICLES::# collision_infos nodes  . . .   137x  117392
2022-08-02 22:17:27: INFO[Main]:   A_PARTICLES::# collision_infos total  . . .   137x  117392
2022-08-02 22:17:27: INFO[Main]:   A_PARTICLES::collision [ms]  . . . . . . . .    1x  6049
2022-08-02 22:17:27: INFO[Main]:   A_PARTICLES::step [ms]  . . . . . . . . . .     1x  6049
2022-08-02 22:17:28: INFO[Main]:   A_PARTICLES::# collision_infos nodes  . . .   100x  22.08
2022-08-02 22:17:28: INFO[Main]:   A_PARTICLES::# collision_infos total  . . .   100x  22.08
2022-08-02 22:17:28: INFO[Main]:   A_PARTICLES::collision [ms] 
2022-08-02 22:17:28: INFO[Main]:   A_PARTICLES::step [ms] 
2022-08-02 22:17:30: INFO[Main]:   A_PARTICLES::# collision_infos nodes  . . .   2352x  21.0357
2022-08-02 22:17:30: INFO[Main]:   A_PARTICLES::# collision_infos total  . . .   2352x  21.0357
2022-08-02 22:17:30: INFO[Main]:   A_PARTICLES::collision [ms]  . . . . . . . .    1x   1
2022-08-02 22:17:30: INFO[Main]:   A_PARTICLES::step [ms]  . . . . . . . . . .     1x   3

Patch to enable this logging:

diff --git a/src/client/particles.cpp b/src/client/particles.cpp
index 818cdc8cc..43d32fd4b 100644
--- a/src/client/particles.cpp
+++ b/src/client/particles.cpp
@@ -32,6 +32,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "nodedef.h"
 #include "client.h"
 #include "settings.h"
+#include "util/timetaker.h"
+#include "profiler.h"
 
 /*
 	Particle
@@ -181,6 +183,7 @@ void Particle::step(float dtime)
 	m_velocity = av*vecSign(m_velocity) + v3f(m_jitter.pickWithin())*dtime;
 
 	if (m_collisiondetection) {
+		ScopeProfiler collision(g_profiler, "A_PARTICLES::collision", SPT_ADD);
 		aabb3f box = m_collisionbox;
 		v3f p_pos = m_pos * BS;
 		v3f p_velocity = m_velocity * BS;
diff --git a/src/collision.cpp b/src/collision.cpp
index 910c80604..1d382e833 100644
--- a/src/collision.cpp
+++ b/src/collision.cpp
@@ -362,6 +362,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
 	}
 
 	} // tt2
+	g_profiler->avg("A_PARTICLES::# collision_infos nodes", cinfo.size());
 
 	if(collideWithObjects)
 	{
@@ -434,7 +435,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
 		}
 #endif
 	} //tt3
-
+	g_profiler->avg("A_PARTICLES::# collision_infos total", cinfo.size());
 	/*
 		Collision detection
 	*/

@appgurueu
Copy link
Contributor

Could this be related to @velartrill's "better particles" PR?

@x2048
Copy link
Contributor Author

x2048 commented Aug 2, 2022

Flamegraph during freeze:
image

@x2048
Copy link
Contributor Author

x2048 commented Aug 2, 2022

Log of velocity and acceleration in collisionMoveSimple()

2022-08-02 23:11:15: INFO[Main]:   A_PARTICLES::velocity  . . . . . . . . . . .  2990x  5.16571
2022-08-02 23:11:26: INFO[Main]:   A_PARTICLES::acceleration  . . . . . . . . .  3531x  56.4033
2022-08-02 23:11:26: INFO[Main]:   A_PARTICLES::velocity  . . . . . . . . . . .  3531x  1.59983e+14
2022-08-02 23:11:40: INFO[Main]:   A_PARTICLES::acceleration  . . . . . . . . .  203x  34.6728
2022-08-02 23:11:40: INFO[Main]:   A_PARTICLES::velocity  . . . . . . . . . . .  203x  inf
2022-08-02 23:11:40: INFO[Main]:   A_PARTICLES::acceleration  . . . . . . . . .  219x  26.6996

@x2048
Copy link
Contributor Author

x2048 commented Aug 2, 2022

Root cause is uninitialized default value for f32 particle parameters such as bounce, which caused particle velocity to become very high after a collision.

Patch that fixes the problem:

diff --git a/src/particles.h b/src/particles.h
index 74bfa7fce..3061deb83 100644
--- a/src/particles.h
+++ b/src/particles.h
@@ -91,7 +91,7 @@ namespace ParticleParamTypes
                using ValType = T;
                using pickFactors = float[PN];
 
-               T val;
+               T val = T();
                using This = Parameter<T, PN>;
 
                Parameter() = default;

Edit: added root cause of the problem.

@x2048 x2048 added Bug Issues that were confirmed to be a bug Regression Something that used to work no longer does and removed Unconfirmed bug Bug report that has not been confirmed to exist/be reproducible labels Aug 2, 2022
@x2048 x2048 added this to the 5.6.0 milestone Aug 2, 2022
@x2048 x2048 closed this as completed in 644f145 Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issues that were confirmed to be a bug @ Client / Audiovisuals @ Client / Controls / Input Regression Something that used to work no longer does
Projects
None yet
Development

No branches or pull requests

2 participants