Vector3 (0, 0, 0) must be normalized error keeps popping on my debugger

Godot Version

4.7 stable

Question

I’m working on a Portal clone and got the portals to stick on the wall correctly.

But everytime i run the game, i get an error that says: The axis Vector3 (0.0, 0.0, 0.0) must be normalized.

(var final_pos = transform.rotated(axis, alpha) is where the error occurs)

var original : Vector3 = global_transform.basis.y
var cosa := original.dot(new_normal)
var alpha := acos(cosa)
var axis : Vector3 = original.cross(new_normal).normalized()

var final_pos : Transform3D = global_transform.rotated(axis, alpha)

global_transform = final_pos
global_position = attach_point

var target_dir : Vector3 = attach_point - new_normal
if not global_position.is_equal_approx(target_dir):
	look_at(target_dir, -Vector3.UP)

if new_normal == Vector3(0, 1, 0): rotation_degrees.x = 90
elif new_normal == Vector3(0, -1, 0): rotation_degrees.x = -90

Despite of the error. The game runs and the portal alignment code works just fine.

I couldn’t find a proper solution online, so does anyone know how to fix this?

Because the engine keeps spamming this error on my debugger and it lags my game.

If new_normal and original are colinear, the cross product is undefined and the engine will complaint. Check for this and use a different vector in the cross product if those vectors coincide.

(post deleted by author)

Good suggestion, but can you show me a code example?

Because I’m kinda dumb..

(Also if you have any suggestions for improving the alignment code, please tell me)