-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instancing nodes in thread causes random errors #30700
Comments
With threads, Calling For Although, I don't remember if instancing nodes without adding them to the tree is safe? |
I am not using add_child() anywhere. All I am doing is instancing (tried both nodes and scripts) and adding them to a dictionary in an already instanced (in scene tree) node. Could that be a problem? I am technically not adding them to the tree. |
Try this in your game.gd
and
in your chunk.gd
|
actually i stumble to this weird phenomena 3 month ago. i just think i am just too dumb to report this as bug maybe i don't know what is reference counting should behave in thread. you don't need scene btw just simple script and extends object, instance it on thread and join the thread to main thread carry the object and use it in main thread, and this null reference thing crash the game even editor. |
Eh, I was going to create a similar issue, but it would be too similar, so commenting here. The project attached in the OP doesn't crash for me. However, I have a project that crashes pretty consistently. I'm just hoping someone with more debugging could pinpoint the issue >_> Also I'd vote for labelling this issue as High Priority, because I'm having it for months and have no idea what to do about it ;_; |
EDIT: As noted by @santouits below, this particular issue was fixed at 274bac2783 These bugs are similar to: I am also having the random error that @KoBeWi is having: It seems to always be called on Children and Grandchildren of my active scene. |
The "Attempt to call function 'XXX' in base 'previously freed instance' on a null instance" issues should have been fixed by this, but I can't run your project because it is not compatible with the master branch. |
I ran the project in the OP five times without any crash, so I assume it might have been fixed by #30934. @KoBeWi's project did not trigger a crash for me, but I get an insane amount of errors when running it on the master branch (mostly physics related). Once I got a freeze of the game in an infinite loop spouting these errors endlessly:
I think there are too many bugs in that projects too properly diagnose what could cause the crash in a thread. I'll close this issue as the bug in OP seems to be fixed. There might still be projects that reproduce weird errors from threads, but it's probably worth opening a dedicated issue for each, unless they are all minimal projects with similar code. |
I got in KoBeWi reproduction project(https://github.com/godotengine/godot/files/3538958/MaximalReproductionProject.zip) this invalid write(Godot 3.2 Beta 4) in Adress Sanitizer
|
Not sure if this a regression in 3.3 (commit 77d0412).
|
FYI it doesnt seem mentionned in this issue, but since my last comment I learned that in Godot 3.x, |
That's good to know, thanks for mentioning. The scene I was instancing just has 1 MeshInstance with 1 ShaderMaterial that has a NoiseTexture and another texture. Maybe some part of this code path also isn't thread safe for unexpected reasons. |
@kdlee: IIRC shader compiling isn't thread safe either, so instancing any meshes can/will lag and have issues. |
@Zireael07: Ah thanks, I think this explains. If I preload the scene from main thread, and turn off 'Local To Scene' for this ShaderMaterial that's being instanced, seems to not crash. I guess 'Local To Scene' is causing each instance() to recompile the shader while that doesn't work in threads? EDIT: Actually from debugging, seems like shader compile only happens once on main thread when I preload. There seems to be just some issue with cloning 'Local To Scene' ShaderMaterial from another thread. |
Godot version:
3.1.1 (Steam Stable)
OS/device including version:
Windows 10 64-bit
Issue description:
I am in the middle of making a simple voxel engine and previously used dictionaries to store block information. However, I wanted to use a list of Block objects and so used load("Block.gd").new() and found that I was getting random crashes that had nothing to do with what I had changed and disappeared when switched back to using dictionaries. I then changed it to instance nodes using load("Block.tscn").instance() however it yielded the same result. This bug has taken me about a month to realize what it was. :(
Steps to reproduce:
Run the project which won't display anything but instance a bunch of nodes on a thread. Sometimes it works fine. If it doesn't crash within 15 seconds, try re-running. It really is pretty random.
Minimal reproduction project:
https://drive.google.com/uc?export=download&id=1juo3WX4UPsXRkiMmM84eVkcyzXlUha0E
The text was updated successfully, but these errors were encountered: