mirror of
https://github.com/godotengine/godot.git
synced 2025-12-07 22:00:10 +00:00
Merge pull request #106636 from Ivorforce/dictionary-mutating-fix
Fix `Dictionary::operator[]` from C++ accidentally modifying `const` dictionaries.
This commit is contained in:
commit
d4a87d9bb3
2 changed files with 14 additions and 12 deletions
|
|
@ -131,8 +131,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue