From 58242dd1f2d186a83fbda80b724467b5a5dd2dd5 Mon Sep 17 00:00:00 2001 From: CoolSpy3 <55305038+CoolSpy3@users.noreply.github.com> Date: Tue, 24 Dec 2024 11:16:52 -0800 Subject: [PATCH] Fix Crash When Loading an Invalid Background HDR Image (#6744) --- docs/reference/changelog-r2024.md | 1 + src/webots/nodes/WbBackground.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/docs/reference/changelog-r2024.md b/docs/reference/changelog-r2024.md index c8f495b3a51..39f328c1769 100644 --- a/docs/reference/changelog-r2024.md +++ b/docs/reference/changelog-r2024.md @@ -34,3 +34,4 @@ Released on December **th, 2023. - Fixed a bug where Webots would crash if a geometry was inserted into a `Shape` node used a bounding box ([#6691](https://github.com/cyberbotics/webots/pull/6691)). - Removed the old `wb_supervisor_field_import_sf_node` and `wb_supervisor_field_import_mf_node` functions from the list of editor autocomplete suggestions ([#6701](https://github.com/cyberbotics/webots/pull/6701)). - Fixed a bug preventing nodes from being inserted into unconnected proto fields ([#6735](https://github.com/cyberbotics/webots/pull/6735)). + - Fixed crash when an invalid HDR image was set as a world background ([#6744](https://github.com/cyberbotics/webots/pull/6744)). diff --git a/src/webots/nodes/WbBackground.cpp b/src/webots/nodes/WbBackground.cpp index 9f442155566..2cb42a8ff16 100644 --- a/src/webots/nodes/WbBackground.cpp +++ b/src/webots/nodes/WbBackground.cpp @@ -540,6 +540,11 @@ bool WbBackground::loadIrradianceTexture(int i) { float *data = stbi_loadf_from_memory(reinterpret_cast(content.constData()), content.size(), &mIrradianceWidth, &mIrradianceHeight, &components, 0); + if (data == NULL) { + warn(tr("Failed to load HDR texture '%1': %2.").arg(url).arg(stbi_failure_reason())); + return false; + } + const int rotate = gCoordinateSystemRotate(i); // FIXME: this texture rotation should be performed by OpenGL or in the shader to get a better performance if (rotate != 0) {