Fix Dictionary::operator[] from C++ accidentally modifying const dictionaries.#106636
Conversation
…dictionaries. Fix `AudioStreamWav` inserting keys into the input dictionary.
02b6570 to
0be2a77
Compare
| return _p->variant_map[key]; | ||
| static Variant empty; | ||
| const Variant *value = _p->variant_map.getptr(key); | ||
| ERR_FAIL_COND_V_MSG(!value, empty, "Bug: Dictionary::operator[] used when there was no value for the given key, please report."); |
There was a problem hiding this comment.
Is this something that engine users can trigger with their own code, or only something that would be triggered by invalid engine code? Even if only the latter, the please report may lead to people reporting bugs triggered by their own fork or thirdparty modules, so maybe it needs to be phrased differently (maybe just drop please report)?
There was a problem hiding this comment.
Good question! I had to look it up. The function is exposed in variant_setget.cpp, which uses getptr and makes its own NULL checks. get() and get_or_add (in variant_call.cpp) likewise use getptr. So i believe the operator[] is only used internally.
|
Thanks! |
|
Hey I was running the newest master with my personal project and it kept spamming The error message happens whenever I save a script in an external editor (haven't tested godot editor yet), and then the script is supposedly reloaded (happens in editor with @tool scripts and when saving while in-game too). I get 3-12 error messages at once. What could I do to further help investigate this behaviour? |
|
Hi @ultsi, thanks for tracking this down so far! What we'd need to find out what's causing the problem is a stack trace. I tried reproducing the error message by editing a gdscript file in an external editor, but did not get the same error message as you. Otherwise, if you know how to work with breakpoints, you could also find the stacktrace yourself. It would require adding a breakpoint on |
|
Hey took me a while to learn gdb but managed, so here's the stacktrace @Ivorforce . Don't mind the 137 line instead of 136, added a line to help me set a breakpoint there, so 137 here is the I also have |
|
Hmm it seems that |
|
@Ivorforce I opened up a PR, have a look #111684 |
Dictionary(and possiblyArrayandNodePath). #106600This fixes a long standing subtle bug where
Dictionarycan be accidentally modified onconstoperator[]subscript.Since #106600 might take a while longer to merge (since it introduces a new type to bikeshed over), I thought it may be appropriate to PR the most important fix separately, so we have time to work through possible regressions.