mohsenph69 / Godot-MTerrain-plugin

A GDExtension plugin which give godot the ability to produce highly optimized Terrain for Open world games
MIT License
372 stars 19 forks source link

Godot builds with precision=double crash #20

Closed nickpolet closed 5 months ago

nickpolet commented 6 months ago

Trying to use Godot builds that have the precision=double flag when compiling, to get around some floating-point issues on very large terrains.

I've built MTerrain with scons platform=linux target=template_debug arch=x86_64 preicsion=double and similar for building Godot.

When I create a new project, and add in the MTerrain files from compiling, the project crashes and I'm left with the below (it's not the most useful error).

...
PulseAudio 15.99.0 detected.
PulseAudio: context other
PulseAudio: context other
PulseAudio: context other
PulseAudio: context ready
PulseAudio: Detecting channels for device: alsa_output.pci-0000_2f_00.4.analog-stereo
PulseAudio: detected 2 output channels
PulseAudio: audio buffer frames: 512 calculated output latency: 11ms

TextServer: Primary interface set to: "ICU / HarfBuzz / Graphite (Built-in)".
*** stack smashing detected ***: terminated

I'm finding that on very large terrains (16km x 16km) floating point issues start to appear a couple of thousands units from the center point.

Has anyone managed to successfully get this addon running with a precision=double build? Interested in getting this running.

mohsenph69 commented 6 months ago

This is really strange as this error is for Audio stuff, Which has nothing to do with terrain but I will try to build this with double precision and see if that work or not

nickpolet commented 6 months ago

Yea, I don't think the PulseAudio output is the issue. I always get this when launching the editor.

It's the *** stack smashing detected ***: terminated output that is the difference when running double precision.

Brilliant, thanks.

mohsenph69 commented 6 months ago

I ran several test and this is what I understand.

Everything works except height-map Collision, which I fix that in this commit so to make sure collission works just build the latest commit

So when you build the Gd-extension library for double precision first thing you need to do is to change library name inside res://addons/m_terrain/libs/MTerrain.gdextension because as you build for double precision a double string will be added at the end of each library name. So first correct the path for each library

Also when you build Godot for double precision a double string will be added at the end of its name.

And make sure you run a double precision version of MTerrain library with Godot with double precision!

One other thing that I note is that, if you run Godot with double precision and MTerrain with double precision with a freshly build Godot Project it will work with no problem, But sometimes I ran to some issue when my project was ran with single precision Godot before. maybe it cache something, I am not sure, maybe remove .godot folder inside your project!

And each time you want to test something new make sure to backup your project file

At the end see if making everything double precision make any change and if is it worse it!

nickpolet commented 6 months ago

Thanks for taking the time to check.

I've tried all the above, and it works on new projects, but doesn't with existing projects (as you experienced).

I've tried removing the .godot folder to see if it's a caching issue, but it still crashes out. Will try a few more things and report back.

mohsenph69 commented 6 months ago

It seems that even some resource file will be stored differently, when using single-precision or double-precision.

I don't think that the terrain data will be a problem as I check this with some demo made with single-precision terrain. But check other resource file!

This is what Godot claim about compatibility between single and double precision: https://docs.godotengine.org/en/stable/tutorials/physics/large_world_coordinates.html#compatibility-between-single-precision-and-double-precision-builds

nickpolet commented 6 months ago

Would you be able to provide a double-precision build if you get a chance? I'm still having issues and just want to make sure I'm building it correctly.

mohsenph69 commented 6 months ago

No problem Nick

I try to publish that with the next build!

mohsenph69 commented 5 months ago

Has been build you can test that!

Build Godot from source for double version and see if that work!

nickpolet commented 5 months ago

Thanks for that.

So, the editor now loads, and can run the project, but collisions on the terrain don't work.

When running the create_grid() method on the terrain on a _ready() function, I get the error below, which I don't get on a normal non double precision build.

image

Using a precision=double build on Godot 4.2.1. image

