Comments (10)
I agree with you, and the proxy sounds like a good idea !
Just to be sure I understand what you meant :
Lets say the [ ]
operator of Array
return an ArrayItem
.
- As you said it would have a conversion operator to
Variant
. - And for the the
&
operator it would return aconst Variant *
or aVariant *
, address of the proxiedVariant
.
The potential issue I see here is that if the Array
is read-only the &
operator should return a const Variant *
and a Variant *
if not. But we don't know that at compile time...
from godot.
A potentially dirty but I'd say sufficient solution might be to add a proxy for the non-const return, akin to CharProxy
of strings, this would error on write and handle that correctly, and be safely cast to Variant
, but unsure exactly what that would entail
Alternatively the proxy would simply work like the read-only
value but individually for each copy
Edit: Doing some testing with a proxy based solution
from godot.
from godot.
We could also make the Variant
read-only by itself, it has already a method is_read_only
but that only checks for read-only arrays and dictionaries. But I like the proxy idea as well.
from godot.
The is_read_only
refers to if it is a read-only Array
or Dictionary
, I don't think messing with the insides of Variant
is useful here, the issues should be solved in Array
and Dictionary
IMO
from godot.
My idea was the following :
If a Variant
is marked as "read-only" the underlying data cannot be modified.
In this context a read-only array contains only Variants
marked as "read-only". Trying to use the =
operator would fail.
Of course this doesn't serve the same purpose as the original is_read_only
as you mentioned.
from godot.
Again I'd say this fix should be local, not in Variant
, only of no other way to fix this can be achieved reasonably should we mess with Variant
IMO
from godot.
With some testing the immediate concern is that the resulting value would need to copy a lot of behaviour from Variant
if it is to be a drop-in replacement, as c++ doesn't allow access via casting etc., so with a proxy type you can't trivially do arr[0].get_type()
unless those methods are all transferred
Adding some read-only state to Variant
would have its own issues, like how would you transfer it to get a mutable result? It'd only make sense to retain immutability on reference, not copy, so that makes the read only state very niche
Will keep testing out some ideas for the proxy and potential adjustments across the code to account for it
The most trivial solution would be to replace the current read only data with another vector, but that would be pretty fragile I think, and wasteful, the issue is having the ability to produce a unique, discardable value for each access, but that would be difficult without leaking memory
The even more trivial but less safe solution would just be to not protect the subscript at all, this might be an acceptable temporary solution
from godot.
Some candidate solutions:
- A proxy object, see above for concerns
- No protection at all, just return a reference
- Add some kind of individual protection without a proxy (can't imagine how)
- Rewrite access to work like
Vector
with awrite
proxy that simply ignores the value if read-only, this would probably be the simplest but would require a lot of reworking to replace the access that would now use non-const references
Did some basic work but probably won't be able to focus on a direct fix on this for the time being, but some loose pointers
from godot.
That proxy return variant is cursed. 🙈
There are 3 constraints the array currently tries to fulfill:
Variant get(int p_index) const;
Variant const& get_ref(int p_index) const;
Variant& get_mutable_ref(int p_index);
Any solution needs to satisfy the above. The get_ref could be deleted.
from godot.
Related Issues (20)
- platform differences in rendering openXRCompositionLayers with Hole Punch feature
- Inconsistent behavior when undoing animation bezier movements upon selection of different animations HOT 1
- Signal 11 crash with no debug info in backtrace HOT 21
- Some weird behaviour involving CanvasLayer, Viewport and World2D HOT 3
- Round primitive meshes contain gaps. HOT 1
- Fullscreen mode's border color does not update when transparent background is disabled HOT 4
- FileSystem shows custom Resource icon of first external dependancy instead of correct icon HOT 1
- MultiMesh custom data bits are not accurate HOT 2
- Resource (re)importing speed is affected by editor framerate, leading to slow import speeds when the window is unfocused
- LineEdit sometimes does not display the last character
- ShapeCast3D detects colliders behind it HOT 5
- Log chinese error. HOT 3
- UV Map Node Ignored in GLTF/GLB Import HOT 2
- Main submenus are all black sometimes (XWayland windows, Nvidia) HOT 3
- PhysicsShapeQueryParameters3D's exclude array seems to be ignored in PhysicsDirectSpaceState3D intersect_shape func. HOT 7
- "Create New Node" dialog main scrolling area is not scrolled up to the top when summoning it HOT 1
- NoThreads Web export : AudioStreamPlayer's finished() signal doesn't emit when sound is done playing. HOT 1
- Disabling (integrated) script editor through 'Manage Editor Features' also disables ability to open external script editor. HOT 1
- Error building Godot on Arch Linux HOT 1
- CollisionObject2D param type mismatch between _InputEvent method and InputEvent delegate
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from godot.