In which cases can a Dictionary go into read-only mode?

Godot Version

4

Question

I run into this every now and then. I have a suspicion that in my case the Dictionary value which I typed as a Node class (that automatically seems to get assigned NodePath) is freed, which may trigger read-only mode.. but then again, it may have a different reason.

Can someone point me to source code that turns on read-only mode for Dictionaries?

Or is it only while iterating over keys for instance?

Are you looking for this?

More specifically in which cases the core engine calls this, because it seems to be triggered by edge cases.

I can assume while it is being accessed to be iterated so it cannot be mutated from another thread…

Yet sometimes a dict seems to get stuck in this state.

Afaik the only case aside from declaring it const may be when the dictionary is in a resource loaded at runtime.

Thanks.. I will keep observing the pattern. It is of course caused by plugin development choices during edit time.

Do you (de)serialize the dictionary in question?

Not proactively no.

I suspect another culprit then. Maybe an npe somewhere.

I get no stacktrace… Can I get that in console mode?

Culprit found:

  1. setting a default value will cause
  2. the reference to be lost when the revert button is clicked (i.e. there is a dangling reference to the old Dictionary in the plugin code → and this dangled about Dict is read-only don’t touch now)
  3. until the scene is closed and reopened again