godotengine / godotengine/godot

Crashing at 2^24 Object Limit

Open
#108,152 15 comments 1 reaction 0 assignees View on GitHub
discussion documentation topic:core
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

- Reproducible in 4.3
- Reproducible in 4.4.1

### System information

Godot v4.3.stable.mono - Windows 10.0.26100 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4060 Laptop GPU - 13th Gen Intel(R) Core(TM) i9-13900H (20 Threads) Godot v4.4.1.stable.mono - Windows 11 (build 26100) - Multi-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4060 Laptop GPU - 13th Gen Intel(R) Core(TM) i9-13900H (20 threads)

### Issue description

When running a Godot Project, if the number of objects reaches 2^24 (or 16777216), the Project will crash.
(NOTABLY: This is separate from issue 104176 (Though you can replicate issue 104176 by simply extending a Godot class in the second script, but that'd stop you at 2^18 instead of 2^24 so you wouldn't see the results of this issue))

(The error outputs)
For Godot v4.3:
```
ERROR: FATAL: Condition "slot_count == (1 << 24)" is true.
at: add_instance (core/object/object.cpp:2202)

================================================================
CrashHandlerException: Program crashed with signal 4
Engine version: Godot Engine v4.3.stable.mono.official (77dcf97d82cbfe4e4615475fa52ca03da645dbd8)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
```
For Godot v4.4.1:
```
ERROR: FATAL: Condition "slot_count == (1 << 24)" is true.
at: add_instance (core/object/object.cpp:2296)

================================================================
CrashHandlerException: Program crashed with signal 4
Engine version: Godot Engine v4.4.1.stable.mono.official (49a5bc7b616bd04689a2c89e89bda41f50241464)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
```
(The backtraces didn't wind up printing)

Addendum:
Consider the following perspective: imagine you have a 2048x2048 map 2^22. Presently this means there can be no more than 4 Objects per 'tile'. Personally, I find this fairly limiting. Imagine now if you wanted your map to have some verticality instead of just being a 2D grid, lets say 1024x1024x16. Oh- all the objects are gone. Personally, I find this fairly limiting.

### Steps to reproduce

1. Create a project
2. Create a script attached to the root node
3. Create a second script (alone, not attached) with a makeshift class (can be completely empty, just has to be something that can be instanced)
4. In the first script, use a simple while loop or nested for loops to append newly instanced objects of the class in the second script to an array
---- Adding Objects as values in a numerically keyed Dictionary also achieves the same result
---- Adding the Objects in a 2D Array achieves the same result
5. (In the while loop or however you're doing this, print every x objects to see how many are stored in the array when it crashes)
6. Wait for Godot to crash upon reaching 2^24 objects

Root Node script:
```gdscript
extends Node2D

var numObjs:int = 0
var objectArr = []
var objectArr2 = []
# Will crash when the number of Objects reaches 2^24 (16777216);
# You should see it stopping at '16760832', or 1024x1023x16 due to the placement of the print statement
# Division into other Arrays doesn't stop it.
func _ready():
for x in range(1024):
var tempArr = []
for y in range(1024):
var miniObjectArr = []
for z in range(16):
miniObjectArr.append(proxyNode_C.new())
numObjs+=1
tempArr.append(miniObjectArr)

# Shows that it will crash regardless of if you split it into arrays that don't reference each other
if numObjs < 12000000:
objectArr.append(tempArr)
else:
objectArr2.append(tempArr)
print(numObjs)
print("||Did not crash|| - ",numObjs)

func _process(delta:float):
pass
```

Detached Script:
```gdscript
class_name proxyNode_C

func _ready():
pass
```

### Minimal reproduction project (MRP)

N/A- was going to include a MRP anyways but I keep getting 'failed to upload'.

Contributor guide

Open the contributing guide

Research direction

Reproduce the crash with the provided GDScript loops, then inspect add_instance in core/object/object.cpp at the referenced failure lines (2202 in 4.3 and 2296 in 4.4.1). Trace how slot_count reaches the 2^24 condition and compare behavior at the boundary; done means the reported object limit no longer causes an unhandled crash or its intended behavior is covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.