Skip to content

Commit

Permalink
Add Engine::destroy(Engine*) to match other APIs (google#1377)
Browse files Browse the repository at this point in the history
  • Loading branch information
romainguy authored Jul 8, 2019
1 parent ba5b9c7 commit 3b3f52f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
35 changes: 31 additions & 4 deletions filament/include/filament/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ class TransformManager;
* }
* } while (!quit);
*
* engine->destroy(&view);
* engine->destroy(&scene);
* engine->destroy(&renderer);
* engine->destroy(&swapChain);
* engine->destroy(view);
* engine->destroy(scene);
* engine->destroy(renderer);
* engine->destroy(swapChain);
* Engine::destroy(&engine); // clears engine*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
Expand Down Expand Up @@ -213,6 +213,33 @@ class UTILS_PUBLIC Engine {
*/
static void destroy(Engine** engine);

/**
* Destroy the Engine instance and all associated resources.
*
* Engine.destroy() should be called last and after all other resources have been destroyed,
* it ensures all filament resources are freed.
*
* Destroy performs the following tasks:
* 1. Destroy all internal software and hardware resources.
* 2. Free all user allocated resources that are not already destroyed and logs a warning.
* This indicates a "leak" in the user's code.
* 3. Terminate the rendering engine's thread.
*
* @param engine A pointer to the filament.Engine to be destroyed.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* #include <filament/Engine.h>
* using namespace filament;
*
* Engine* engine = Engine::create();
* Engine::destroy(engine);
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* \remark
* This method is thread-safe.
*/
static void destroy(Engine* engine);

RenderableManager& getRenderableManager() noexcept;

LightManager& getLightManager() noexcept;
Expand Down
4 changes: 4 additions & 0 deletions filament/src/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,10 @@ Engine* Engine::create(Backend backend, Platform* platform, void* sharedGLContex
return handle;
}

void Engine::destroy(Engine* engine) {
destroy(&engine);
}

void Engine::destroy(Engine** engine) {
if (engine) {
std::unique_ptr<FEngine> filamentEngine;
Expand Down

0 comments on commit 3b3f52f

Please sign in to comment.