Просмотр исходного кода

Fix envTextureLoader leaking an exception that can not be caught by the consumer (#9835)

* Add error handling to the envTextureLoader

* Add line to what's new

* Update src/Materials/Textures/Loaders/envTextureLoader.ts

Co-authored-by: Gary Hsu <bghgary@users.noreply.github.com>

* Going back to a .catch to capture errors thrown inside of the .then itself

* Gary was right. Don't catch errors thrown from the onLoad callbacks.

Co-authored-by: Gary Hsu <bghgary@users.noreply.github.com>
CoPrez 5 лет назад
Родитель
Сommit
d09b161949

+ 1 - 0
dist/preview release/what's new.md

@@ -121,6 +121,7 @@
 - Fix issue with NinePatch displaying half pixel gaps between slices on Firefox browsers. ([Pryme8](https://github.com/Pryme8))
 - Fix issue when canvas loses focus while holding a pointer button ([PolygonalSun](https://github.com/PolygonalSun))
 - Fix issue where camera controls stay detached if PointerDragBehavior is disabled prematurely ([PolygonalSun](https://github.com/PolygonalSun))
+- Fix uncatchable exception that could be thrown when initializing the environment textures ([CoPrez](https://github.com/CoPrez))
 
 ## Breaking changes
 

+ 15 - 9
src/Materials/Textures/Loaders/envTextureLoader.ts

@@ -42,15 +42,21 @@ export class _ENVTextureLoader implements IInternalTextureLoader {
             texture.width = info.width;
             texture.height = info.width;
 
-            EnvironmentTextureTools.UploadEnvSpherical(texture, info);
-            EnvironmentTextureTools.UploadEnvLevelsAsync(texture, data, info).then(() => {
-                texture.isReady = true;
-                texture.onLoadedObservable.notifyObservers(texture);
-                texture.onLoadedObservable.clear();
-                if (onLoad) {
-                    onLoad();
-                }
-            });
+            try {
+                EnvironmentTextureTools.UploadEnvSpherical(texture, info);
+                EnvironmentTextureTools.UploadEnvLevelsAsync(texture, data, info).then(() => {
+                    texture.isReady = true;
+                    texture.onLoadedObservable.notifyObservers(texture);
+                    texture.onLoadedObservable.clear();
+                    if (onLoad) {
+                        onLoad();
+                    }
+                }, (reason) => {
+                    onError?.("Can not upload environment levels", reason);
+                });
+            } catch (e) {
+                onError?.("Can not upload environment file", e);
+            }
         }
         else if (onError) {
             onError("Can not parse the environment file", null);