godot_debug_draw_3d icon indicating copy to clipboard operation
godot_debug_draw_3d copied to clipboard

[Bug]: Cannot make a functional build for large world co ordinates

Open InfernoSuperNova opened this issue 1 year ago • 2 comments
trafficstars

Godot version

4.3

DebugDraw3D version

1.4.4

On which operating systems the error occurs

Linux

Using which renderers the error occurs

All

Issue description

Floats in 2d/graphs.cpp at line 164 and 3d/config_3d.cpp at line 49 prevent building entirely. Replacing them with doubles allows building, everything appears to work until you actually try to draw something and the player crashes with the error:

E 0:00:02:0341 NativeCalls.cs:7043 @ Godot.Variant Godot.NativeCalls.godot_icall_2_783(nint, nint, Godot.NativeInterop.godot_string_name, Godot.Variant[], Godot.NativeInterop.godot_string_name): Condition "array.size() != p_vertex_array_len * s" is true. Returning: ERR_INVALID_PARAMETER <C++ Source> servers/rendering_server.cpp:823 @ _surface_set_data() <Stack Trace> NativeCalls.cs:7043 @ Godot.Variant Godot.NativeCalls.godot_icall_2_783(nint, nint, Godot.NativeInterop.godot_string_name, Godot.Variant[], Godot.NativeInterop.godot_string_name) GodotObject.cs:654 @ Godot.Variant Godot.GodotObject.Call(Godot.StringName, Godot.Variant[]) DebugDrawGeneratedAPI.generated.cs:760 @ void DebugDraw3D.DrawBox(Godot.Vector3, Godot.Quaternion, Godot.Vector3, System.Nullable`1[Godot.Color], bool, float) PlayerController.cs:34 @ void ArchitectsInVoid.Player.PlayerController._Ready() Node.cs:2401 @ bool Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&) ArchitectsInVoid.Player.PlayerController_ScriptMethods.generated.cs:100 @ bool ArchitectsInVoid.Player.PlayerController.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&) CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(nint, Godot.NativeInterop.godot_string_name*, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant_call_error*, Godot.NativeInterop.godot_variant*) Godot.NativeInterop.NativeFuncs.generated.cs:359 @ void Godot.NativeInterop.NativeFuncs.godotsharp_method_bind_ptrcall(nint, nint, System.Void**, System.Void*) NativeCalls.cs:6864 @ void Godot.NativeCalls.godot_icall_3_770(nint, nint, nint, Godot.NativeInterop.godot_bool, int) Node.cs:776 @ void Godot.Node.AddChild(Godot.Node, bool, Godot.Node+InternalMode) PlayerData.cs:39 @ void PlayerData._Load(Godot.FileAccess) WorldDataManager.cs:55 @ void ArchitectsInVoid.WorldData.WorldDataManager._Load(Godot.FileAccess) Data.cs:48 @ void ArchitectsInVoid.WorldData.Data.Load(string) WorldManager.cs:168 @ void ArchitectsInVoid.UI.WorldManager.LoadSelectedWorld() Callable.generics.cs:39 @ void Godot.Callable.<From>g__Trampoline|1_0(object, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&) DelegateUtils.cs:86 @ void Godot.DelegateUtils.InvokeWithVariantArgs(nint, System.Void*, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant*)

Steps to reproduce

Build with the parameter "precision=double"

Minimal reproduction project

Built plugin attached debug_draw_3d.tar.gz

InfernoSuperNova avatar Sep 17 '24 10:09 InfernoSuperNova

I am also trying to do this.

fire avatar Nov 03 '24 03:11 fire

The problem is that I currently have all instance positions stored in Vector3, which are now double, and RenderingServer only works with float and now I need to convert it all. Also, the Custom0 data array accepts only float, and for me it is converted from Vector3 by direct copying of memory. And there are probably many other problems 🤷‍♂️.

Hopefully fixing these issues won't take very long. At least Godot doesn't crash for me right now.


https://github.com/user-attachments/assets/2621f453-d166-425d-b30b-fe6ad61f24db


image


The main issues have been fixed. 65b4e624b201c1cc509f836dbbff1e473b4a4027 image

DmitriySalnikov avatar Nov 03 '24 07:11 DmitriySalnikov

Most of the problems have been fixed (in fact, I'm not sure if these are problems and someone needs such large coordinates).

https://github.com/user-attachments/assets/24732f7e-afa1-43c1-908f-cd17f29ac3da

DmitriySalnikov avatar Nov 04 '24 16:11 DmitriySalnikov

Are you familiar with real_t and the define REAL_T_IS_DOUBLE

fire avatar Nov 04 '24 18:11 fire

I don't understand what you mean, because real_t has been used in the lib for a long time. REAL_T_IS_DOUBLE was used at one point, until I realized that MultiMesh always accepts only PackedFloat32Array (and as I wrote above, RenderingServer only works with float). And the latest commits are aimed at using REAL_T_IS_DOUBLE.

in fact, I'm not sure if these are problems and someone needs such large coordinates

Here I expressed my uncertainty, because the example from the last video was on Vector3(16000000, 0, 0). Even on Vector3(1000000, 0, 0) without additional fixes, everything looks relatively acceptable. And I do not know if such large coordinates are really needed, but I added a fix (optional) that adds accuracy and spends more CPU resources.

So you can build this library simply with precision=double support, but without position corrections and with or without an advanced extendable mesh shader.

DmitriySalnikov avatar Nov 05 '24 02:11 DmitriySalnikov

Can you guys check if everything is working as it should? All recent changes in the master branch.

You can also download libdouble-* here for testing. This version is built with fix_precision_enabled=yes shader_world_coords_enabled=no. The comparison is here.

DmitriySalnikov avatar Nov 05 '24 13:11 DmitriySalnikov

I will do that as I can find some bandwidth. Thanks!

fire avatar Nov 05 '24 17:11 fire

Is there a demo you know works? I might need to do something differently. It is crashing without a log.

Edited:

~~It requires a new gdextension file, but it works.~~

debug_draw_3d.gdextension.txt

Crashes

fire avatar Nov 05 '24 23:11 fire

It is crashing without a log.

I'm sorry, I completely forgot that I changed the .gdextension file.

As I understand from your edited file, is your editor crashing on macos? In that case, I'll have to mess with the macos VM again :(

DmitriySalnikov avatar Nov 06 '24 02:11 DmitriySalnikov

I am on Windows right now, but I'm only frustrated because I lack a log. Good work, though.

fire avatar Nov 06 '24 02:11 fire

I just built godot master and copied the double library from CI and everything seems to work:

image

On Windows, libraries from CI are also run in both double and single. I think everything is ready for release.

DmitriySalnikov avatar Nov 06 '24 03:11 DmitriySalnikov

Fixed in 1.4.5

DmitriySalnikov avatar Nov 06 '24 07:11 DmitriySalnikov