Godot Version
4.3-stable (double)
Question
I realise this is a bit of an open ended question, but I am at a loss. I have a GDExtension that I have been working on that uses a CMake build system instead of SCons. It integrates with my IDE (CLion) better than Scons and I am more familiar with it, so doing things like linking in extra libraries is much more natural to me.
But when building with double precision enabled I am getting issues that I wouldn’t normally expect. The current one is that I am unable to edit custom resources.
I have a custom class that exposes a Vector3 object, in single precision mode this works exactly as intended. You create a new resource file, open it in the inspector and change the values. But when I build with double precision (making sure to pass in the extension_api.json that was created by a double precision build of Godot 4.3) upon editing the resource file it throws a memory access exception.
I’m not sure what’s causing this behaviour so I was hoping someone would know if the godot-cpp scons file does anything special when building with double precision in mind. I did make sure that when using FetchContent to get the godot-cpp file that I added the FLOAT_PRECISION = double
as a cache variable so that it would be propegated to the godot-cpp CMake file
Thanks in advanced
The CMake solution for 4.3 and lower is very sparse, you will need to almost re-create the whole thing. I’ve been submitting changes for updating and am making progress.
There are two steps, firstly the python bindings_generator.py uses the flag to generate appropriate sources.
And the definition REAL_T_IS_DOUBLE is added to the compile command.
There are a few projects which are linked from discord discussions which people find useful like the roguelite example project.
You might also checkout master and see how things will change and perhaps backport to your version,
Thanks, I suspected that that was the case for CMake and I was hoping that I was simply missing something stupid that would have been an easy fix. Unfortunately, I do both things that you mention. This is my CMake function for getting godot-cpp:
function(get_and_link_godot_cpp TARGET TAG PRECISION EXTENSION_FILE)
set(GODOT_ENABLE_HOT_RELOAD ON CACHE INTERNAL "Enable hot reloading support")
set(GODOT_CPP_SYSTEM_HEADERS ON CACHE INTERNAL "Generate system headers")
set(GODOT_CPP_WARNING_AS_ERROR OFF CACHE INTERNAL "Treat warnings as errors")
set(GENERATE_TEMPLATE_GET_NODE ON CACHE INTERNAL "Get template node")
set(FLOAT_PRECISION "${PRECISION}" CACHE INTERNAL "Library precision")
set(GODOT_CUSTOM_API_FILE "${EXTENSION_FILE}" CACHE INTERNAL "Extension api file")
include(FetchContent)
FetchContent_Declare(
godot-cpp
GIT_REPOSITORY https://github.com/godotengine/godot-cpp.git
GIT_TAG ${TAG}
GIT_SUBMODULES_RECURSE 1
)
FetchContent_MakeAvailable(godot-cpp)
set_target_properties(godot-cpp PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
)
# Turn on LTO and export compile commands for VSCode to use
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
target_link_libraries(${TARGET} PRIVATE godot-cpp)
endfunction()
As you can see I store all the values that are mentioned in godot-cpp’s CMakeLists and I also added print statements to ensure that they were still set inside godot-cpp’s CMakeList. I’m also having this issue with hot reloading to where GODOT_ENABLE_HOT_RELOAD is set but otherwise has no effect.
I will do what you suggested and take a look at the main branch to see if it indicates anything that needs changing.
I haven’t tested using double precision atm, I’m still focused on proving out the web infrastructure using CMake, but I can change focus to this next if you like. Do you have a test project that demonstrates the issue? Since your gdextension does infact load, perhaps stepping through with a debugger might be able to highlight the problem.
As a separate issue:
You’ve got to watch out to set CMAKE_* things before targets and projects depending. See the documentation : INTERPROCEDURAL_OPTIMIZATION — CMake 3.31.3 Documentation
It states: “This property is initialized by the CMAKE_INTERPROCEDURAL_OPTIMIZATION variable if it is set when a target is created.”
So that means that the targets created by MakeAvaialble above do not have this property set.
but I can change focus to this next if you like. Do you have a test project that demonstrates the issue?
I do actually. Not so much a test project, but just my actual project here. l’d certainly appreciate a second pair of eyes.
The configure command should be cmake -B ./build -DPRECISION="double" -DEXTENSION_FILE="./templates/extension_api.json2
. It’s currently fixed to 4.3-stable
You’ve got to watch out to set CMAKE_* things before targets and projects depending
Cheers, I will keep an eye open on it. Thanks again