You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After introducing VoxelServer, which is a singleton created in register_voxel_types() and destroyed in unregister_voxel_types(), now all the threads used for voxel processing are shared between voxel nodes, using a thread pool (see #188). That pool is stored in the VoxelServer singleton. That means that when the game exits, a thread could still exist and task results not handled yet. These tasks are just waited for and then destroyed when the VoxelServer singleton is destroyed.
However, users can write custom world generators with GDScript. Such generators are resources that can be referenced by these tasks. And it's impossible to free scripts correctly in that case, because GDScriptLanguage::singleton is destroyed before the voxel module. A similar problem might occur for other languages.
There is no "pre-destroy" prepass of any sort that I'm aware of in Godot which could help freeing these dependencies between singletons.
So instead, I might rely on some sort of autoload which I'll shove into the scene tree somehow (this also requires awkward code to get in), and when that node is destroyed, will clear up all data VoxelServer is referencing.
I really don't like doing these workarounds so I hope something better can be done in the future...
The text was updated successfully, but these errors were encountered:
Something could be proposed, but I'm not sure what. One way would be to have a prepass before unregistration of modules, so that they can cleanup any ref they could be indirectly holding from others (even though modules likely don't depend on each other explicitely), then free their singletons in the second pass that we have currently.
For now I found a slightly better workaround which is to clear every pending tasks when the last voxel node is unregistered (which does happen on exit, but can also happen in game or editor).
Writing this issue to keep track of the problem.
After introducing
VoxelServer
, which is a singleton created inregister_voxel_types()
and destroyed inunregister_voxel_types()
, now all the threads used for voxel processing are shared between voxel nodes, using a thread pool (see #188). That pool is stored in theVoxelServer
singleton. That means that when the game exits, a thread could still exist and task results not handled yet. These tasks are just waited for and then destroyed when theVoxelServer
singleton is destroyed.However, users can write custom world generators with
GDScript
. Such generators are resources that can be referenced by these tasks. And it's impossible to free scripts correctly in that case, becauseGDScriptLanguage::singleton
is destroyed before thevoxel
module. A similar problem might occur for other languages.There is no "pre-destroy" prepass of any sort that I'm aware of in Godot which could help freeing these dependencies between singletons.
So instead, I might rely on some sort of autoload which I'll shove into the scene tree somehow (this also requires awkward code to get in), and when that node is destroyed, will clear up all data
VoxelServer
is referencing.I really don't like doing these workarounds so I hope something better can be done in the future...
The text was updated successfully, but these errors were encountered: