openrndr / orx

A growing library of assorted data structures, algorithms and utilities for OPENRNDR
https://openrndr.org
BSD 2-Clause "Simplified" License
119 stars 35 forks source link

[orx-gui] Make `gui.shutdown()` clean up after itself #258

Open hamoid opened 1 year ago

hamoid commented 1 year ago

Motivation

I would like to be able to extend(gui), later do gui.shutdown() and once again extend(gui).

Currently gui adds listeners for key presses and maintains mutable lists which are not cleared on shutdown. It seems to assume that a program has one gui which exists for the duration of the program.

More generally, there's gui.add() but no gui.remove(), there's program.extend() but no program.drop().

Help make it happen!

I am willing to submit a PR to implement this change, but would need some guidance.

Treide1 commented 1 year ago

On that note, I see a similar problem with [orx-compositor]. There are funtions provided ike deepDestroy that would allow cleanup, but the important vars themselfs are kept private.

This follows the same logic of providing creation, but no kind of destruction.

In general, I would welcome opening up resources to follow the acquire-release pattern. This allows for dynamic usage of resources, acquiring and releasing them as needed.

Note: My personal motivation is using orx-compisitor for scenes (like theaters scenes) were I have to cleanup resources after a scene completes. (I define many scenes in advance, but only one is in active use at any point.) I hope it's understandable how this benefit similar dynamic projects.

Treide1 commented 1 year ago

I am also willing to write a PR for orx-compositor specifically. I would like a second opionion before authoring it though.

edwinRNDR commented 1 year ago

Admittedly orx-compositor is written entirely without thinking of releasing resources.

OPENRNDR has a hidden resource manager provided by Session, it is primarily used to release resources in the live coding mode provided by orx-olive. It may be worthwhile to formalize/untangle what Session does and document the API. It may be possible to create a scene inside a Session scope and have all the resources cleaned up automatically by closing the session.