gltfio: Clear texture caches before loading resources (#5580)

* gltfio: Clear texture caches before loading resources

* iOS gltf-viewer: add double-tap to reload model for debugging

* iOS samples: add instructions on ASan / UBSan debugging
This commit is contained in:
Ben Doherty
2022-05-20 11:41:24 -07:00
committed by GitHub
parent 035f162ebc
commit 3461ec863b
3 changed files with 32 additions and 2 deletions

View File

@@ -99,3 +99,17 @@ $ xcodegen
within a sample folder to re-generate the Xcode project. You may need to close and re-open the
project in Xcode to see changes take effect.
## Building iOS Samples with ASan / UBSan
1. Turn on ASan / UBSan in Filament's top-level CMakeLists.txt by uncommenting the following line:
```
set(EXTRA_SANITIZE_OPTIONS "-fsanitize=undefined -fsanitize=address")
```
2. In the Xcode project, navigate to Product -> Scheme -> Edit Scheme... Under the Diagnostics tab,
check the box next for Address Sanitizer and Undefined Behavior.
3. Build Filament and run the iOS sample as usual. Any errors will cause an exception to raise and
diagnostics to print in the console.

View File

@@ -56,6 +56,8 @@ using namespace ktxreader;
Texture* _iblTexture;
IndirectLight* _indirectLight;
Entity _sun;
UITapGestureRecognizer* _doubleTapRecognizer;
}
#pragma mark UIViewController methods
@@ -91,6 +93,10 @@ using namespace ktxreader;
_server = new viewer::RemoteServer();
_automation = viewer::AutomationEngine::createDefault();
_doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(reloadModel)];
_doubleTapRecognizer.numberOfTapsRequired = 2;
[self.modelView addGestureRecognizer:_doubleTapRecognizer];
}
- (void)viewWillAppear:(BOOL)animated {
@@ -101,6 +107,8 @@ using namespace ktxreader;
[self stopDisplayLink];
}
#pragma mark Private
- (void)startDisplayLink {
[self stopDisplayLink];
@@ -116,8 +124,6 @@ using namespace ktxreader;
_displayLink = nil;
}
#pragma mark Private
- (void)createRenderablesFromPath:(NSString*)model {
// Retrieve the full path to the model in the documents directory.
NSString* documentPath = [NSSearchPathForDirectoriesInDomains(
@@ -257,6 +263,11 @@ using namespace ktxreader;
[self.modelView render];
}
- (void)reloadModel {
[self.modelView destroyModel];
[self createDefaultRenderables];
}
- (void)dealloc {
delete _server;
delete _automation;

View File

@@ -342,6 +342,11 @@ bool ResourceLoader::loadResources(FFilamentAsset* asset, bool async) {
SYSTRACE_CONTEXT();
SYSTRACE_ASYNC_END("addResourceData", 1);
// Clear our texture caches. Previous calls to loadResources may have populated these, but the
// Texture objects could have since been destroyed.
pImpl->mBufferTextureCache.clear();
pImpl->mFilepathTextureCache.clear();
if (asset->mResourcesLoaded) {
return false;
}