Repository: godotengine/godot
File: modules/gridmap/grid_map.cpp (C++)

Code before:
		return;
	}

	OctantKey octantkey = ok;

	if (!octant_map.has(octantkey)) {
		//create octant because it does not exist
		Octant *g = memnew(Octant);
		g->dirty = true;
#ifndef PHYSICS_3D_DISABLED
		g->static_body = PhysicsServer3D::get_singleton()->body_create();
		PhysicsServer3D::get_singleton()->body_set_mode(g->static_body, PhysicsServer3D::BODY_MODE_STATIC);
		PhysicsServer3D::get_singleton()->body_attach_object_instance_id(g->static_body, get_instance_id());
		PhysicsServer3D::get_singleton()->body_set_collision_layer(g->static_body, collision_layer);
		PhysicsServer3D::get_singleton()->body_set_collision_mask(g->static_body, collision_mask);
		PhysicsServer3D::get_singleton()->body_set_collision_priority(g->static_body, collision_priority);
		if (physics_material.is_valid()) {
			PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_FRICTION, physics_material->computed_friction());
			PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_BOUNCE, physics_material->computed_bounce());
		}
#endif // PHYSICS_3D_DISABLED
		SceneTree *st = SceneTree::get_singleton();
		bool debug_collisions = false;
		switch (collision_visibility_mode) {
			case DEBUG_VISIBILITY_MODE_DEFAULT:
				debug_collisions = !Engine::get_singleton()->is_editor_hint() && st && st->is_debugging_collisions_hint();
				break;
			case DEBUG_VISIBILITY_MODE_FORCE_HIDE:
				debug_collisions = false;
				break;
			case DEBUG_VISIBILITY_MODE_FORCE_SHOW:
				debug_collisions = true;
				break;
		}
		if (debug_collisions) {
			g->collision_debug = RS::get_singleton()->mesh_create();
			g->collision_debug_instance = RS::get_singleton()->instance_create();
			RS::get_singleton()->instance_set_base(g->collision_debug_instance, g->collision_debug);
		}

		octant_map[octantkey] = g;

		if (is_inside_world()) {
			_octant_enter_world(octantkey);
			_octant_transform(octantkey);
		}
	}

	Octant &g = *octant_map[octantkey];
	g.cells.insert(key);
	g.dirty = true;

Review comment (bug):
You could move the `st` variable into the `DEBUG_VISIBILITY_MODE_DEFAULT` scope, since it's only used there.

Code after:
		return;
	}

	OctantKey octantkey = ok;

	if (!octant_map.has(octantkey)) {
		//create octant because it does not exist
		Octant *g = memnew(Octant);
		g->dirty = true;
#ifndef PHYSICS_3D_DISABLED
		g->static_body = PhysicsServer3D::get_singleton()->body_create();
		PhysicsServer3D::get_singleton()->body_set_mode(g->static_body, PhysicsServer3D::BODY_MODE_STATIC);
		PhysicsServer3D::get_singleton()->body_attach_object_instance_id(g->static_body, get_instance_id());
		PhysicsServer3D::get_singleton()->body_set_collision_layer(g->static_body, collision_layer);
		PhysicsServer3D::get_singleton()->body_set_collision_mask(g->static_body, collision_mask);
		PhysicsServer3D::get_singleton()->body_set_collision_priority(g->static_body, collision_priority);
		if (physics_material.is_valid()) {
			PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_FRICTION, physics_material->computed_friction());
			PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_BOUNCE, physics_material->computed_bounce());
		}
#endif // PHYSICS_3D_DISABLED
		bool debug_collisions = false;
		switch (collision_visibility_mode) {
			case DEBUG_VISIBILITY_MODE_DEFAULT: {
				SceneTree *st = SceneTree::get_singleton();
				debug_collisions = st && !Engine::get_singleton()->is_editor_hint() && st->is_debugging_collisions_hint();
			} break;
			case DEBUG_VISIBILITY_MODE_FORCE_HIDE: {
				debug_collisions = false;
			} break;
			case DEBUG_VISIBILITY_MODE_FORCE_SHOW: {
				debug_collisions = true;
			} break;
		}
		if (debug_collisions) {
			g->collision_debug = RS::get_singleton()->mesh_create();
			g->collision_debug_instance = RS::get_singleton()->instance_create();
			RS::get_singleton()->instance_set_base(g->collision_debug_instance, g->collision_debug);
		}

		octant_map[octantkey] = g;

		if (is_inside_world()) {
			_octant_enter_world(octantkey);
			_octant_transform(octantkey);
		}
	}

	Octant &g = *octant_map[octantkey];
	g.cells.insert(key);
	g.dirty = true;