Repository: godotengine/godot
File: scene/2d/path_2d.cpp (C++)

Code before:
#endif

bool PathDebug2D::debug_enabled = true;
Color PathDebug2D::debug_paths_color = Color(0.1, 1.0, 0.7, 0.4);
float PathDebug2D::debug_paths_width = 2.0;
float PathDebug2D::debug_paths_sample_interval = 5.0;
bool PathDebug2D::debug_paths_fish_bones_enabled = true;
int PathDebug2D::debug_paths_fish_bones_interval = 4;

Mutex PathDebug2D::update_callbacks_mutex;
HashMap<Path2D *, Callable> PathDebug2D::update_callbacks;

void PathDebug2D::add_update_callback(Path2D *p_path, Callable p_callback) {
	MutexLock lock(update_callbacks_mutex);
	update_callbacks.insert(p_path, p_callback);
}

void PathDebug2D::remove_update_callback(Path2D *p_path) {
	MutexLock lock(update_callbacks_mutex);
	update_callbacks.erase(p_path);
}

void PathDebug2D::emit_update_callbacks() {
	MutexLock lock(update_callbacks_mutex);
	for (KeyValue<Path2D *, Callable> &kv : update_callbacks) {
		ERR_CONTINUE(kv.value.is_null());
		kv.value.call();
	}
}

void PathDebug2D::init_settings() {
#ifndef DISABLE_DEPRECATED
	if (!ProjectSettings::get_singleton()->has_setting("debug/shapes/paths/2d/geometry_color") && ProjectSettings::get_singleton()->has_setting("debug/shapes/paths/geometry_color")) {
		Color legacy_geometry_color = GLOBAL_GET("debug/shapes/paths/geometry_color");

		ProjectSettings::get_singleton()->set_setting("debug/shapes/paths/2d/geometry_color", legacy_geometry_color);
		ProjectSettings::get_singleton()->clear("debug/shapes/paths/geometry_color");
	}

	if (ProjectSettings::get_singleton()->has_setting("debug/shapes/paths/geometry_width")) {
		debug_paths_width = GLOBAL_GET("debug/shapes/paths/geometry_width");
	}
#endif // DISABLE_DEPRECATED

	debug_paths_color = GLOBAL_DEF("debug/shapes/paths/2d/geometry_color", Color(0.1, 1.0, 0.7, 0.4));
	debug_paths_sample_interval = GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "debug/shapes/paths/2d/sample_interval_2d", PROPERTY_HINT_RANGE, "0.1,10,0.001,or_greater"), 5.0);
	debug_paths_fish_bones_enabled = GLOBAL_DEF(PropertyInfo(Variant::BOOL, "debug/shapes/paths/2d/fish_bones_enabled"), true);
	debug_paths_fish_bones_interval = GLOBAL_DEF(PropertyInfo(Variant::INT, "debug/shapes/paths/2d/fish_bones_interval", PROPERTY_HINT_RANGE, "1,10,1,or_greater"), 4);
}

void PathDebug2D::set_debug_enabled(bool p_enabled) {

Review comment (suggestion):
```suggestion
		ERR_CONTINUE(!kv.value.is_valid());
```
`Callable` should be checked against `is_valid` for checking if it can be called

Code after:

#ifdef DEBUG_ENABLED
Rect2 Path2D::_edit_get_rect() const {
	if (curve.is_null() || curve->get_point_count() == 0) {
		return Rect2(0, 0, 0, 0);
	}

	Rect2 aabb = Rect2(curve->get_point_position(0), Vector2(0, 0));

	for (int i = 0; i < curve->get_point_count(); i++) {
		for (int j = 0; j <= 8; j++) {
			real_t frac = j / 8.0;
			Vector2 p = curve->sample(i, frac);
			aabb.expand_to(p);
		}
	}

	return aabb;
}

bool Path2D::_edit_use_rect() const {
	return curve.is_valid() && curve->get_point_count() != 0;
}

bool Path2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
	if (curve.is_null()) {
		return false;
	}

	for (int i = 0; i < curve->get_point_count(); i++) {
		Vector2 segment_a = curve->get_point_position(i);

		for (int j = 1; j <= 8; j++) {
			real_t frac = j / 8.0;
			const Vector2 segment_b = curve->sample(i, frac);

			Vector2 p = Geometry2D::get_closest_point_to_segment(p_point, segment_a, segment_b);
			if (p.distance_to(p_point) <= p_tolerance) {
				return true;
			}

			segment_a = segment_b;
		}
	}

	return false;
}
#endif

void Path2D::_notification(int p_what) {
	switch (p_what) {