filament-lifetime
Enforce correct Filament object creation and destruction lifecycles. Use this skill when initializing rendering pipelines or allocating/deallocating GPU buffers and entities.
- License 许可
- Apache-2.0
- 所属仓库
- google/filament
- 最近更新
- 2026-11-14
- Stars
- ★ 2.1w
- Forks
- 2.3k
01 前言 Front Matter
- name
- filament-lifetime
- description
- Enforce correct Filament object creation and destruction lifecycles. Use this skill when initializing rendering pipelines or allocating/deallocating GPU buffers and entities.
03 SKILL.md 正文
Filament object creation and destruction lifecycles
Filament manages its own native allocations. To prevent segmentation faults and memory leaks, follow these rules:
1. ECS Entities & Components
Getting the Entity Manager
- Preferred Method: Retrieve the
EntityManagerdirectly from theEngineinstance:utils::EntityManager& em = engine->getEntityManager(); - Alternative (Avoid if engine is available): Only use the global singleton if the
Enginepointer is inaccessible:utils::EntityManager& em = utils::EntityManager::get();
Entities
- Create: Create Entity IDs using the entity manager:
utils::Entity entity = engine->getEntityManager().create(); - Destroy: Free the Entity ID from the entity manager:
engine->getEntityManager().destroy(entity);
Components
- Create: Attach components to an existing entity using manager builders:
- Renderables/Lights: Use
RenderableManager::BuilderorLightManager::Builderon the entity:RenderableManager::Builder(1) .geometry(0, RenderableManager::PrimitiveType::TRIANGLES, vb, ib) .material(0, matInstance) .build(*engine, entity); - Cameras: Attach a Camera component to the entity:
Camera* camera = engine->createCamera(entity);
- Renderables/Lights: Use
- Destroy (CRITICAL):
- To clean up the entire entity:
First, destroy all Filament-managed components on the entity:
engine->destroy(entity);Second, free the Entity ID:engine->getEntityManager().destroy(entity);// Correct Entity Cleanup engine->destroy(myEntity); engine->getEntityManager().destroy(myEntity); - To remove a single component from the entity:
You can destroy specific components individually without deleting the entity:
- Cameras:
engine->destroyCameraComponent(entity); - Transforms:
engine->getTransformManager().destroy(entity); - Renderables:
engine->getRenderableManager().destroy(entity);
- Cameras:
- To clean up the entire entity:
First, destroy all Filament-managed components on the entity:
2. Engine-Managed Native Objects
Native GPU objects are created using the Engine factory or nested Builder patterns.
- NO
delete: Never call standard C++deleteon pointers returned byEngine. - Direct Factories: Instantiated directly from the
Engineinstance.- Objects:
View,Scene,Renderer,SwapChain. - Pattern:
View* view = engine->createView(); // ... engine->destroy(view);
- Objects:
- Builder Pattern: Instantiated using a nested
Builderclass, passing the engine instance tobuild(*engine).- Objects:
VertexBuffer,IndexBuffer,Texture,Material,IndirectLight,Skybox,RenderTarget. - Pattern:
VertexBuffer* vb = VertexBuffer::Builder() .vertexCount(count) .bufferCount(1) .attribute(VertexAttribute::POSITION, 0, VertexBuffer::AttributeType::FLOAT3) .build(*engine); // ... engine->destroy(vb);
- Objects:
04 同仓库更多 Skills
filament-math
Enforce correct mathematical primitives and naming conventions in Filament code. Use this skill when performing coordinate transformations, vector math, or projection setups.
cherry-pick
Cherry-pick a commit onto another branch and open the PR. Use when the user asks to cherry-pick or backport a commit or PR to a release branch.
verification-protocols
Standard verification pipeline to execute after modifying C++ source or header files. Use this skill to format includes, build the engine, and run core tests.
preprocessor-guard-hygiene
Enforce preprocessor guard rules and macro-dependent inclusion hygiene in C++. Use this skill when modifying conditional imports or preprocessor directives.
header-self-containment
Enforce strict header self-containment so that every header file compiles independently. Use this skill when creating or modifying C++ header files.
filament-desktop-testing
Execute unit tests and performance benchmarks for Filament on desktop platforms. Use this skill to run and filter tests or benchmarks locally.