Fix Dictionary::operator[] from C++ accidentally modifying const dictionaries.

Fix `AudioStreamWav` inserting keys into the input dictionary.
This commit is contained in:
Lukas Tenbrink 2025-05-20 15:41:19 +02:00
parent 4fcd85551c
commit 0be2a77156
2 changed files with 14 additions and 12 deletions

View file

@ -127,8 +127,10 @@ const Variant &Dictionary::operator[](const Variant &p_key) const {
VariantInternal::initialize(_p->typed_fallback, _p->typed_value.type);
return *_p->typed_fallback;
} else {
// Will not insert key, so no initialization is necessary.
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.");
return *value;
}
}