Skip to content

Commit

Permalink
gltfio: Clear texture caches before loading resources (#5580)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bejado committed May 20, 2022
1 parent 035f162 commit 3461ec8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
14 changes: 14 additions & 0 deletions ios/samples/README.md
Expand Up @@ -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.
15 changes: 13 additions & 2 deletions ios/samples/gltf-viewer/gltf-viewer/FILViewController.mm
Expand Up @@ -56,6 +56,8 @@ @implementation FILViewController {
Texture* _iblTexture;
IndirectLight* _indirectLight;
Entity _sun;

UITapGestureRecognizer* _doubleTapRecognizer;
}

#pragma mark UIViewController methods
Expand Down Expand Up @@ -91,6 +93,10 @@ - (void)viewDidLoad {

_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 {
Expand All @@ -101,6 +107,8 @@ - (void)viewWillDisappear:(BOOL)animated {
[self stopDisplayLink];
}

#pragma mark Private

- (void)startDisplayLink {
[self stopDisplayLink];

Expand All @@ -116,8 +124,6 @@ - (void)stopDisplayLink {
_displayLink = nil;
}

#pragma mark Private

- (void)createRenderablesFromPath:(NSString*)model {
// Retrieve the full path to the model in the documents directory.
NSString* documentPath = [NSSearchPathForDirectoriesInDomains(
Expand Down Expand Up @@ -257,6 +263,11 @@ - (void)render {
[self.modelView render];
}

- (void)reloadModel {
[self.modelView destroyModel];
[self createDefaultRenderables];
}

- (void)dealloc {
delete _server;
delete _automation;
Expand Down
5 changes: 5 additions & 0 deletions libs/gltfio/src/ResourceLoader.cpp
Expand Up @@ -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;
}
Expand Down

0 comments on commit 3461ec8

Please sign in to comment.