Also tried a more recent 4.2.2 version. image

Any ideas on what is going on here?

mohsenph69 commented 5 months ago

That is really strange, I tested even the collision with double precision on windows and linux and on both of them it worked! the screenshot bellow is a test for double-precision for Godot

Screenshot_20240109_153701

It can be that Godot double-precision that you use has some issue! so I send you two version of Godot double-precision for windows and Linux, try them and see if they work!

Windows: https://drive.google.com/file/d/1lJ0nRV8lMJlAgPWFHkxAGTmpe6LoXc-D/view?usp=sharing Linux: https://drive.google.com/file/d/1vuUrihCs8IodRGH8a26ocOfxhsUHUbj0/view?usp=sharing

Even try to create a brand new project and see if they work or not!!

And remember you need also to use double precision export template for all platform if you use double precision!

nickpolet commented 5 months ago

An update on this:

The issue I was having at the start of this issue was related to my not updating the godot-cpp submodule before building mTerrain.

The issue above I was having seems to be related to https://github.com/godotengine/godot/issues/86346.

Unfortunately, the linux build you provided above doesn't work with me. The glibc version on Ubuntu 22.04 is behind the version you built it with (maybe manjaro or something?).

Can you let me know what versions of everything you are building?

I have a feeling I've got a mismatch between godot-cpp and godot. Knowing what you're building might help me.

mohsenph69 commented 5 months ago

I use Godot 4.1.3 And godot-cpp 4.1 latest, or the same one in the project which exist as submodule

The MTerrain library is build with GLIBC 2.7 I used ubuntu 18 which run on virtual machine to build that!

I think the problem could be from the Godot-editor which I sended you, I build that with my manjaro system which has GLIBC 3.8, I tried to build Godot-editor with ubuntu but as its gcc was old it could not build godot-editor itself

to check your version of GLIBC run this command in terminal ldd --version

Regarding the issue discussed in this: https://github.com/godotengine/godot/issues/86346

I never encounter such a problem and I don't think extension_api.json will differ for double or single precision! and by the way in this issue Godot 4.3 is used, which currently is under development

The main difference regarding the GDExtension part for double precision is this

#ifdef REAL_T_IS_DOUBLE
typedef double real_t;
#else
typedef float real_t;
#endif

which is defined in defs.hpp, What this tell is that real_t in double precision is a double and will take 8 bytes while real_t in single precision is float and it will take 4 bytes. This is the main difference, ... GDExtension in double or single precision does not have a really different c++ code!!!

Off-course there are more difference in rendering part, but that is not our concern as all of that is written inside Godot core and GDExtension has noting to do with that!

I believe it could be that your Godot-editor is not build in double precision, after you build your Godot from the source code, the Godot-editor which is in bin folder should have this name: godot.linuxbsd.editor.double.x86_64

Make sure double exist in its name!!!!! I wish Godot website provide also double precision of Godot but unfortunately we should build that by yourself now

At the end, I am not sure what could cause this problem, But if you get any other error send me!

nickpolet commented 5 months ago

I never encounter such a problem and I don't think extension_api.json will differ for double or single precision! and by the way in this issue Godot 4.3 is used, which currently is under development

I get the same for 4.2 builds as well. It's really odd. 2 builds right after another, one double, the other single precision. Different extension_api.json file.

I will try building everything with 4.1.3 and see how that goes.

I believe it could be that your Godot-editor is not build in double precision, after you build your Godot from the source code, the Godot-editor which is in bin folder should have this name: godot.linuxbsd.editor.double.x86_64

I'm pretty sure it is. All the rendering artefacts are gone when you go far from the centre point, which indicates float=64. I've done other double precision builds for the godot-voxel module in the past with success.

I'll keep going for now and see what comes of it.

nickpolet commented 5 months ago

Thanks for all the help on this. Found a solution to everything and now have a nice little buildchain going that builds godot and this for all platforms with double precision.

mohsenph69 commented 5 months ago

Happy that this finally worked!