free all resources in FilamentViewer destructor
This commit is contained in:
@@ -126,11 +126,10 @@ namespace thermion_filament
|
|||||||
|
|
||||||
static const uint16_t sFullScreenTriangleIndices[3] = {0, 1, 2};
|
static const uint16_t sFullScreenTriangleIndices[3] = {0, 1, 2};
|
||||||
|
|
||||||
FilamentViewer::FilamentViewer(const void *sharedContext, const ResourceLoaderWrapperImpl *const ResourceLoaderWrapperImpl, void *const platform, const char *uberArchivePath)
|
FilamentViewer::FilamentViewer(const void *sharedContext, const ResourceLoaderWrapperImpl *const resourceLoader, void *const platform, const char *uberArchivePath)
|
||||||
: _resourceLoaderWrapper(ResourceLoaderWrapperImpl)
|
: _resourceLoaderWrapper(resourceLoader)
|
||||||
{
|
{
|
||||||
_context = (void*) sharedContext;
|
_context = (void*) sharedContext;
|
||||||
|
|
||||||
ASSERT_POSTCONDITION(_resourceLoaderWrapper != nullptr, "Resource loader must be non-null");
|
ASSERT_POSTCONDITION(_resourceLoaderWrapper != nullptr, "Resource loader must be non-null");
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
@@ -269,7 +268,6 @@ namespace thermion_filament
|
|||||||
.culling(false)
|
.culling(false)
|
||||||
.build(*_engine, _imageEntity);
|
.build(*_engine, _imageEntity);
|
||||||
_scene->addEntity(_imageEntity);
|
_scene->addEntity(_imageEntity);
|
||||||
Log("Added imageEntity %d", _imageEntity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilamentViewer::setAntiAliasing(bool msaa, bool fxaa, bool taa)
|
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),
|
new ktxreader::Ktx1Bundle(static_cast<const uint8_t *>(rb.data),
|
||||||
static_cast<uint32_t>(rb.size));
|
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);
|
ResourceBuffer *rbCopy = new ResourceBuffer(rb);
|
||||||
|
|
||||||
std::vector<void *> *callbackData = new std::vector<void *>{(void *)_resourceLoaderWrapper, rbCopy};
|
std::vector<void *> *callbackData = new std::vector<void *>{(void *)_resourceLoaderWrapper, rbCopy};
|
||||||
@@ -680,22 +679,21 @@ namespace thermion_filament
|
|||||||
|
|
||||||
FilamentViewer::~FilamentViewer()
|
FilamentViewer::~FilamentViewer()
|
||||||
{
|
{
|
||||||
clearEntities();
|
clearLights();
|
||||||
|
destroySwapChain();
|
||||||
|
_engine->destroy(_imageEntity);
|
||||||
|
_engine->destroy(_imageTexture);
|
||||||
|
_engine->destroy(_imageVb);
|
||||||
|
_engine->destroy(_imageIb);
|
||||||
|
_engine->destroy(_imageMaterial);
|
||||||
delete _sceneManager;
|
delete _sceneManager;
|
||||||
|
|
||||||
for (auto it : _lights)
|
|
||||||
{
|
|
||||||
_engine->destroy(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
_engine->destroyCameraComponent(_mainCamera->getEntity());
|
_engine->destroyCameraComponent(_mainCamera->getEntity());
|
||||||
_mainCamera = nullptr;
|
_mainCamera = nullptr;
|
||||||
_engine->destroy(_view);
|
_engine->destroy(_view);
|
||||||
_engine->destroy(_scene);
|
_engine->destroy(_scene);
|
||||||
_engine->destroy(_renderer);
|
_engine->destroy(_renderer);
|
||||||
_engine->destroy(_swapChain);
|
Engine::destroy(&_engine);
|
||||||
|
delete _resourceLoaderWrapper;
|
||||||
Engine::destroy(&_engine); // clears engine*
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer *FilamentViewer::getRenderer() { return _renderer; }
|
Renderer *FilamentViewer::getRenderer() { return _renderer; }
|
||||||
@@ -930,7 +928,6 @@ namespace thermion_filament
|
|||||||
}
|
}
|
||||||
|
|
||||||
Log("Loading skybox from path %s", skyboxPath);
|
Log("Loading skybox from path %s", skyboxPath);
|
||||||
|
|
||||||
ResourceBuffer skyboxBuffer = _resourceLoaderWrapper->load(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)
|
// 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)
|
||||||
|
|||||||
Reference in New Issue
Block a user