memory management #210
Unanswered
bricerebsamen
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello
I'm starting to write an application based on OWL. The basic idea is that I create a context once at the beginning, then create a scene with a few objects (triangle meshes) which move around and sometimes disappear and then new ones appear. Then I raycast against the same scene several times (from different camera angles). So in this case it makes sense to create a blase per object in the scene when they appear and keep them around, regenerate the tlas only when the blases change (either different set of blases or they moved).
All of that was working fine in my unit tests until I started to work on recycling the memory of the various buffers. Now I get some raycasting results that are not deterministic: it might work for the first iteration but then it gives me wrong results. Since my objects all have more or less the same number of triangles, and I have more or less always the same amount of objects, I am trying to reuse all the buffers.
So my question is how do the different owl objects relate to one another? I see in the code that all the OWL* objects are defined as pointers to some structs (e.g. OWLBuffer). But the comments for owlBufferRelease mention some reference counting. There are also some
::SP
types for shared pointer. I treat an OWLBuffer as a raw pointer: I init it with nullptr, create it with owlBufferCreate, and destroy it with owlBufferRelease. But since the create calls require a context, I wonder whether there might be some reference to the existing buffers in the context? It's also not clear to me which object takes ownership of which. For instance in my earlier version I was not keeping a handle to the buffers or the OWLGeom used when creating the OWLGroup and it seemed to be working well but perhaps I had a memory leak...Warning: heavy details section ;)
For instance a blas is made of a buffer of the vertices (OWLBuffer), one for the indices, a OWLGeom and a OWLGroup. I created a Blas class to group them, always encapsulated in a unique_ptr for easy move only semantic. Upon creation I call owlDeviceBufferCreate on the index buffer and vertex buffer (with a null ptr for the init data, just to allocate the memory). Then I call owlBufferUpload on them to populate them with proper data. Then I create a geometry with owlGeomCreate, owlTrianglesSetIndices, owlTrianglesSetVertices, and owlGeomSetBuffer. Finally I create a group with owlTrianglesGeomGroupCreate and owlGroupBuildAccel. At destruction time I call owlGroupRelease, owlGeomRelease, and owlBufferRelease (twice), in this order. Same idea for the tlas and the rays. When I run this only once it works, but when I run this several times in a for loop (with the same context, created outside of the for loop), it starts failing (doesn't crash, just starts giving me nonsensical results). Perhaps I'm doing some double free...
Apologies for the heavy post but I feel that I had to provide some details
Beta Was this translation helpful? Give feedback.
All reactions