diff --git a/ios/samples/README.md b/ios/samples/README.md index ee229815f49..4c132849ee4 100644 --- a/ios/samples/README.md +++ b/ios/samples/README.md @@ -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. diff --git a/ios/samples/gltf-viewer/gltf-viewer/FILViewController.mm b/ios/samples/gltf-viewer/gltf-viewer/FILViewController.mm index e2dd92e9929..2ea0be20b6c 100644 --- a/ios/samples/gltf-viewer/gltf-viewer/FILViewController.mm +++ b/ios/samples/gltf-viewer/gltf-viewer/FILViewController.mm @@ -56,6 +56,8 @@ @implementation FILViewController { Texture* _iblTexture; IndirectLight* _indirectLight; Entity _sun; + + UITapGestureRecognizer* _doubleTapRecognizer; } #pragma mark UIViewController methods @@ -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 { @@ -101,6 +107,8 @@ - (void)viewWillDisappear:(BOOL)animated { [self stopDisplayLink]; } +#pragma mark Private + - (void)startDisplayLink { [self stopDisplayLink]; @@ -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( @@ -257,6 +263,11 @@ - (void)render { [self.modelView render]; } +- (void)reloadModel { + [self.modelView destroyModel]; + [self createDefaultRenderables]; +} + - (void)dealloc { delete _server; delete _automation; diff --git a/libs/gltfio/src/ResourceLoader.cpp b/libs/gltfio/src/ResourceLoader.cpp index b673308a8c4..90ea9118a6b 100644 --- a/libs/gltfio/src/ResourceLoader.cpp +++ b/libs/gltfio/src/ResourceLoader.cpp @@ -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; }