free all resources in FilamentViewer destructor

This commit is contained in:
Nick Fisher
2024-06-19 13:15:36 +08:00
parent a455e4f88a
commit 49b8e7023b

View File

@@ -126,11 +126,10 @@ namespace thermion_filament
static const uint16_t sFullScreenTriangleIndices[3] = {0, 1, 2};
FilamentViewer::FilamentViewer(const void *sharedContext, const ResourceLoaderWrapperImpl *const ResourceLoaderWrapperImpl, void *const platform, const char *uberArchivePath)
: _resourceLoaderWrapper(ResourceLoaderWrapperImpl)
FilamentViewer::FilamentViewer(const void *sharedContext, const ResourceLoaderWrapperImpl *const resourceLoader, void *const platform, const char *uberArchivePath)
: _resourceLoaderWrapper(resourceLoader)
{
_context = (void*) sharedContext;
ASSERT_POSTCONDITION(_resourceLoaderWrapper != nullptr, "Resource loader must be non-null");
#if TARGET_OS_IPHONE
@@ -269,7 +268,6 @@ namespace thermion_filament
.culling(false)
.build(*_engine, _imageEntity);
_scene->addEntity(_imageEntity);
Log("Added imageEntity %d", _imageEntity);
}
void FilamentViewer::setAntiAliasing(bool msaa, bool fxaa, bool taa)
@@ -444,7 +442,8 @@ namespace thermion_filament
new ktxreader::Ktx1Bundle(static_cast<const uint8_t *>(rb.data),
static_cast<uint32_t>(rb.size));
// because the ResourceBuffer will go out of scope before the texture callback is invoked, we need to make a copy to the heap
// the ResourceBuffer will go out of scope before the texture callback is invoked
// make a copy to the heap
ResourceBuffer *rbCopy = new ResourceBuffer(rb);
std::vector<void *> *callbackData = new std::vector<void *>{(void *)_resourceLoaderWrapper, rbCopy};
@@ -680,22 +679,21 @@ namespace thermion_filament
FilamentViewer::~FilamentViewer()
{
clearEntities();
clearLights();
destroySwapChain();
_engine->destroy(_imageEntity);
_engine->destroy(_imageTexture);
_engine->destroy(_imageVb);
_engine->destroy(_imageIb);
_engine->destroy(_imageMaterial);
delete _sceneManager;
for (auto it : _lights)
{
_engine->destroy(it);
}
_engine->destroyCameraComponent(_mainCamera->getEntity());
_mainCamera = nullptr;
_engine->destroy(_view);
_engine->destroy(_scene);
_engine->destroy(_renderer);
_engine->destroy(_swapChain);
Engine::destroy(&_engine); // clears engine*
Engine::destroy(&_engine);
delete _resourceLoaderWrapper;
}
Renderer *FilamentViewer::getRenderer() { return _renderer; }
@@ -930,7 +928,6 @@ namespace thermion_filament
}
Log("Loading skybox from path %s", skyboxPath);
ResourceBuffer skyboxBuffer = _resourceLoaderWrapper->load(skyboxPath);
// because this will go out of scope before the texture callback is invoked, we need to make a copy of the variable itself (not its contents)