godotengine / godotengine/godot

Error messages when running a project with a custom StyleBox in main theme

Open
#110,548 5 comments 7 reactions 0 assignees View on GitHub
bug needs testing topic:gui
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

- Reproducible in 4.5.stable
- Not reproducible in 4.4.stable

### System information

Godot v4.5.stable (876b29033) - Windows 10 (build 19045) - Multi-window, 2 monitors - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3070 (NVIDIA; 32.0.15.6094) - AMD Ryzen 9 5950X 16-Core Processor (32 threads) - 31.92 GiB memory

### Issue description

When using a custom `StyleBox` (that is, a script that `extends StyleBox`) in the project's main theme that has an `@export` parameter, running the project prints the following error 8 times:
```
E 0:00:00:851 StyleBoxSomething.gd:5 @ @implicit_new(): Parameter "SceneTree::get_singleton()" is null.
scene/debugger/scene_debugger.cpp:491 @ parse_message()
StyleBoxSomething.gd:5 @ @implicit_new()
```

I only tested this using gdscript to make the custom style box. I did not try using C#.

### Steps to reproduce

In a new project:
1. Make a new script that `extends StyleBox`. Give it a `class_name`.
2. Add an `@export var` to the script. The type doesn't matter, and it doesn't matter if it's used at all.
3. Override the script's `_draw` method (an implementation of `pass` is fine).
4. Make a new theme file.
5. In the Project Settings, set `GUI/Theme/Custom` to point to the new theme file. This step is very important. This error will not reproduce if the theme is set explicitly or if using a Theme Override.
6. Open the theme editor by double-clicking on the theme file in the FileSystem.
7. Add a new theme for a `Panel`.
8. Make its `panel` property (under StyleBoxes) use the new StyleBox.
9. Make a new scene file. Add a `Panel` as a child.
10. Run the scene. See the errors printed in the debugger panel.

The MRP should have all of this set up, and the one scene is set to be the main scene, so all you should need to do to reproduce is run the project.

### Minimal reproduction project (MRP)

[test-error-repro.zip](https://github.com/user-attachments/files/22355154/test-error-repro.zip)

Contributor guide

Open the contributing guide

Research direction

Start with the attached minimal reproduction project and run its main scene to confirm the repeated SceneTree::get_singleton() errors from the custom StyleBox. Trace how the exported custom StyleBox is initialized when GUI/Theme/Custom is loaded, then verify the project runs without those debugger errors while explicit themes and Theme Overrides retain their behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, godot
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.