godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

Invalid Signed Integer Literal (-2147483648) in RenderingServer.hpp Causes Cross-Compiler Error

Open CycloneRing opened this issue 5 months ago • 4 comments

Godot version

4.5.beta

godot-cpp version

latest

System information

Windows 11 - MSVC

Issue description

There's a compiler issue after adding CANVAS_LAYER_MIN to godot-cpp, After compiling the library and headers there will be :

	static const int CANVAS_LAYER_MIN = -2147483648;
	static const int CANVAS_LAYER_MAX = 2147483647;

Which causes error in compile :

godot_cpp\classes\rendering_server.hpp(805,38): error C4146: unary minus operator applied to unsigned type, result still unsigned.

Here's the lines from extension_api.json

{
	"name": "CANVAS_LAYER_MIN",
	"value": -2147483648 <- TYPO
},
{
	"name": "CANVAS_LAYER_MAX",
	"value": 2147483647
}

Steps to reproduce

  1. Clone godot-cpp repo
  2. Build
  3. Link against GDExtension with usage of Rendering Server

How to fix :

Change -2147483648 to -2147483647 or use (-2147483647 - 1)

CycloneRing avatar Jul 21 '25 12:07 CycloneRing

Okay it's a issue in engine itself, closing this and make a new one to engine.

CycloneRing avatar Jul 21 '25 12:07 CycloneRing

Issue still exists in 4.6 @dsnopek can you please check this. On both msvc and clangcl i get the error for CANVAS_LAYER_MIN

godot_cpp\classes\rendering_server.hpp(814,38): error C4146: unary minus operator applied to unsigned type, result still unsigned

At generated rendering_server.hpp :

static const int CANVAS_LAYER_MIN = -2147483648; <- HERE
static const int CANVAS_LAYER_MAX = 2147483647;

It must be generated like this

static const int CANVAS_LAYER_MIN = (-2147483647 - 1);
static const int CANVAS_LAYER_MAX = 2147483647;

CycloneRing avatar Oct 25 '25 03:10 CycloneRing

Thanks!

However, I'm not sure I understand why this is an error?

The value of CANVAS_LAYER_MIN is -2147483648 in Godot itself:

https://github.com/dsnopek/godot/blob/c0c1c685621971c75c0f0f4aab85e8293c67a993/servers/rendering/rendering_server.h#L105

This is the code generated currently in godot-cpp:

static const int CANVAS_LAYER_MIN = -2147483648;

This is a signed integer, and, as far as I know, -2147483648 is a valid value for a signed 32-bit integer.

Whereas the error says "unary minus operator applied to unsigned type, result still unsigned"

Why does it think this integer is unsigned? And why does switching to (-2147483647 - 1) somehow fix that?

dsnopek avatar Nov 01 '25 12:11 dsnopek

@dsnopek You're right that -2147483648 is a valid signed 32-bit value, but the issue is how the compiler parses it. 2147483648 exceeds INT32_MAX, so it's treated as an unsigned literal... Applying unary minus to that triggers the error: "unary minus operator applied to unsigned type, result still unsigned." on msvc and msclang.

Using (-2147483647 - 1) avoids this by staying within signed literal bounds and evaluating correctly at compile time. It's a common workaround for expressing INT32_MIN safely across compilers.

CycloneRing avatar Nov 02 '25 21:11 CycloneRing