You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This might be just clarification needed in the documentation.
Previously I could make a list of instances of pyo3 class Texture in python and pass that list to a method as Vec<&Texture>. Now however I have to impl Clone for Texture and define the method argument as Vec otherwise I get a compiler error
the trait pyo3::FromPyObject<'_> is not implemented for `std::vec::Vec<&core::Texture>
But this scrambles the behavior. Texture is a pyo3 wrapper for a rust struct containing a large array of pixels as well as OpenGL references. By passing the ownership into the class method the GL ref gets dropped then reused by other Textures. If I don't pass the Texture references in as a list but individually it all works fine. I tried defining the method argument as &PyList but that doesn't help (see question here)
Is there a straightforward way to do this or do I have to refactor my code by ref counting Textures or such like?
The text was updated successfully, but these errors were encountered:
Can you try using Vec<PyRef<Texture>>? I believe that should work. To make pyo3's APIs safe in the face of python's shared mutability model a refcell-like mechanism has been added.
In the future, if you don't ever need Texture instances to be mutated from Python then I'd like to provide a way to opt-out of the pycell system so you can have Vec<&Texture> again - see #1068
@davidhewitt That's exactly what I needed. It works fine and is more explicit about what's actually going on than the Vec<&
In this instance the extra overhead unpacking a pycell is low as the GL Texture2D ref is passed relatively infrequently (If it needed to be unpacked for every draw on every buffer on every frame then that would be more of an issue)
This might be just clarification needed in the documentation.
Previously I could make a list of instances of pyo3 class Texture in python and pass that list to a method as Vec<&Texture>. Now however I have to impl Clone for Texture and define the method argument as Vec otherwise I get a compiler error
But this scrambles the behavior. Texture is a pyo3 wrapper for a rust struct containing a large array of pixels as well as OpenGL references. By passing the ownership into the class method the GL ref gets dropped then reused by other Textures. If I don't pass the Texture references in as a list but individually it all works fine. I tried defining the method argument as &PyList but that doesn't help (see question here)
Is there a straightforward way to do this or do I have to refactor my code by ref counting Textures or such like?
The text was updated successfully, but these errors were encountered: