godotengine / godotengine/godot
Existence of Static Function Prevents Access of Unrelated Static Variable
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
Reproducible in 4.2stable, 4.3 stable
### System information
Windows 11 - Godot 4.2stable, Godot 4.3 stable
### Issue description
I truly do not know why this is the case, but in my project the very existence of the below code causes a crash when attempting to access an unrelated static variable. This function is not called before the crash occurs.
```gdscript
class_name CardHelpers
...
static func arrow_to_target_k(origin:CardStub, target:PilotButton)->void:
#TODO: Add color and/or texture as arguments
var arrow:TargetArrow = load("res://engine/common/ui_scenes/target_arrow.tscn").instantiate()
origin.add_child(arrow)
arrow.unpack(origin.global_position, target.global_position)
```
The existence of "arrow_to_target_k" causes a crash elsewhere in the project when attempting to access a static variable.
This code:
```gdscript
class_name CardHelpers
....
static func card_by_id(id:String, origin:String)->LogicalCard:
if origin == "pilot":
return PilotCardLib.lib[id]
```
causes the error below:
`Invalid access to property or key 'lib' on a base object of type 'GDScript'.`
### Steps to reproduce
Hit "new game" after running this branch: https://github.com/BluntBSE/ultra_mayor_2/tree/non_crashing_example
to see intended behavior
Hit "new game" after running this branch: https://github.com/BluntBSE/ultra_mayor_2/tree/crashing_example
to see the crash
### Minimal reproduction project (MRP)
Steps to reproduce not exactly known. Crashing/non crashing branches posted above.
_Bugsquad edit:_ Fix codeblock formatting.
Contributor guide
Research direction
Start by comparing the non_crashing_example and crashing_example branches, then reproduce the failure by hitting “new game.” Investigate how GDScript handles the presence of the unused static function and the later access to PilotCardLib.lib; done means the crashing branch no longer reports invalid access to 'lib' while preserving the intended behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- godot
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100