urho3d/urho3d

TileMapLayer2D using raw pointers to RefCounted

SirNate0 opened this issue · 4 comments

You can see from a copy of the documentation, TileMapLayer2D is using 4 const raw pointers to various layer/group data. All of these classes derive from RefCounted, though, so I'm not sure why they are not weak pointers or shared pointers instead.

Type Variable From Docs TileMapLayer2D.h
const TmxLayer2D * tmxLayer_ {}  Tmx layer.
const TmxTileLayer2D * tileLayer_ {}  Tile layer.
const TmxObjectGroup2D * objectGroup_ {}  Object group.
const TmxImageLayer2D * imageLayer_ {}  Image layer.

Disclaimer: I have basically no experience with the Urho2D side of things, I'm just coming across some things with it in trying to automate the Lua bindings. It wouldn't affect me, except the bindings store all things derived from RefCounted in SharedPtr (so the Lua will own a copy) and I can't construct a SharedPtr from the const T* because AddRef() cannot be called on a const object.

1vanK commented

I believe that bindings should not restrict the style of C++ code, C++ code authors should not think about bindings, that's the meaning of automation. Anything that cannot be binded automatically can be binded manually

I agree fully with that notion. I just am wondering in this case if the existing code is incorrect (or really, not following the best practice - it obviously functions correctly). Since the pointed-to objects are RefCounted, why is the count not being updated by the TileMapLayer2D object to reflect that it is using them? There are several possibly good reasons for the code being the way it is, I'm just not aware of them myself (and am not interested enough in 2D games to try and figure it out on my own).

1vanK commented

I haven't done any deep research, but it looks like the objects are created and destroyed in another class, so everything works as it should.

Marking this stale since there has been no activity for 30 days.
It will be closed if there is no activity for another 15 days.