-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pool*Array instances should be references and not values in GDscript #8409
Comments
OK, did some digging the problem seems to be that I think @reduz needs to way in on this. |
OK, After understanding a bit more. I don't think it's they should be values for them as Array and Dictionary are not Values. |
Just found this oddity as well, thankfully I was aware of other COW things but I thought they were due to be removed in GDScript for 3.0? In Godot 2.1.3 and 3.0 master, the following test is a fail: func _ready():
test()
static func lol(a):
a.resize(42)
static func test():
var a = PoolVector3Array()
lol(a)
assert(a.size() == 42)
print("Test succeeded ", a.size()) @reduz any way of dealing with this? |
those are often sent to other threads and require locking for manipulation, so making them share data can lead to unexpected behavior. A solution may be to use an internal variant reference counter and making them shared only in GDScript.. |
What about GDNative scripts that do mesh generation? Those also have to give PoolArrays back to Godot, but they can't lock them for performance AFAIK. |
Zylann It should be perfectly possible to lock them in GDNative, would need to ask Karroffel to implement it |
Still undecided on this, so kicking to 3.1 |
I've run afoul of this as well, just as a data point. Exposing a lock/unlock method so you can get mutable references in GDscript/GDNative would be one way? Seems pretty important to be able to get a reference to a PoolArray somehow. |
Read/write locks have been exposed to GDNative, but GDScript still doesn't have it (it's important to remember that even if GDScript doesn't touch them, it may pass them around quite often!) |
I still think these should be reference counted when inside of variant and shared (but not by themselves when passing to a function). This is considerable amount of work to change, though so for now will kick to 3.2 unless anyone wants to do it. |
This is scheduled to change after 3.1 is out.
…On Thu, Jan 24, 2019, 10:39 avencherus ***@***.*** wrote:
Also ran into this with dictionaries.
extends Node2D
func _ready():
var dict = {
vecs = PoolVector2Array()
}
print(dict.vecs)
dict.vecs.append(Vector2())
print(dict.vecs)
[image: image]
<https://user-images.githubusercontent.com/13004169/51681723-2e3df280-1fee-11e9-9606-3699934aad39.png>
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#8409 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF-Z25Rc3yD47e4TxhGbutPHqkK5Ddn2ks5vGbecgaJpZM4M90F6>
.
|
Is this still an issue with Packed*Array? cc @reduz |
Yes this is fixed by #36311. |
In some cases this doesn't work: func _ready():
var p2d = Polygon2D.new()
var polygon = PackedVector2Array([Vector2(0, 0), Vector2(100, 0), Vector2(100, 100), Vector2(0, 100)])
p2d.polygon = polygon
print(p2d.polygon)
p2d.polygon.push_back(Vector2(213, 123))
print(p2d.polygon) # same as `polygon`
# var poly_copy = polygon
# poly_copy.push_back(Vector2(213, 123))
# p2d.polygon = poly_copy But It does work with dictionaries and other Variant containers as described above. |
I have stumbled upon a similar bug and curious if this is also related:
prints:
however,
prints
|
Operating system or device - Godot version:
Issue description:
Calling PoolStringArray.push_back() sometimes silently does nothing.
Steps to reproduce:
outputs [PRE, POST] instead of [PRE, I'm B, POST]
Link to minimal example project:
The text was updated successfully, but these errors were encountered: