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

The GridMap freezes if meshes are changed frequently #49995

Closed
Valeryn4 opened this issue Jun 29, 2021 · 8 comments · Fixed by #50052
Closed

The GridMap freezes if meshes are changed frequently #49995

Valeryn4 opened this issue Jun 29, 2021 · 8 comments · Fixed by #50052

Comments

@Valeryn4
Copy link
Contributor

Valeryn4 commented Jun 29, 2021

Godot version

3.3.2-stable

System information

Windows 10, GTX 1050ti, GLES3

Issue description

GridMap freezes and throws errors if grids change frequently

ERROR: get: Condition "!id_map.has(p_rid.get_data())" is true. Returned: __null
   At: ./core/rid.h:150
ERROR: body_add_shape: Condition "!body" is true.
   At: modules/bullet/bullet_physics_server.cpp:504

see this video: https://www.youtube.com/watch?v=ckImAKQaIuw

Maybe this is related to issue?

Steps to reproduce

Create a GridMap project and change tiles frequently, in large numbers in one frame.
Decreasing the octave will increase the errors.

Minimal reproduction project

This project. Run Test.tscn
SCP Manager.zip

LEFT_CLICK - Set block/Remove block
RIGHT_CLICK - Move Camera
WHILE_MOUSE - Zoom

GitHub: https://github.com/Valeryn4/Godot-GridMap-Err

@Valeryn4
Copy link
Contributor Author

And maybe this problem: #33648

@Calinou
Copy link
Member

Calinou commented Jun 29, 2021

Can you reproduce this if you change the 3D physics engine to GodotPhysics in the Project Settings?

@Valeryn4
Copy link
Contributor Author

Can you reproduce this if you change the 3D physics engine to GodotPhysics in the Project Settings?

yes

ERROR: get: Condition "!id_map.has(p_rid.get_data())" is true. Returned: __null
   At: ./core/rid.h:150 @ get()
ERROR: body_clear_shapes: Condition "!body" is true.
   At: servers/physics/physics_server_sw.cpp:614 @ body_clear_shapes()

@Valeryn4
Copy link
Contributor Author

may be problem in: modules/gridmap/grid_map.cpp in g.static_body ?

bool GridMap::_octant_update(const OctantKey &p_key) {
	....

	//erase body shapes
420:	PhysicsServer::get_singleton()->body_clear_shapes(g.static_body); /* <<<< IS OK! */
        ....
                                                                            /* \/\/ IS NOT OK*/
496:			PhysicsServer::get_singleton()->body_add_shape(g.static_body, shapes[i].shape->get_rid(), xform * shapes[i].local_transform); 

I don't have a GDB debugger at hand right now to trace the life cycle of STATIC_BODY

@Valeryn4
Copy link
Contributor Author

I've done some experiments.
Remove ALL physics body in meshlib.
Disable all collision layer.
image

ERROR: get: Condition "!id_map.has(p_rid.get_data())" is true. Returned: __null
   At: ./core/rid.h:150
ERROR: body_clear_shapes: Condition "!body" is true.
   At: modules/bullet/bullet_physics_server.cpp:567
ERROR: getornull: Condition "!id_map.has(p_rid.get_data())" is true. Returned: __null
   At: ./core/rid.h:160
ERROR: mesh_clear: Condition "!mesh" is true.
   At: drivers/gles3/rasterizer_storage_gles3.cpp:4401
ERROR: Invalid ID.
   At: modules/bullet/bullet_physics_server.cpp:1535

I deleted and created a large number of cells - caused errors and visual glitches.

If I delete or create cells one by one per frame - no problem.

Perhaps the problem is not in physics, but in the work of the octaves of the "GridMap" itself

@Valeryn4
Copy link
Contributor Author

Valeryn4 commented Jul 1, 2021

HEY! may be is problems? @Calinou

void GridMap::_update_octants_callback() { 

	if (!awaiting_update)
		return;

	List<OctantKey> to_delete;
	for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {

		if (_octant_update(E->key())) { /*free g.static_body <<<<<<<*/
			to_delete.push_back(E->key()); /*push remove queue <<<<<<<<<<*/
		}
	}

	while (to_delete.front()) {
		octant_map.erase(to_delete.front()->get()); /* erase FRONT queue <<<<<<*/
		to_delete.pop_back(); /* pop BACK! skip empty octans <<<<<<< */
	}
	...
}

fixed

while (to_delete.front()) {
		octant_map.erase(to_delete.front()->get()); //erase FRONT queue
		to_delete.pop_front(); // FIXXXXXX ?
	}

@Calinou
Copy link
Member

Calinou commented Jul 1, 2021

HEY! may be is problems?

I don't use GridMaps extensively or have experience dealing with the physics server, so I don't know. cc @pouleyKetchoupp

@Valeryn4
Copy link
Contributor Author

Valeryn4 commented Jul 1, 2021

The problem is logical.
We free the element from the top, and then we pop the last element.
If you extract several octans at once in one frame, a problem arises.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants