User avatar
Gazoo
Topic Author
Posts: 36
Joined: 14 Sep 2022, 10:00
Contact:

Ownership of the Noesis::IView object in the IntegrationGLUT example

02 Jan 2023, 16:34

Having succesfully adapted the 'IntegrationGLUT' example for NoesisGUI in the Cinder framework, I'm confused about the ownership of the Noesis::IView resource used in the example.

The example states ~Line 102:
// View creation to render and interact with the user interface
// We transfer the ownership to a global pointer instead of a Ptr<> because there is no way
// in GLUT to do shutdown and we don't want the Ptr<> to be released at global time
_view = Noesis::GUI::CreateView(xaml).GiveOwnership();
At this stage, does the NoesisGUI internally also hold/own the IView object created?

My assumption is yes, as my own attempts to releasing the resource in the right place have so far caused crashes. The only non-crashing shutdown I've managed to build is one that doesn't do anything with the returned pointer (upon shutdown).

But if NoesisGUI holds this resource, I'm a tad confused as to why it's possible for me to get a ptr to it, on which I can call GiveOwnership(), and yet still not be responsible for managing said resource.

Clearly I'm not understanding something here.

Cheers,
Gazoo
 
User avatar
jsantos
Site Admin
Posts: 3640
Joined: 20 Jan 2012, 17:18
Contact:

Re: Ownership of the Noesis::IView object in the IntegrationGLUT example

03 Jan 2023, 14:00

Noesis objects are reference-counted. When the last Release() is invoked the instance is destroyed. Ptr<> is a smart pointer that handles references automatically for you.

GLUT does not offer any opportunity to clean resources, so if you have a global Ptr<> to the renderer, it will be automatically destroyed at process shutdown time. At that time, releasing GL resources is not a good idea (the GL context is probably destroyed), so in this specific example we decided to avoid shutting down Noesis.

But maybe we are wrong and the example can be improved. If you have any suggestion please let us know.

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests