From 351c87be15f55d20f34206da34f7955e92248226 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Mon, 27 Oct 2025 16:39:14 +0100 Subject: [PATCH 01/47] enable sanitizers for macOS, Linux and Android --- .github/jobs/android.yml | 7 ++++-- .github/jobs/linux.yml | 4 +++- .github/jobs/macos.yml | 7 ++++-- .../Android/BabylonNative/build.gradle | 7 +++++- CMakeLists.txt | 13 +++++++++++ azure-pipelines.yml | 22 +++++++++++++++++++ 6 files changed, 54 insertions(+), 6 deletions(-) diff --git a/.github/jobs/android.yml b/.github/jobs/android.yml index c2f9e8f7b..4126b7953 100644 --- a/.github/jobs/android.yml +++ b/.github/jobs/android.yml @@ -9,7 +9,10 @@ jobs: timeoutInMinutes: 45 pool: vmImage: ${{ parameters.vmImage }} - + + variables: + SANITIZER_FLAG: ${{ parameters.Sanitizers && 'ON' || 'OFF' }} + steps: - template: cmake.yml parameters: @@ -26,7 +29,7 @@ jobs: workingDirectory: 'Apps/Playground/Android' gradleWrapperFile: 'Apps/Playground/Android/gradlew' gradleOptions: '-Xmx1536m' - options: '-PJSEngine=${{ parameters.JSEngine }} -PARM64Only -PNDK_VERSION=$(NDK_VERSION)' + options: '-PJSEngine=${{ parameters.JSEngine }} -PARM64Only -PNDK_VERSION=$(NDK_VERSION) -PSANITIZERS=$(SANITIZER_FLAG)' publishJUnitResults: false tasks: 'assembleRelease' displayName: 'Build Playground ${{ parameters.JSEngine }}' diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index 4ecc86ba0..901ec4cfd 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -4,6 +4,7 @@ parameters: CC: '' CXX: '' JSEngine: '' + Sanitizers: false jobs: - job: ${{ parameters.name }} @@ -12,6 +13,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: + SANITIZER_FLAG: ${{ parameters.Sanitizers && 'ON' || 'OFF' }} CC: ${{ parameters.CC }} CXX: ${{ parameters.CXX }} @@ -26,7 +28,7 @@ jobs: displayName: 'Install packages' - script: | - cmake -G Ninja -B build -D JAVASCRIPTCORE_LIBRARY=/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.1.so -D NAPI_JAVASCRIPT_ENGINE=${{ parameters.JSEngine }} -D CMAKE_BUILD_TYPE=RelWithDebInfo -D BX_CONFIG_DEBUG=ON -D CMAKE_UNITY_BUILD=$(UNITY_BUILD) -D OpenGL_GL_PREFERENCE=GLVND -D BABYLON_DEBUG_TRACE=ON + cmake -G Ninja -B build -D JAVASCRIPTCORE_LIBRARY=/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.1.so -D NAPI_JAVASCRIPT_ENGINE=${{ parameters.JSEngine }} -D CMAKE_BUILD_TYPE=RelWithDebInfo -D BX_CONFIG_DEBUG=ON -D CMAKE_UNITY_BUILD=$(UNITY_BUILD) -D OpenGL_GL_PREFERENCE=GLVND -D BABYLON_DEBUG_TRACE=ON -D ENABLE_SANITIZERS=$(SANITIZER_FLAG) . ninja -C build displayName: 'Build X11' diff --git a/.github/jobs/macos.yml b/.github/jobs/macos.yml index 6de9d3913..b04c33dc0 100644 --- a/.github/jobs/macos.yml +++ b/.github/jobs/macos.yml @@ -7,7 +7,10 @@ jobs: timeoutInMinutes: 30 pool: vmImage: ${{ parameters.vmImage }} - + + variables: + SANITIZER_FLAG: ${{ parameters.Sanitizers && 'ON' || 'OFF' }} + steps: - template: cmake.yml parameters: @@ -18,7 +21,7 @@ jobs: displayName: 'Select XCode $(XCODE_VERSION)' - script: | - cmake -G Xcode -B buildmacOS -D CMAKE_UNITY_BUILD=$(UNITY_BUILD) -D BABYLON_DEBUG_TRACE=ON + cmake -G Xcode -B buildmacOS -D CMAKE_UNITY_BUILD=$(UNITY_BUILD) -D BABYLON_DEBUG_TRACE=ON -D ENABLE_SANITIZERS=$(SANITIZER_FLAG) displayName: 'Generate macOS solution' - script: | diff --git a/Apps/Playground/Android/BabylonNative/build.gradle b/Apps/Playground/Android/BabylonNative/build.gradle index 11486d023..8f3a0d269 100644 --- a/Apps/Playground/Android/BabylonNative/build.gradle +++ b/Apps/Playground/Android/BabylonNative/build.gradle @@ -20,6 +20,10 @@ def unity_build = "false" if (project.hasProperty("UNITY_BUILD")) { unity_build = project.property("UNITY_BUILD") } +def sanitizers = "OFF" +if (project.hasProperty("SANITIZERS")) { + sanitizers = project.property("SANITIZERS") +} def arcore_libpath = "${buildDir}/arcore-native" configurations { natives } @@ -48,7 +52,8 @@ android { "-DNAPI_JAVASCRIPT_ENGINE=${jsEngine}", "-DBABYLON_NATIVE_BUILD_APPS=ON", "-DCMAKE_UNITY_BUILD=${unity_build}", - "-DBABYLON_DEBUG_TRACE=ON" + "-DBABYLON_DEBUG_TRACE=ON", + "-DENABLE_SANITIZERS=${sanitizers}" } } ndk { diff --git a/CMakeLists.txt b/CMakeLists.txt index b33a30ab8..63bf71c06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,6 +106,19 @@ option(BABYLON_NATIVE_PLUGIN_TESTUTILS "Include Babylon Native Plugin TestUtils. option(BABYLON_NATIVE_POLYFILL_WINDOW "Include Babylon Native Polyfill Window." ON) option(BABYLON_NATIVE_POLYFILL_CANVAS "Include Babylon Native Polyfill Canvas." ON) +# Sanitizers +option(ENABLE_SANITIZERS "Enable AddressSanitizer and UBSan" OFF) + +if(ENABLE_SANITIZERS) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") + set(SANITIZERS "address,undefined") + add_compile_options(-fsanitize=${SANITIZERS} -fno-omit-frame-pointer) + add_link_options(-fsanitize=${SANITIZERS}) + else() + message(WARNING "Sanitizers not supported on this compiler.") + endif() +endif() + # -------------------------------------------------- if(ANDROID) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 14bab2c4e..5e23baa12 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -21,6 +21,12 @@ jobs: name: MacOS vmImage: 'macOS-latest' + - template: .github/jobs/macos.yml + parameters: + name: MacOS + vmImage: 'macOS-latest' + Sanitizers: true + - template: .github/jobs/ios.yml parameters: name: iOS_iOS180 @@ -102,6 +108,15 @@ jobs: CXX: g++ JSEngine: JavaScriptCore + - template: .github/jobs/linux.yml + parameters: + name: Ubuntu_Clang_JavaScriptCore + vmImage: 'ubuntu-latest' + CC: clang + CXX: clang++ + JSEngine: JavaScriptCore + Sanitizers: true + # Android - template: .github/jobs/android.yml parameters: @@ -127,6 +142,13 @@ jobs: vmImage: 'macOS-latest' JSEngine: V8 + - template: .github/jobs/android.yml + parameters: + name: Android_MacOS_V8 + vmImage: 'macOS-latest' + JSEngine: V8 + Sanitizers: true + # Installation tests. - template: .github/jobs/test_install_win32.yml parameters: From b78acf4700a5de062746faf2ffe8b38743e5cb8d Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Mon, 27 Oct 2025 16:49:14 +0100 Subject: [PATCH 02/47] no && --- .github/jobs/android.yml | 2 +- .github/jobs/linux.yml | 2 +- .github/jobs/macos.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/jobs/android.yml b/.github/jobs/android.yml index 4126b7953..99630e7c0 100644 --- a/.github/jobs/android.yml +++ b/.github/jobs/android.yml @@ -11,7 +11,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: ${{ parameters.Sanitizers && 'ON' || 'OFF' }} + SANITIZER_FLAG: ${{ if eq(parameters.Sanitizers, true) }}'ON'${{ else }}'OFF'${{ endif }} steps: - template: cmake.yml diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index 901ec4cfd..ba4d8e143 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -13,7 +13,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: ${{ parameters.Sanitizers && 'ON' || 'OFF' }} + SANITIZER_FLAG: ${{ if eq(parameters.Sanitizers, true) }}'ON'${{ else }}'OFF'${{ endif }} CC: ${{ parameters.CC }} CXX: ${{ parameters.CXX }} diff --git a/.github/jobs/macos.yml b/.github/jobs/macos.yml index b04c33dc0..25dc1d22e 100644 --- a/.github/jobs/macos.yml +++ b/.github/jobs/macos.yml @@ -9,7 +9,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: ${{ parameters.Sanitizers && 'ON' || 'OFF' }} + SANITIZER_FLAG: ${{ if eq(parameters.Sanitizers, true) }}'ON'${{ else }}'OFF'${{ endif }} steps: - template: cmake.yml From c2f11385bb15eee46522792980fb3652b177d93d Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Mon, 27 Oct 2025 16:56:53 +0100 Subject: [PATCH 03/47] syntax --- .github/jobs/android.yml | 2 +- .github/jobs/linux.yml | 2 +- .github/jobs/macos.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/jobs/android.yml b/.github/jobs/android.yml index 99630e7c0..e86fb48d0 100644 --- a/.github/jobs/android.yml +++ b/.github/jobs/android.yml @@ -11,7 +11,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: ${{ if eq(parameters.Sanitizers, true) }}'ON'${{ else }}'OFF'${{ endif }} + SANITIZER_FLAG: $[coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF')] steps: - template: cmake.yml diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index ba4d8e143..3f444069d 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -13,7 +13,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: ${{ if eq(parameters.Sanitizers, true) }}'ON'${{ else }}'OFF'${{ endif }} + SANITIZER_FLAG: $[coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF')] CC: ${{ parameters.CC }} CXX: ${{ parameters.CXX }} diff --git a/.github/jobs/macos.yml b/.github/jobs/macos.yml index 25dc1d22e..1f585e7bd 100644 --- a/.github/jobs/macos.yml +++ b/.github/jobs/macos.yml @@ -9,7 +9,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: ${{ if eq(parameters.Sanitizers, true) }}'ON'${{ else }}'OFF'${{ endif }} + SANITIZER_FLAG: $[coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF')] steps: - template: cmake.yml From ed44d18582a66e57d49efdac3bdb62b316a2969f Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Mon, 27 Oct 2025 16:58:31 +0100 Subject: [PATCH 04/47] job names --- azure-pipelines.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5e23baa12..bf48db7d1 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -23,7 +23,7 @@ jobs: - template: .github/jobs/macos.yml parameters: - name: MacOS + name: MacOS_Sanitizers vmImage: 'macOS-latest' Sanitizers: true @@ -110,7 +110,7 @@ jobs: - template: .github/jobs/linux.yml parameters: - name: Ubuntu_Clang_JavaScriptCore + name: Ubuntu_Clang_JavaScriptCore_Sanitizers vmImage: 'ubuntu-latest' CC: clang CXX: clang++ @@ -144,7 +144,7 @@ jobs: - template: .github/jobs/android.yml parameters: - name: Android_MacOS_V8 + name: Android_MacOS_V8_Sanitizers vmImage: 'macOS-latest' JSEngine: V8 Sanitizers: true From a388975819d4eefe915c989279b2c481846b9f90 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Mon, 27 Oct 2025 17:58:50 +0100 Subject: [PATCH 05/47] parameters --- .github/jobs/android.yml | 2 +- .github/jobs/linux.yml | 2 +- .github/jobs/macos.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/jobs/android.yml b/.github/jobs/android.yml index e86fb48d0..6c7d59c7e 100644 --- a/.github/jobs/android.yml +++ b/.github/jobs/android.yml @@ -11,7 +11,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: $[coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF')] + SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF') }} steps: - template: cmake.yml diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index 3f444069d..75204d49c 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -13,7 +13,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: $[coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF')] + SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF') }} CC: ${{ parameters.CC }} CXX: ${{ parameters.CXX }} diff --git a/.github/jobs/macos.yml b/.github/jobs/macos.yml index 1f585e7bd..9e2e2fb23 100644 --- a/.github/jobs/macos.yml +++ b/.github/jobs/macos.yml @@ -9,7 +9,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: $[coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF')] + SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF') }} steps: - template: cmake.yml From f46d415336030b7b8d5e39bc19fac53a3c3f4bbc Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Tue, 28 Oct 2025 09:42:18 +0100 Subject: [PATCH 06/47] disable unity build --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index bf48db7d1..566d280f6 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -10,7 +10,7 @@ variables: - name: NDK_VERSION value: 25.2.9519653 - name: UNITY_BUILD - value: true + value: false - name: XCODE_VERSION value: 16.4 From ba0e5c34322e037f483072f5b90b8f87905c8bf5 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Tue, 28 Oct 2025 10:11:43 +0100 Subject: [PATCH 07/47] missing header, unity build back --- .github/jobs/macos.yml | 8 ++++---- Polyfills/Canvas/Source/Gradient.cpp | 17 +++++++++-------- azure-pipelines.yml | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/jobs/macos.yml b/.github/jobs/macos.yml index 9e2e2fb23..253290be5 100644 --- a/.github/jobs/macos.yml +++ b/.github/jobs/macos.yml @@ -31,20 +31,20 @@ jobs: - task: Xcode@5 inputs: xcWorkspacePath: 'buildmacOS/BabylonNative.xcodeproj' - scheme: 'Playground' + scheme: 'UnitTests' sdk: 'macosx' useXcpretty: false configuration: RelWithDebInfo - displayName: 'Build Playground macOS' + displayName: 'Build UnitTests macOS' - task: Xcode@5 inputs: xcWorkspacePath: 'buildmacOS/BabylonNative.xcodeproj' - scheme: 'UnitTests' + scheme: 'Playground' sdk: 'macosx' useXcpretty: false configuration: RelWithDebInfo - displayName: 'Build UnitTests macOS' + displayName: 'Build Playground macOS' - script: | cd buildmacOS/Apps/UnitTests/RelWithDebInfo diff --git a/Polyfills/Canvas/Source/Gradient.cpp b/Polyfills/Canvas/Source/Gradient.cpp index 031b83ab3..435f09c32 100644 --- a/Polyfills/Canvas/Source/Gradient.cpp +++ b/Polyfills/Canvas/Source/Gradient.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "Canvas.h" #include "Context.h" #include "Gradient.h" @@ -63,7 +64,7 @@ namespace Babylon::Polyfills::Internal return color; color = nvgRGBAf(color.r * x->mul[0], color.g * x->mul[1], color.b * x->mul[2], color.a * x->mul[3]); color = nvgRGBAf(color.r + x->add[0], color.g + x->add[1], color.b + x->add[2], color.a + x->add[3]); - color = nvgRGBAf(fmax(0.0f, fmin(color.r, 1.0f)), fmax(0.0f, fmin(color.g, 1.0f)), fmax(0.0f, fmin(color.b, 1.0f)), fmax(0.0f, fmin(color.a, 1.0f))); + color = nvgRGBAf(std::fmax(0.0f, std::fmin(color.r, 1.0f)), std::fmax(0.0f, std::fmin(color.g, 1.0f)), std::fmax(0.0f, std::fmin(color.b, 1.0f)), std::fmax(0.0f, std::fmin(color.a, 1.0f))); return color; } @@ -182,10 +183,10 @@ namespace Babylon::Polyfills::Internal NVGcolor lerpColor(NVGcolor color0, NVGcolor color1, float offset0, float offset1, float g) { NVGcolor dst; - float den = fmax(0.00001f, offset1 - offset0); + float den = std::fmax(0.00001f, offset1 - offset0); for (int i = 0; i < 4; i++) dst.rgba[i] = color0.rgba[i] + (color1.rgba[i] - color0.rgba[i]) * (g - offset0) / den; - dst = nvgRGBAf(fmax(0.0f, fmin(dst.r, 1.0f)), fmax(0.0f, fmin(dst.g, 1.0f)), fmax(0.0f, fmin(dst.b, 1.0f)), fmax(0.0f, fmin(dst.a, 1.0f))); + dst = nvgRGBAf(std::fmax(0.0f, std::fmin(dst.r, 1.0f)), std::fmax(0.0f, std::fmin(dst.g, 1.0f)), std::fmax(0.0f, std::fmin(dst.b, 1.0f)), std::fmax(0.0f, std::fmin(dst.a, 1.0f))); return dst; } @@ -254,7 +255,7 @@ namespace Babylon::Polyfills::Internal float numerator = (dx * fxp + dy * fyp); float df = dx * fyp - dy * fxp; - numerator += sqrtf((rn * rn) * (dx * dx + dy * dy) - (df * df)); + numerator += std::sqrtf((rn * rn) * (dx * dx + dy * dy) - (df * df)); float g = numerator / denominator; // color = c0 + (c1 - c0)(g - x0)/(x1 - x0) @@ -282,12 +283,12 @@ namespace Babylon::Polyfills::Internal } else { - int w = (int)fabsf(g); + int w = (int)std::fabsf(g); if (spreadMode == SPREAD_REPEAT) { if (g < 0) { - g = 1 - (fabs(g) - w); + g = 1 - (std::fabs(g) - w); } else { @@ -300,11 +301,11 @@ namespace Babylon::Polyfills::Internal { if (w % 2 == 0) { // even - g = (fabsf(g) - w); + g = (std::fabsf(g) - w); } else { // odd - g = (1 - (fabsf(g) - w)); + g = (1 - (std::fabsf(g) - w)); } } else diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 566d280f6..bf48db7d1 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -10,7 +10,7 @@ variables: - name: NDK_VERSION value: 25.2.9519653 - name: UNITY_BUILD - value: false + value: true - name: XCODE_VERSION value: 16.4 From 121cd8a1da41ae7f0450eec66ed0a2fc876a5dc7 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Tue, 28 Oct 2025 10:42:45 +0100 Subject: [PATCH 08/47] linux build --- .github/jobs/macos.yml | 8 ++++---- Polyfills/Canvas/Source/Gradient.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/jobs/macos.yml b/.github/jobs/macos.yml index 253290be5..9e2e2fb23 100644 --- a/.github/jobs/macos.yml +++ b/.github/jobs/macos.yml @@ -31,20 +31,20 @@ jobs: - task: Xcode@5 inputs: xcWorkspacePath: 'buildmacOS/BabylonNative.xcodeproj' - scheme: 'UnitTests' + scheme: 'Playground' sdk: 'macosx' useXcpretty: false configuration: RelWithDebInfo - displayName: 'Build UnitTests macOS' + displayName: 'Build Playground macOS' - task: Xcode@5 inputs: xcWorkspacePath: 'buildmacOS/BabylonNative.xcodeproj' - scheme: 'Playground' + scheme: 'UnitTests' sdk: 'macosx' useXcpretty: false configuration: RelWithDebInfo - displayName: 'Build Playground macOS' + displayName: 'Build UnitTests macOS' - script: | cd buildmacOS/Apps/UnitTests/RelWithDebInfo diff --git a/Polyfills/Canvas/Source/Gradient.cpp b/Polyfills/Canvas/Source/Gradient.cpp index 435f09c32..fd5e9738a 100644 --- a/Polyfills/Canvas/Source/Gradient.cpp +++ b/Polyfills/Canvas/Source/Gradient.cpp @@ -255,7 +255,7 @@ namespace Babylon::Polyfills::Internal float numerator = (dx * fxp + dy * fyp); float df = dx * fyp - dy * fxp; - numerator += std::sqrtf((rn * rn) * (dx * dx + dy * dy) - (df * df)); + numerator += std::sqrt((rn * rn) * (dx * dx + dy * dy) - (df * df)); float g = numerator / denominator; // color = c0 + (c1 - c0)(g - x0)/(x1 - x0) @@ -283,7 +283,7 @@ namespace Babylon::Polyfills::Internal } else { - int w = (int)std::fabsf(g); + int w = (int)std::fabs(g); if (spreadMode == SPREAD_REPEAT) { if (g < 0) @@ -301,11 +301,11 @@ namespace Babylon::Polyfills::Internal { if (w % 2 == 0) { // even - g = (std::fabsf(g) - w); + g = (std::fabs(g) - w); } else { // odd - g = (1 - (std::fabsf(g) - w)); + g = (1 - (std::fabs(g) - w)); } } else From 46a5c250c699e9f18bae54e5cf054a59ad2638b1 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Tue, 28 Oct 2025 17:10:04 +0100 Subject: [PATCH 09/47] rtti for glslang --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 63bf71c06..70ae6fb63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,6 +110,7 @@ option(BABYLON_NATIVE_POLYFILL_CANVAS "Include Babylon Native Polyfill Canvas." option(ENABLE_SANITIZERS "Enable AddressSanitizer and UBSan" OFF) if(ENABLE_SANITIZERS) + set(ENABLE_RTTI ON CACHE BOOL "" FORCE) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") set(SANITIZERS "address,undefined") add_compile_options(-fsanitize=${SANITIZERS} -fno-omit-frame-pointer) From 2fa678474020c39ae9b5b137a907dc097a65a64d Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Wed, 29 Oct 2025 10:45:37 +0100 Subject: [PATCH 10/47] android sanitizers --- .../Android/BabylonNative/CMakeLists.txt | 9 ++ azure-pipelines.yml | 102 ------------------ 2 files changed, 9 insertions(+), 102 deletions(-) diff --git a/Apps/Playground/Android/BabylonNative/CMakeLists.txt b/Apps/Playground/Android/BabylonNative/CMakeLists.txt index 6764be52c..5691e8ad9 100644 --- a/Apps/Playground/Android/BabylonNative/CMakeLists.txt +++ b/Apps/Playground/Android/BabylonNative/CMakeLists.txt @@ -5,6 +5,15 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) project(BabylonNative) +if(ENABLE_SANITIZERS) + set(ENABLE_RTTI ON CACHE BOOL "" FORCE) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") + set(SANITIZERS "address,undefined") + add_compile_options(-fsanitize=${SANITIZERS} -fno-omit-frame-pointer) + add_link_options(-fsanitize=${SANITIZERS}) + endif() +endif() + get_filename_component(PLAYGROUND_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE) get_filename_component(REPO_ROOT_DIR "${PLAYGROUND_DIR}/../.." ABSOLUTE) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index bf48db7d1..387c9430f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -15,108 +15,6 @@ variables: value: 16.4 jobs: -# Apple - - template: .github/jobs/macos.yml - parameters: - name: MacOS - vmImage: 'macOS-latest' - - - template: .github/jobs/macos.yml - parameters: - name: MacOS_Sanitizers - vmImage: 'macOS-latest' - Sanitizers: true - - - template: .github/jobs/ios.yml - parameters: - name: iOS_iOS180 - vmImage: 'macOS-latest' - deploymentTarget: 18.0 - - - template: .github/jobs/ios.yml - parameters: - name: iOS_iOS175 - vmImage: 'macOS-latest' - deploymentTarget: 17.5 - -# WIN32 - - template: .github/jobs/win32.yml - parameters: - name: Win32_x64_D3D11 - vmImage: 'windows-latest' - platform: x64 - - - template: .github/jobs/win32.yml - parameters: - name: Win32_x64_JSI_D3D11 - vmImage: 'windows-latest' - platform: x64 - napiType: jsi - - - template: .github/jobs/win32.yml - parameters: - name: Win32_x64_V8_D3D11 - vmImage: 'windows-latest' - platform: x64 - napiType: V8 - - - template: .github/jobs/win32.yml - parameters: - name: Win32_x64_D3D12 - vmImage: 'windows-latest' - platform: x64 - graphics_api: D3D12 - -# UWP - - template: .github/jobs/uwp.yml - parameters: - name: UWP_x64 - vmImage: 'windows-latest' - platform: x64 - - - template: .github/jobs/uwp.yml - parameters: - name: UWP_arm64 - vmImage: 'windows-latest' - platform: arm64 - - - template: .github/jobs/uwp.yml - parameters: - name: UWP_arm64_JSI - vmImage: 'windows-latest' - platform: arm64 - napiType: jsi - -# Ubuntu/Linux - - # TODO: v8 is incompatible with curl for some reason - # See https://github.com/BabylonJS/BabylonNative/issues/1190 - - - template: .github/jobs/linux.yml - parameters: - name: Ubuntu_Clang_JavaScriptCore - vmImage: 'ubuntu-latest' - CC: clang - CXX: clang++ - JSEngine: JavaScriptCore - - - template: .github/jobs/linux.yml - parameters: - name: Ubuntu_GCC_JavaScriptCore - vmImage: 'ubuntu-latest' - CC: gcc - CXX: g++ - JSEngine: JavaScriptCore - - - template: .github/jobs/linux.yml - parameters: - name: Ubuntu_Clang_JavaScriptCore_Sanitizers - vmImage: 'ubuntu-latest' - CC: clang - CXX: clang++ - JSEngine: JavaScriptCore - Sanitizers: true - # Android - template: .github/jobs/android.yml parameters: From 18f0dab301bfd344fc746d52922b870f1fce3716 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Wed, 29 Oct 2025 11:10:09 +0100 Subject: [PATCH 11/47] ndk 28 --- azure-pipelines.yml | 104 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 387c9430f..dfa3b78a0 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -8,13 +8,115 @@ variables: - name: CMAKE_VERSION value: 3.31.6 - name: NDK_VERSION - value: 25.2.9519653 + value: 28.2.13676358 - name: UNITY_BUILD value: true - name: XCODE_VERSION value: 16.4 jobs: +# Apple + - template: .github/jobs/macos.yml + parameters: + name: MacOS + vmImage: 'macOS-latest' + + - template: .github/jobs/macos.yml + parameters: + name: MacOS_Sanitizers + vmImage: 'macOS-latest' + Sanitizers: true + + - template: .github/jobs/ios.yml + parameters: + name: iOS_iOS180 + vmImage: 'macOS-latest' + deploymentTarget: 18.0 + + - template: .github/jobs/ios.yml + parameters: + name: iOS_iOS175 + vmImage: 'macOS-latest' + deploymentTarget: 17.5 + +# WIN32 + - template: .github/jobs/win32.yml + parameters: + name: Win32_x64_D3D11 + vmImage: 'windows-latest' + platform: x64 + + - template: .github/jobs/win32.yml + parameters: + name: Win32_x64_JSI_D3D11 + vmImage: 'windows-latest' + platform: x64 + napiType: jsi + + - template: .github/jobs/win32.yml + parameters: + name: Win32_x64_V8_D3D11 + vmImage: 'windows-latest' + platform: x64 + napiType: V8 + + - template: .github/jobs/win32.yml + parameters: + name: Win32_x64_D3D12 + vmImage: 'windows-latest' + platform: x64 + graphics_api: D3D12 + +# UWP + - template: .github/jobs/uwp.yml + parameters: + name: UWP_x64 + vmImage: 'windows-latest' + platform: x64 + + - template: .github/jobs/uwp.yml + parameters: + name: UWP_arm64 + vmImage: 'windows-latest' + platform: arm64 + + - template: .github/jobs/uwp.yml + parameters: + name: UWP_arm64_JSI + vmImage: 'windows-latest' + platform: arm64 + napiType: jsi + +# Ubuntu/Linux + + # TODO: v8 is incompatible with curl for some reason + # See https://github.com/BabylonJS/BabylonNative/issues/1190 + + - template: .github/jobs/linux.yml + parameters: + name: Ubuntu_Clang_JavaScriptCore + vmImage: 'ubuntu-latest' + CC: clang + CXX: clang++ + JSEngine: JavaScriptCore + + - template: .github/jobs/linux.yml + parameters: + name: Ubuntu_GCC_JavaScriptCore + vmImage: 'ubuntu-latest' + CC: gcc + CXX: g++ + JSEngine: JavaScriptCore + + - template: .github/jobs/linux.yml + parameters: + name: Ubuntu_Clang_JavaScriptCore_Sanitizers + vmImage: 'ubuntu-latest' + CC: clang + CXX: clang++ + JSEngine: JavaScriptCore + Sanitizers: true + # Android - template: .github/jobs/android.yml parameters: From c11fba684615e2a1605304b4518185c9f3c0c44b Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Wed, 29 Oct 2025 11:33:24 +0100 Subject: [PATCH 12/47] sanitizers for unittests android --- Apps/Playground/Android/BabylonNative/CMakeLists.txt | 8 +++----- Apps/UnitTests/Android/app/build.gradle | 7 ++++++- Apps/UnitTests/Android/app/src/main/cpp/CMakeLists.txt | 7 +++++++ azure-pipelines.yml | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Apps/Playground/Android/BabylonNative/CMakeLists.txt b/Apps/Playground/Android/BabylonNative/CMakeLists.txt index 5691e8ad9..e0c7ab482 100644 --- a/Apps/Playground/Android/BabylonNative/CMakeLists.txt +++ b/Apps/Playground/Android/BabylonNative/CMakeLists.txt @@ -7,11 +7,9 @@ project(BabylonNative) if(ENABLE_SANITIZERS) set(ENABLE_RTTI ON CACHE BOOL "" FORCE) - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") - set(SANITIZERS "address,undefined") - add_compile_options(-fsanitize=${SANITIZERS} -fno-omit-frame-pointer) - add_link_options(-fsanitize=${SANITIZERS}) - endif() + set(SANITIZERS "address,undefined") + add_compile_options(-fsanitize=${SANITIZERS} -fno-omit-frame-pointer) + add_link_options(-fsanitize=${SANITIZERS}) endif() get_filename_component(PLAYGROUND_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE) diff --git a/Apps/UnitTests/Android/app/build.gradle b/Apps/UnitTests/Android/app/build.gradle index e6fca383d..1b120be8e 100644 --- a/Apps/UnitTests/Android/app/build.gradle +++ b/Apps/UnitTests/Android/app/build.gradle @@ -6,6 +6,10 @@ def jsEngine = "V8" if (project.hasProperty("jsEngine")) { jsEngine = project.property("jsEngine") } +def sanitizers = "OFF" +if (project.hasProperty("SANITIZERS")) { + sanitizers = project.property("SANITIZERS") +} configurations { natives } @@ -29,7 +33,8 @@ android { "-DANDROID_STL=c++_shared", "-DNAPI_JAVASCRIPT_ENGINE=${jsEngine}", "-DJSRUNTIMEHOST_CORE_APPRUNTIME_V8_INSPECTOR=ON", - "-DBABYLON_NATIVE_BUILD_APPS=ON" + "-DBABYLON_NATIVE_BUILD_APPS=ON", + "-DENABLE_SANITIZERS=${sanitizers}" ) } } diff --git a/Apps/UnitTests/Android/app/src/main/cpp/CMakeLists.txt b/Apps/UnitTests/Android/app/src/main/cpp/CMakeLists.txt index aac3d46ba..74a7ec8fc 100644 --- a/Apps/UnitTests/Android/app/src/main/cpp/CMakeLists.txt +++ b/Apps/UnitTests/Android/app/src/main/cpp/CMakeLists.txt @@ -5,6 +5,13 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) project(UnitTestsJNI) +if(ENABLE_SANITIZERS) + set(ENABLE_RTTI ON CACHE BOOL "" FORCE) + set(SANITIZERS "address,undefined") + add_compile_options(-fsanitize=${SANITIZERS} -fno-omit-frame-pointer) + add_link_options(-fsanitize=${SANITIZERS}) +endif() + get_filename_component(UNIT_TESTS_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../../.." ABSOLUTE) get_filename_component(APPS_DIR "${UNIT_TESTS_DIR}/.." ABSOLUTE) get_filename_component(REPO_ROOT_DIR "${APPS_DIR}/.." ABSOLUTE) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index dfa3b78a0..bf48db7d1 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -8,7 +8,7 @@ variables: - name: CMAKE_VERSION value: 3.31.6 - name: NDK_VERSION - value: 28.2.13676358 + value: 25.2.9519653 - name: UNITY_BUILD value: true - name: XCODE_VERSION From 8d910e70ffac60f6b3122eaf838aa45520fb31c2 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Thu, 13 Nov 2025 09:52:47 +0100 Subject: [PATCH 13/47] removed perf test --- .github/jobs/linux.yml | 6 +- .github/jobs/macos.yml | 3 +- .../Android/BabylonNative/CMakeLists.txt | 7 -- .../Android/BabylonNative/build.gradle | 8 +- Apps/UnitTests/Android/app/build.gradle | 7 +- .../Android/app/src/main/cpp/CMakeLists.txt | 7 -- Apps/UnitTests/CMakeLists.txt | 6 +- .../Scripts/unittests_performance_spheres.ts | 33 ------- Apps/UnitTests/Shared/Shared.cpp | 85 ------------------- Apps/UnitTests/webpack.config.js | 1 - CMakeLists.txt | 18 +++- azure-pipelines.yml | 7 +- 12 files changed, 27 insertions(+), 161 deletions(-) delete mode 100644 Apps/UnitTests/Scripts/unittests_performance_spheres.ts diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index 75204d49c..19a58b46e 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -4,7 +4,7 @@ parameters: CC: '' CXX: '' JSEngine: '' - Sanitizers: false + enableSanitizers: false jobs: - job: ${{ parameters.name }} @@ -13,7 +13,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF') }} + SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.enableSanitizers), 'True', 'ON'), 'OFF') }} CC: ${{ parameters.CC }} CXX: ${{ parameters.CXX }} @@ -24,7 +24,7 @@ jobs: - script: | sudo apt-get update - sudo apt-get install libjavascriptcoregtk-4.1-dev libgl1-mesa-dev libcurl4-openssl-dev libwayland-dev + sudo apt-get install libjavascriptcoregtk-4.1-dev libgl1-mesa-dev libcurl4-openssl-dev libwayland-dev clang displayName: 'Install packages' - script: | diff --git a/.github/jobs/macos.yml b/.github/jobs/macos.yml index 9e2e2fb23..748dd4bb4 100644 --- a/.github/jobs/macos.yml +++ b/.github/jobs/macos.yml @@ -1,6 +1,7 @@ parameters: name: '' vmImage: '' + enableSanitizers: false jobs: - job: ${{ parameters.name }} @@ -9,7 +10,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF') }} + SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.enableSanitizers), 'True', 'ON'), 'OFF') }} steps: - template: cmake.yml diff --git a/Apps/Playground/Android/BabylonNative/CMakeLists.txt b/Apps/Playground/Android/BabylonNative/CMakeLists.txt index 27227bd14..4d6e6e2d8 100644 --- a/Apps/Playground/Android/BabylonNative/CMakeLists.txt +++ b/Apps/Playground/Android/BabylonNative/CMakeLists.txt @@ -5,13 +5,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) project(BabylonNative) -if(ENABLE_SANITIZERS) - set(ENABLE_RTTI ON CACHE BOOL "" FORCE) - set(SANITIZERS "address,undefined") - add_compile_options(-fsanitize=${SANITIZERS} -fno-omit-frame-pointer) - add_link_options(-fsanitize=${SANITIZERS}) -endif() - get_filename_component(PLAYGROUND_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE) get_filename_component(REPO_ROOT_DIR "${PLAYGROUND_DIR}/../.." ABSOLUTE) diff --git a/Apps/Playground/Android/BabylonNative/build.gradle b/Apps/Playground/Android/BabylonNative/build.gradle index 8f3a0d269..9082ed1fd 100644 --- a/Apps/Playground/Android/BabylonNative/build.gradle +++ b/Apps/Playground/Android/BabylonNative/build.gradle @@ -20,10 +20,7 @@ def unity_build = "false" if (project.hasProperty("UNITY_BUILD")) { unity_build = project.property("UNITY_BUILD") } -def sanitizers = "OFF" -if (project.hasProperty("SANITIZERS")) { - sanitizers = project.property("SANITIZERS") -} + def arcore_libpath = "${buildDir}/arcore-native" configurations { natives } @@ -52,8 +49,7 @@ android { "-DNAPI_JAVASCRIPT_ENGINE=${jsEngine}", "-DBABYLON_NATIVE_BUILD_APPS=ON", "-DCMAKE_UNITY_BUILD=${unity_build}", - "-DBABYLON_DEBUG_TRACE=ON", - "-DENABLE_SANITIZERS=${sanitizers}" + "-DBABYLON_DEBUG_TRACE=ON" } } ndk { diff --git a/Apps/UnitTests/Android/app/build.gradle b/Apps/UnitTests/Android/app/build.gradle index 1b120be8e..e6fca383d 100644 --- a/Apps/UnitTests/Android/app/build.gradle +++ b/Apps/UnitTests/Android/app/build.gradle @@ -6,10 +6,6 @@ def jsEngine = "V8" if (project.hasProperty("jsEngine")) { jsEngine = project.property("jsEngine") } -def sanitizers = "OFF" -if (project.hasProperty("SANITIZERS")) { - sanitizers = project.property("SANITIZERS") -} configurations { natives } @@ -33,8 +29,7 @@ android { "-DANDROID_STL=c++_shared", "-DNAPI_JAVASCRIPT_ENGINE=${jsEngine}", "-DJSRUNTIMEHOST_CORE_APPRUNTIME_V8_INSPECTOR=ON", - "-DBABYLON_NATIVE_BUILD_APPS=ON", - "-DENABLE_SANITIZERS=${sanitizers}" + "-DBABYLON_NATIVE_BUILD_APPS=ON" ) } } diff --git a/Apps/UnitTests/Android/app/src/main/cpp/CMakeLists.txt b/Apps/UnitTests/Android/app/src/main/cpp/CMakeLists.txt index dad94b8df..e8049cf63 100644 --- a/Apps/UnitTests/Android/app/src/main/cpp/CMakeLists.txt +++ b/Apps/UnitTests/Android/app/src/main/cpp/CMakeLists.txt @@ -5,13 +5,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) project(UnitTestsJNI) -if(ENABLE_SANITIZERS) - set(ENABLE_RTTI ON CACHE BOOL "" FORCE) - set(SANITIZERS "address,undefined") - add_compile_options(-fsanitize=${SANITIZERS} -fno-omit-frame-pointer) - add_link_options(-fsanitize=${SANITIZERS}) -endif() - get_filename_component(UNIT_TESTS_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../../.." ABSOLUTE) get_filename_component(APPS_DIR "${UNIT_TESTS_DIR}/.." ABSOLUTE) get_filename_component(REPO_ROOT_DIR "${APPS_DIR}/.." ABSOLUTE) diff --git a/Apps/UnitTests/CMakeLists.txt b/Apps/UnitTests/CMakeLists.txt index 5a35ac2e3..14c623e69 100644 --- a/Apps/UnitTests/CMakeLists.txt +++ b/Apps/UnitTests/CMakeLists.txt @@ -5,13 +5,11 @@ endif() set(SCRIPTS "Scripts/tests.ts" - "Scripts/unittests_performance_shadercache.ts" - "Scripts/unittests_performance_spheres.ts") + "Scripts/unittests_performance_shadercache.ts") set(BUILD_SCRIPTS "dist/tests.js" - "dist/unittests_performance_shadercache.js" - "dist/unittests_performance_spheres.js") + "dist/unittests_performance_shadercache.js") set(SOURCES "Shared/Shared.h" diff --git a/Apps/UnitTests/Scripts/unittests_performance_spheres.ts b/Apps/UnitTests/Scripts/unittests_performance_spheres.ts deleted file mode 100644 index c4f7de559..000000000 --- a/Apps/UnitTests/Scripts/unittests_performance_spheres.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { - Scene, - NativeEngine, - Mesh -} from "@babylonjs/core"; - -declare const setSceneReady: () => void; -declare const setReady: () => void; - -console.log("Setting up Performance test."); -var engine = new NativeEngine(); -var scene = new Scene(engine); - -var size = 12; -for (var i = 0; i < size; i++) { - for (var j = 0; j < size; j++) { - for (var k = 0; k < size; k++) { - var sphere = Mesh.CreateSphere("sphere" + i + j + k, 32, 0.9, scene); - sphere.position.x = i; - sphere.position.y = j; - sphere.position.z = k; - } - } -} - -scene.createDefaultCamera(true, true, true); -scene.activeCamera.alpha += Math.PI; -scene.createDefaultLight(true); -engine.runRenderLoop(function () { - scene.render(); -}); -console.log("Ready!"); -setReady(); diff --git a/Apps/UnitTests/Shared/Shared.cpp b/Apps/UnitTests/Shared/Shared.cpp index 871582001..dcf05f7e1 100644 --- a/Apps/UnitTests/Shared/Shared.cpp +++ b/Apps/UnitTests/Shared/Shared.cpp @@ -99,91 +99,6 @@ TEST(JavaScript, All) EXPECT_EQ(exitCode, 0); } -/* -This test does a serie of initialization and shutdowns. -It needs the shutdown PR to be merged before running properly. -TEST(NativeAPI, LifeCycle) -{ - for (int cycle = 0; cycle < 20; cycle++) - { - Babylon::Graphics::Device device{deviceConfig}; - std::optional nativeCanvas; - - Babylon::AppRuntime runtime{}; - runtime.Dispatch([&device, &nativeCanvas](Napi::Env env) { - device.AddToJavaScript(env); - - Babylon::Polyfills::XMLHttpRequest::Initialize(env); - Babylon::Polyfills::Console::Initialize(env, [](const char* message, auto) { - printf("%s", message); - fflush(stdout); - }); - Babylon::Polyfills::Window::Initialize(env); - nativeCanvas.emplace(Babylon::Polyfills::Canvas::Initialize(env)); - Babylon::Plugins::NativeEngine::Initialize(env); - }); - - Babylon::ScriptLoader loader{runtime}; - loader.LoadScript("app:///Scripts/babylon.max.js"); - loader.LoadScript("app:///Scripts/babylonjs.materials.js"); - - for (int frame = 0; frame < 10; frame++) - { - device.StartRenderingCurrentFrame(); - device.FinishRenderingCurrentFrame(); - } - } -} -*/ - -TEST(Performance, Spheres) -{ - // create a bunch of sphere, does the rendering for a number of frames, log time it took - Babylon::Graphics::Device device{deviceConfig}; - std::optional update{}; - std::promise ready; - update.emplace(device.GetUpdate("update")); - - Babylon::AppRuntime runtime{}; - runtime.Dispatch([&ready, &device](Napi::Env env) { - device.AddToJavaScript(env); - - Babylon::Polyfills::Console::Initialize(env, [](const char* message, auto) { - std::cout << message << std::endl; - std::cout.flush(); - }); - Babylon::Polyfills::Window::Initialize(env); - Babylon::Plugins::NativeEngine::Initialize(env); - env.Global().Set("setReady", Napi::Function::New( - env, [&ready](const Napi::CallbackInfo& info) { - Napi::Env env = info.Env(); - ready.set_value(1); - }, - "setReady")); - }); - - Babylon::ScriptLoader loader{runtime}; - loader.LoadScript("app:///Scripts/unittests_performance_spheres.js"); - - ready.get_future().get(); - - const auto start = std::chrono::high_resolution_clock::now(); - - for (int frame = 0; frame < 100; frame++) - { - device.StartRenderingCurrentFrame(); - update->Start(); - update->Finish(); - device.FinishRenderingCurrentFrame(); - } - // Stop measuring time - const auto stop = std::chrono::high_resolution_clock::now(); - const auto duration = std::chrono::duration_cast(stop - start); - const float durationSeconds = float(duration.count()) / 1000.f; - std::cout << "Duration is " << durationSeconds << " seconds. " << std::endl; - std::cout.flush(); -} - TEST(Performance, ShaderCache) { Babylon::ShaderCache::Enabled(true); diff --git a/Apps/UnitTests/webpack.config.js b/Apps/UnitTests/webpack.config.js index 63efc17a0..ac5cb119b 100644 --- a/Apps/UnitTests/webpack.config.js +++ b/Apps/UnitTests/webpack.config.js @@ -8,7 +8,6 @@ module.exports = { entry: { tests: './Scripts/tests.ts', unittests_performance_shadercache: './Scripts/unittests_performance_shadercache.ts', - unittests_performance_spheres: './Scripts/unittests_performance_spheres.ts', }, output: { filename: '[name].js', diff --git a/CMakeLists.txt b/CMakeLists.txt index eb745fa8d..871c18781 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ include(FetchContent) # -------------------------------------------------- FetchContent_Declare(AndroidExtensions GIT_REPOSITORY https://github.com/BabylonJS/AndroidExtensions.git - GIT_TAG 66520bff9b57030b67894a4934d18ad7e161ba6f) + GIT_TAG f7ed149b5360cc8a4908fece66607c5ce1e6095b) FetchContent_Declare(arcana.cpp GIT_REPOSITORY https://github.com/microsoft/arcana.cpp.git GIT_TAG c726dbe58713eda65bfb139c257093c43479b894) @@ -114,13 +114,23 @@ if(ENABLE_SANITIZERS) set(ENABLE_RTTI ON CACHE BOOL "" FORCE) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") set(SANITIZERS "address,undefined") - add_compile_options(-fsanitize=${SANITIZERS} -fno-omit-frame-pointer) - add_link_options(-fsanitize=${SANITIZERS}) + # Check for Clang since vptr and fdsan are Clang-specific + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + list(APPEND SANITIZERS "vptr") + # FDSan only works on Android builds with Clang + if (ANDROID) + list(APPEND SANITIZERS "fdsan") + endif() + endif() + + string(JOIN "," SANITIZER_FLAGS ${SANITIZERS}) + + add_compile_options(-fsanitize=${SANITIZER_FLAGS} -fno-omit-frame-pointer) + add_link_options(-fsanitize=${SANITIZER_FLAGS}) else() message(WARNING "Sanitizers not supported on this compiler.") endif() endif() - # -------------------------------------------------- if(ANDROID) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index bf48db7d1..c74b334e8 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -8,7 +8,7 @@ variables: - name: CMAKE_VERSION value: 3.31.6 - name: NDK_VERSION - value: 25.2.9519653 + value: 28.2.13676358 - name: UNITY_BUILD value: true - name: XCODE_VERSION @@ -25,7 +25,7 @@ jobs: parameters: name: MacOS_Sanitizers vmImage: 'macOS-latest' - Sanitizers: true + enableSanitizers: true - template: .github/jobs/ios.yml parameters: @@ -115,7 +115,7 @@ jobs: CC: clang CXX: clang++ JSEngine: JavaScriptCore - Sanitizers: true + enableSanitizers: true # Android - template: .github/jobs/android.yml @@ -147,7 +147,6 @@ jobs: name: Android_MacOS_V8_Sanitizers vmImage: 'macOS-latest' JSEngine: V8 - Sanitizers: true # Installation tests. - template: .github/jobs/test_install_win32.yml From 8f93ea4f94c3b935905b492810d99941f781860d Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Thu, 13 Nov 2025 18:34:12 +0100 Subject: [PATCH 14/47] JSRuntimeHost update --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 871c18781..f0d63e05e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ FetchContent_Declare(ios-cmake GIT_TAG 4.5.0) FetchContent_Declare(JsRuntimeHost GIT_REPOSITORY https://github.com/BabylonJS/JsRuntimeHost.git - GIT_TAG 7964539e733a5cd2cbae7e0155f5391d64a9d45d) + GIT_TAG 70ba1e53d386c3f50727d6586c71aece614ff08b) FetchContent_Declare(SPIRV-Cross GIT_REPOSITORY https://github.com/BabylonJS/SPIRV-Cross.git GIT_TAG 6abfcf066d171e9ade7604d91381ebebe4209edc) From 55ee8007c5af63507dd2868e389202cf14b59192 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Fri, 14 Nov 2025 09:28:14 +0100 Subject: [PATCH 15/47] removed android + sanitizer --- azure-pipelines.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c74b334e8..4b8f001a5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -142,12 +142,6 @@ jobs: vmImage: 'macOS-latest' JSEngine: V8 - - template: .github/jobs/android.yml - parameters: - name: Android_MacOS_V8_Sanitizers - vmImage: 'macOS-latest' - JSEngine: V8 - # Installation tests. - template: .github/jobs/test_install_win32.yml parameters: From 31f815f926e2b1a16a2f1843a533cb764ab82706 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Fri, 14 Nov 2025 11:03:40 +0100 Subject: [PATCH 16/47] disable ubsan for 1 template method --- Plugins/NativeEngine/Source/NativeDataStream.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Plugins/NativeEngine/Source/NativeDataStream.h b/Plugins/NativeEngine/Source/NativeDataStream.h index e3bb1140a..c0e0fcf08 100644 --- a/Plugins/NativeEngine/Source/NativeDataStream.h +++ b/Plugins/NativeEngine/Source/NativeDataStream.h @@ -89,6 +89,12 @@ namespace Babylon } template +#ifndef _MSC_VER + // Clang reports UndefinedBehaviorSanitizer : undefined - behavior + // load of misaligned address which requires 8 byte alignment + // pointed data are fine so it looks like a false positive + __attribute__((no_sanitize("undefined"))) +#endif T ReadNativeData() { Validate(*this); From c80dd5c09a298b7055526ea948e325904d04deab Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Fri, 14 Nov 2025 11:45:57 +0100 Subject: [PATCH 17/47] fix leaks --- Apps/Playground/X11/App.cpp | 1 + .../TestUtils/Source/Unix/TestUtilsImpl.cpp | 21 +++++++++++++------ Polyfills/Canvas/Source/Path2D.cpp | 9 ++++---- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Apps/Playground/X11/App.cpp b/Apps/Playground/X11/App.cpp index b5395b8a4..31e24afdc 100644 --- a/Apps/Playground/X11/App.cpp +++ b/Apps/Playground/X11/App.cpp @@ -296,5 +296,6 @@ int main(int _argc, const char* const* _argv) XUnmapWindow(display, window); XDestroyWindow(display, window); + XCloseDisplay(display); return 0; } diff --git a/Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp b/Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp index d7185cb1a..6f91f1a1b 100644 --- a/Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp +++ b/Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp @@ -11,6 +11,7 @@ namespace Babylon::Plugins::TestUtils { int errorCode{}; + Display* display{nullptr}; } namespace Babylon::Plugins::Internal @@ -20,15 +21,20 @@ namespace Babylon::Plugins::Internal auto window = (Window)m_implData->m_window; const int32_t exitCode = info[0].As().Int32Value(); Plugins::TestUtils::errorCode = exitCode; - Display* display = XOpenDisplay(NULL); + if (!Plugins::TestUtils::display) + { + Plugins::TestUtils::display = XOpenDisplay(NULL); + } XClientMessageEvent dummyEvent; memset(&dummyEvent, 0, sizeof(XClientMessageEvent)); dummyEvent.type = ClientMessage; dummyEvent.window = window; dummyEvent.format = 32; - dummyEvent.data.l[0] = XInternAtom(display, "WM_DELETE_WINDOW", False);; - XSendEvent(display, window, 0, 0, (XEvent*)&dummyEvent); - XFlush(display); + dummyEvent.data.l[0] = XInternAtom(Plugins::TestUtils::display, "WM_DELETE_WINDOW", False);; + XSendEvent(Plugins::TestUtils::display, window, 0, 0, (XEvent*)&dummyEvent); + XFlush(Plugins::TestUtils::display); + XCloseDisplay(Plugins::TestUtils::display) + Plugins::TestUtils::display = nullptr; } void TestUtils::UpdateSize(const Napi::CallbackInfo& /*info*/) @@ -38,9 +44,12 @@ namespace Babylon::Plugins::Internal void TestUtils::SetTitle(const Napi::CallbackInfo& info) { const auto title = info[0].As().Utf8Value(); - Display* display = XOpenDisplay(NULL); + if (!Plugins::TestUtils::display) + { + Plugins::TestUtils::display = XOpenDisplay(NULL); + } auto window = (Window)m_implData->m_window; - XStoreName(display, window, title.c_str()); + XStoreName(Plugins::TestUtils::display, window, title.c_str()); } Napi::Value TestUtils::GetOutputDirectory(const Napi::CallbackInfo& info) diff --git a/Polyfills/Canvas/Source/Path2D.cpp b/Polyfills/Canvas/Source/Path2D.cpp index 95d927222..12a5edfa6 100644 --- a/Polyfills/Canvas/Source/Path2D.cpp +++ b/Polyfills/Canvas/Source/Path2D.cpp @@ -136,7 +136,8 @@ namespace Babylon::Polyfills::Internal const NativeCanvasPath2D* path = NativeCanvasPath2D::Unwrap(info[0].As()); // optional transform arg - float *xformInv = nullptr; + bool xformInvReady{false}; + float xformInv[6]; if (info.Length() == 2) { Napi::Object transform = info[1].As(); @@ -148,8 +149,8 @@ namespace Babylon::Polyfills::Internal auto f = transform.Get("f").As().FloatValue(); float xform[6] = {a, b, c, d, e, f}; - xformInv = new float[6]; nsvg__xformInverse(xformInv, xform); + xformInvReady = true; Path2DCommandArgs args = {}; args.transform = { xform[0], xform[1], xform[2], xform[3], xform[4], xform[5] }; @@ -164,9 +165,9 @@ namespace Babylon::Polyfills::Internal // invert transform after all commands played if (info.Length() == 2) { - assert(xformInv != nullptr); + assert(xformInvReady); Path2DCommandArgs argsInv = {}; - argsInv.transform = { xformInv[0], xformInv[1], xformInv[2], xformInv[3], xformInv[4], xformInv[5] }; + argsInv.transform = {xformInv[0], xformInv[1], xformInv[2], xformInv[3], xformInv[4], xformInv[5]}; AppendCommand(P2D_TRANSFORM, argsInv); } } From 88724f31a568c5b2048e03d7011f1078717362cf Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Fri, 14 Nov 2025 12:06:48 +0100 Subject: [PATCH 18/47] fix casting --- Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp | 2 +- Polyfills/Canvas/Source/nanovg/nanovg.cpp | 12 ++++++------ Polyfills/Canvas/Source/nanovg/nanovg_babylon.cpp | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp b/Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp index 6f91f1a1b..f02427d96 100644 --- a/Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp +++ b/Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp @@ -33,7 +33,7 @@ namespace Babylon::Plugins::Internal dummyEvent.data.l[0] = XInternAtom(Plugins::TestUtils::display, "WM_DELETE_WINDOW", False);; XSendEvent(Plugins::TestUtils::display, window, 0, 0, (XEvent*)&dummyEvent); XFlush(Plugins::TestUtils::display); - XCloseDisplay(Plugins::TestUtils::display) + XCloseDisplay(Plugins::TestUtils::display); Plugins::TestUtils::display = nullptr; } diff --git a/Polyfills/Canvas/Source/nanovg/nanovg.cpp b/Polyfills/Canvas/Source/nanovg/nanovg.cpp index 541ea0faf..771b0da8e 100644 --- a/Polyfills/Canvas/Source/nanovg/nanovg.cpp +++ b/Polyfills/Canvas/Source/nanovg/nanovg.cpp @@ -2438,7 +2438,7 @@ static void nvg__renderText(NVGcontext* ctx, NVGpaint* paint, NVGvertex* verts, static float nvg__getSdfFontSize(NVGstate* state, float scale) { - int fontSize = state->fontSize*scale; + int fontSize = static_cast(state->fontSize * scale); int sdfFontSize = 32; // We double the font size so that SDFs are also used for smaller font sizes @@ -2447,7 +2447,7 @@ static float nvg__getSdfFontSize(NVGstate* state, float scale) // Reduce the font size to a powers of 4 after 32 (e.g. 32, 32*4, 32*4*4) fontSize /= sdfFontSize; while (fontSize /= 4) sdfFontSize *= 4; - return sdfFontSize; + return static_cast(sdfFontSize); } // Computes the distance in SDF values of a single pixel @@ -2536,9 +2536,9 @@ float nvgText(NVGcontext* ctx, float x, float y, const char* string, const char* float scale = nvg__getFontScale(state) * ctx->devicePxRatio; float pixelDist = nvg__getSdfPixelDist(state, scale); - paint.sdfMin = 0.5; + paint.sdfMin = 0.5f; // Add an extra pixel so it doesn't start fading out in the middle of the text - paint.sdfMax = 1.0 + pixelDist; + paint.sdfMax = 1.0f + pixelDist; // TODO: handle text blurring paint.sdfBlur = pixelDist; return nvg__text(ctx, &paint, scale, x, y, string, end); @@ -2554,8 +2554,8 @@ float nvgStrokeText(NVGcontext* ctx, float x, float y, const char* string, const // The distance in SDF values to get the required stroke width float strokeDist = state->strokeWidth * strokeScale * pixelDist; - paint.sdfMin = 0.5 - strokeDist / 2; - paint.sdfMax = 0.5 + strokeDist / 2; + paint.sdfMin = 0.5f - strokeDist / 2.f; + paint.sdfMax = 0.5f + strokeDist / 2.f; // TODO: handle text blurring paint.sdfBlur = pixelDist; return nvg__text(ctx, &paint, scale, x, y, string, end); diff --git a/Polyfills/Canvas/Source/nanovg/nanovg_babylon.cpp b/Polyfills/Canvas/Source/nanovg/nanovg_babylon.cpp index 583ad1c57..510f123ca 100644 --- a/Polyfills/Canvas/Source/nanovg/nanovg_babylon.cpp +++ b/Polyfills/Canvas/Source/nanovg/nanovg_babylon.cpp @@ -1328,6 +1328,7 @@ namespace bgfx::destroy(gl->u_scissorExtScale); bgfx::destroy(gl->u_extentRadius); bgfx::destroy(gl->u_params); + bgfx::destroy(gl->u_sdf); bgfx::destroy(gl->s_tex); bgfx::destroy(gl->s_tex2); nanovg_filterstack::DisposeBgfx(); From 9345b67589b188ecb888b273a22dbc0f833dd3db Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Fri, 14 Nov 2025 12:47:07 +0100 Subject: [PATCH 19/47] leaks and warnings --- Core/Graphics/Source/DeviceImpl_Unix.cpp | 1 + .../TestUtils/Source/Unix/TestUtilsImpl.cpp | 23 +++++++------------ Polyfills/Canvas/Source/nanosvg.h | 14 +++++------ 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/Core/Graphics/Source/DeviceImpl_Unix.cpp b/Core/Graphics/Source/DeviceImpl_Unix.cpp index 80c9df92e..202abfe37 100644 --- a/Core/Graphics/Source/DeviceImpl_Unix.cpp +++ b/Core/Graphics/Source/DeviceImpl_Unix.cpp @@ -33,6 +33,7 @@ namespace Babylon::Graphics // See: https://scanline.ca/dpi/ return dpi / 96.0f; } + XCloseDisplay(display); return 1; } diff --git a/Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp b/Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp index f02427d96..2db0dc43a 100644 --- a/Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp +++ b/Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp @@ -11,7 +11,6 @@ namespace Babylon::Plugins::TestUtils { int errorCode{}; - Display* display{nullptr}; } namespace Babylon::Plugins::Internal @@ -21,20 +20,16 @@ namespace Babylon::Plugins::Internal auto window = (Window)m_implData->m_window; const int32_t exitCode = info[0].As().Int32Value(); Plugins::TestUtils::errorCode = exitCode; - if (!Plugins::TestUtils::display) - { - Plugins::TestUtils::display = XOpenDisplay(NULL); - } + auto display = XOpenDisplay(NULL); XClientMessageEvent dummyEvent; memset(&dummyEvent, 0, sizeof(XClientMessageEvent)); dummyEvent.type = ClientMessage; dummyEvent.window = window; dummyEvent.format = 32; - dummyEvent.data.l[0] = XInternAtom(Plugins::TestUtils::display, "WM_DELETE_WINDOW", False);; - XSendEvent(Plugins::TestUtils::display, window, 0, 0, (XEvent*)&dummyEvent); - XFlush(Plugins::TestUtils::display); - XCloseDisplay(Plugins::TestUtils::display); - Plugins::TestUtils::display = nullptr; + dummyEvent.data.l[0] = XInternAtom(display, "WM_DELETE_WINDOW", False);; + XSendEvent(display, window, 0, 0, (XEvent*)&dummyEvent); + XFlush(display); + XCloseDisplay(display); } void TestUtils::UpdateSize(const Napi::CallbackInfo& /*info*/) @@ -44,12 +39,10 @@ namespace Babylon::Plugins::Internal void TestUtils::SetTitle(const Napi::CallbackInfo& info) { const auto title = info[0].As().Utf8Value(); - if (!Plugins::TestUtils::display) - { - Plugins::TestUtils::display = XOpenDisplay(NULL); - } + auto display = XOpenDisplay(NULL); auto window = (Window)m_implData->m_window; - XStoreName(Plugins::TestUtils::display, window, title.c_str()); + XStoreName(display, window, title.c_str()); + XCloseDisplay(display); } Napi::Value TestUtils::GetOutputDirectory(const Napi::CallbackInfo& info) diff --git a/Polyfills/Canvas/Source/nanosvg.h b/Polyfills/Canvas/Source/nanosvg.h index 76e0dbebe..df90da446 100644 --- a/Polyfills/Canvas/Source/nanosvg.h +++ b/Polyfills/Canvas/Source/nanosvg.h @@ -1248,7 +1248,7 @@ static unsigned int nsvg__parseColorRGB(const char* str) while (*str && (nsvg__isspace(*str))) str++; // skip leading spaces if (*str == '+') str++; // skip '+' (don't allow '-') if (!*str) break; - rgbf[i] = nsvg__atof(str); + rgbf[i] = static_cast(nsvg__atof(str)); // Note 1: it would be great if nsvg__atof() returned how many // bytes it consumed but it doesn't. We need to skip the number, @@ -1270,9 +1270,9 @@ static unsigned int nsvg__parseColorRGB(const char* str) else break; } if (i == 3) { - rgbi[0] = roundf(rgbf[0] * 2.55f); - rgbi[1] = roundf(rgbf[1] * 2.55f); - rgbi[2] = roundf(rgbf[2] * 2.55f); + rgbi[0] = static_cast(roundf(rgbf[0] * 2.55f)); + rgbi[1] = static_cast(roundf(rgbf[1] * 2.55f)); + rgbi[2] = static_cast(roundf(rgbf[2] * 2.55f)); } else { rgbi[0] = rgbi[1] = rgbi[2] = 128; } @@ -1478,7 +1478,7 @@ static float nsvg__parseOpacity(const char* str) static float nsvg__parseMiterLimit(const char* str) { - float val = nsvg__atof(str); + float val = static_cast(nsvg__atof(str)); if (val < 0.0f) val = 0.0f; return val; } @@ -1520,7 +1520,7 @@ static NSVGcoordinate nsvg__parseCoordinateRaw(const char* str) NSVGcoordinate coord = {0, NSVG_UNITS_USER}; char buf[64]; coord.units = nsvg__parseUnits(nsvg__parseNumber(str, buf, 64)); - coord.value = nsvg__atof(buf); + coord.value = static_cast(nsvg__atof(buf)); return coord; } @@ -2594,7 +2594,7 @@ static void nsvg__parseSVG(NSVGparser* p, const char** attr) const char *s = attr[i + 1]; char buf[64]; s = nsvg__parseNumber(s, buf, 64); - p->viewMinx = nsvg__atof(buf); + p->viewMinx = static_cast(nsvg__atof(buf)); while (*s && (nsvg__isspace(*s) || *s == '%' || *s == ',')) s++; if (!*s) return; s = nsvg__parseNumber(s, buf, 64); From 51740d364a27370026c75d9fd1adbe83338f2f45 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Fri, 14 Nov 2025 14:10:09 +0100 Subject: [PATCH 20/47] early exit --- Core/Graphics/Source/DeviceImpl_Unix.cpp | 3 ++- Polyfills/Canvas/Source/nanosvg.h | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Core/Graphics/Source/DeviceImpl_Unix.cpp b/Core/Graphics/Source/DeviceImpl_Unix.cpp index 202abfe37..4a39ddd99 100644 --- a/Core/Graphics/Source/DeviceImpl_Unix.cpp +++ b/Core/Graphics/Source/DeviceImpl_Unix.cpp @@ -23,6 +23,8 @@ namespace Babylon::Graphics auto width = DisplayWidthMM(display, screen); auto pixelWidth = DisplayWidth(display, screen); + XCloseDisplay(display); + if (width > 0) { constexpr float MILLIMETERS_TO_INCHES = 0.03937f; @@ -33,7 +35,6 @@ namespace Babylon::Graphics // See: https://scanline.ca/dpi/ return dpi / 96.0f; } - XCloseDisplay(display); return 1; } diff --git a/Polyfills/Canvas/Source/nanosvg.h b/Polyfills/Canvas/Source/nanosvg.h index df90da446..7722ca785 100644 --- a/Polyfills/Canvas/Source/nanosvg.h +++ b/Polyfills/Canvas/Source/nanosvg.h @@ -1470,7 +1470,7 @@ static unsigned int nsvg__parseColor(const char* str) static float nsvg__parseOpacity(const char* str) { - float val = nsvg__atof(str); + float val = static_cast(nsvg__atof(str)); if (val < 0.0f) val = 0.0f; if (val > 1.0f) val = 1.0f; return val; @@ -2598,15 +2598,15 @@ static void nsvg__parseSVG(NSVGparser* p, const char** attr) while (*s && (nsvg__isspace(*s) || *s == '%' || *s == ',')) s++; if (!*s) return; s = nsvg__parseNumber(s, buf, 64); - p->viewMiny = nsvg__atof(buf); + p->viewMiny = static_cast(nsvg__atof(buf)); while (*s && (nsvg__isspace(*s) || *s == '%' || *s == ',')) s++; if (!*s) return; s = nsvg__parseNumber(s, buf, 64); - p->viewWidth = nsvg__atof(buf); + p->viewWidth = static_cast(nsvg__atof(buf)); while (*s && (nsvg__isspace(*s) || *s == '%' || *s == ',')) s++; if (!*s) return; s = nsvg__parseNumber(s, buf, 64); - p->viewHeight = nsvg__atof(buf); + p->viewHeight = static_cast(nsvg__atof(buf)); } else if (strcmp(attr[i], "preserveAspectRatio") == 0) { if (strstr(attr[i + 1], "none") != 0) { // No uniform scaling From a46ad858ab17ee034e24cb67d357e5f0783792a1 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Fri, 14 Nov 2025 14:39:29 +0100 Subject: [PATCH 21/47] mem leak --- Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h b/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h index 43f64478e..c8d369eb2 100644 --- a/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h +++ b/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h @@ -44,7 +44,10 @@ class nanovg_filterstack { // break down shadow as blur + color } - void Clear() { stackElements.clear(); } + void Clear() + { + stackElements = std::vector(); // deallocate memory + } protected: enum StackElementTypes From 654407ca1f9ac63e1a1905e11e59ba2166ce2b45 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Fri, 14 Nov 2025 15:51:43 +0100 Subject: [PATCH 22/47] removed union --- Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h b/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h index c8d369eb2..9134806db 100644 --- a/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h +++ b/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h @@ -72,12 +72,9 @@ class nanovg_filterstack struct StackElement { StackElementTypes type; - union - { - SepiaElement sepiaElement; - Contrast contrastElement; - Blur blurElement; - }; + SepiaElement sepiaElement; + Contrast contrastElement; + Blur blurElement; }; std::vector stackElements; From 5c1c3afe3d732c8aecf5306cf5e056f584838bb3 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Mon, 17 Nov 2025 17:26:42 +0100 Subject: [PATCH 23/47] operator = --- Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h b/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h index 9134806db..59a104c4a 100644 --- a/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h +++ b/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h @@ -40,13 +40,18 @@ class nanovg_filterstack void ParseString(const std::string& string); static bool ValidString(const std::string& string); + operator =(const nanovg_filterstack& other) + { + this->stackElements = other.stackElements; + return *this; + } void AddDropShadow() { // break down shadow as blur + color } void Clear() { - stackElements = std::vector(); // deallocate memory + stackElements.clear(); // deallocate memory } protected: From 2bbe45be3e0dc2e3578fc47a8b569731befb0b0d Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Mon, 17 Nov 2025 17:29:28 +0100 Subject: [PATCH 24/47] check for self assignment --- Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h b/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h index 59a104c4a..a01e332e3 100644 --- a/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h +++ b/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h @@ -40,9 +40,12 @@ class nanovg_filterstack void ParseString(const std::string& string); static bool ValidString(const std::string& string); - operator =(const nanovg_filterstack& other) + nanovg_filterstack& operator=(const nanovg_filterstack& other) { - this->stackElements = other.stackElements; + if (this != &other) + { + this->stackElements = other.stackElements; + } return *this; } void AddDropShadow() From 2b399ad7ab8d8f5586b67be802c39c43610d73ff Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Wed, 19 Nov 2025 16:38:47 +0100 Subject: [PATCH 25/47] win32 sanitizer --- .github/jobs/win32.yml | 6 +++++- CMakeLists.txt | 4 ++++ azure-pipelines.yml | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/jobs/win32.yml b/.github/jobs/win32.yml index f716c63d4..2732bfdc5 100644 --- a/.github/jobs/win32.yml +++ b/.github/jobs/win32.yml @@ -15,6 +15,9 @@ parameters: - name: graphics_api type: string default: D3D11 +- name: enableSanitizers + type: boolean + default: false jobs: - job: ${{ parameters.name }} @@ -22,6 +25,7 @@ jobs: pool: vmImage: ${{ parameters.vmImage }} variables: + SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.enableSanitizers), 'True', 'ON'), 'OFF') }} ${{ if eq(parameters.napiType, 'jsi') }}: napiSuffix: '_JSI' jsEngineDefine: '-DNAPI_JAVASCRIPT_ENGINE=JSI' @@ -40,7 +44,7 @@ jobs: # BGFX_CONFIG_MAX_FRAME_BUFFERS is set so enough Framebuffers are available before V8 starts disposing unused ones - script: | - cmake -G "Visual Studio 17 2022" -B build${{ variables.solutionName }} -A ${{ parameters.platform }} ${{ variables.jsEngineDefine }} -D BX_CONFIG_DEBUG=ON -D GRAPHICS_API=${{ parameters.graphics_api }} -D CMAKE_UNITY_BUILD=$(UNITY_BUILD) -D BGFX_CONFIG_MAX_FRAME_BUFFERS=256 -D BABYLON_DEBUG_TRACE=ON + cmake -G "Visual Studio 17 2022" -B build${{ variables.solutionName }} -A ${{ parameters.platform }} ${{ variables.jsEngineDefine }} -D BX_CONFIG_DEBUG=ON -D GRAPHICS_API=${{ parameters.graphics_api }} -D CMAKE_UNITY_BUILD=$(UNITY_BUILD) -D BGFX_CONFIG_MAX_FRAME_BUFFERS=256 -D BABYLON_DEBUG_TRACE=ON -D ENABLE_SANITIZERS=$(SANITIZER_FLAG) displayName: 'Generate ${{ variables.solutionName }} solution' - task: MSBuild@1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fe046038..69db9b7a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,6 +127,10 @@ if(ENABLE_SANITIZERS) add_compile_options(-fsanitize=${SANITIZER_FLAGS} -fno-omit-frame-pointer) add_link_options(-fsanitize=${SANITIZER_FLAGS}) + elseif(MSVC) + # MSVC only supports AddressSanitizer + add_compile_options(/fsanitize=address /Zi /Od) + add_link_options(/fsanitize=address) else() message(WARNING "Sanitizers not supported on this compiler.") endif() diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 4b8f001a5..f485091d9 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -67,6 +67,21 @@ jobs: platform: x64 graphics_api: D3D12 + - template: .github/jobs/win32.yml + parameters: + name: Win32_x64_D3D12_Sanitizers + vmImage: 'windows-latest' + platform: x64 + enableSanitizers: true + + - template: .github/jobs/win32.yml + parameters: + name: Win32_x64_V8_D3D11_Sanitizers + vmImage: 'windows-latest' + platform: x64 + napiType: V8 + enableSanitizers: true + # UWP - template: .github/jobs/uwp.yml parameters: From 32a2773ea6fee510998c15cfbd4184d24da8d0a1 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet Date: Wed, 19 Nov 2025 16:41:32 +0100 Subject: [PATCH 26/47] fix errors reported by ASAN --- Plugins/NativeEngine/Source/NativeEngine.cpp | 2 +- Polyfills/Canvas/Source/Canvas.h | 9 +++--- Polyfills/Canvas/Source/nanovg/nanovg.cpp | 1 - .../Canvas/Source/nanovg/nanovg_babylon.cpp | 1 - .../Source/nanovg/nanovg_filterstack.cpp | 17 ++++++----- .../Canvas/Source/nanovg/nanovg_filterstack.h | 28 ++++++++----------- 6 files changed, 25 insertions(+), 33 deletions(-) diff --git a/Plugins/NativeEngine/Source/NativeEngine.cpp b/Plugins/NativeEngine/Source/NativeEngine.cpp index 19b646327..4996b3b8f 100644 --- a/Plugins/NativeEngine/Source/NativeEngine.cpp +++ b/Plugins/NativeEngine/Source/NativeEngine.cpp @@ -222,7 +222,7 @@ namespace Babylon // Unpack to RGB and RGBA such that RGB is the grayscale and the A is the alpha. bimg::ImageContainer* oldImage{image}; image = bimg::imageAlloc(&allocator, bimg::TextureFormat::RGBA8, static_cast(image->m_width), static_cast(image->m_height), 1, 1, false, false); - TransformImage(oldImage, image, image->m_format == bimg::TextureFormat::R8 ? UnpackR8 : UnpackRG8); + TransformImage(oldImage, image, oldImage->m_format == bimg::TextureFormat::R8 ? UnpackR8 : UnpackRG8); bimg::imageFree(oldImage); } diff --git a/Polyfills/Canvas/Source/Canvas.h b/Polyfills/Canvas/Source/Canvas.h index d2f1d35e0..c475997b8 100644 --- a/Polyfills/Canvas/Source/Canvas.h +++ b/Polyfills/Canvas/Source/Canvas.h @@ -22,19 +22,20 @@ namespace Babylon::Polyfills struct MonitoredResource { MonitoredResource(Canvas::Impl& impl) - : m_impl(impl) + : m_impl(impl.shared_from_this()) { - m_impl.AddMonitoredResource(this); + m_impl->AddMonitoredResource(this); } virtual ~MonitoredResource() { - m_impl.RemoveMonitoredResource(this); + m_impl->RemoveMonitoredResource(this); } virtual void FlushGraphicResources() = 0; private: - Canvas::Impl& m_impl; + // context is a monitoredResource managed by the GC while Canvas::Impl is managed by the app. Make sure the canvas impl is destroyed after all monitoredResources are. + std::shared_ptr m_impl; }; private: diff --git a/Polyfills/Canvas/Source/nanovg/nanovg.cpp b/Polyfills/Canvas/Source/nanovg/nanovg.cpp index 771b0da8e..1bf1f6a4b 100644 --- a/Polyfills/Canvas/Source/nanovg/nanovg.cpp +++ b/Polyfills/Canvas/Source/nanovg/nanovg.cpp @@ -676,7 +676,6 @@ void nvgReset(NVGcontext* ctx) state->fontBlur = 0.0f; state->textAlign = NVG_ALIGN_LEFT | NVG_ALIGN_BASELINE; state->fontId = 0; - state->m_filterStack.Clear(); } // State setting diff --git a/Polyfills/Canvas/Source/nanovg/nanovg_babylon.cpp b/Polyfills/Canvas/Source/nanovg/nanovg_babylon.cpp index 510f123ca..74a984438 100644 --- a/Polyfills/Canvas/Source/nanovg/nanovg_babylon.cpp +++ b/Polyfills/Canvas/Source/nanovg/nanovg_babylon.cpp @@ -1027,7 +1027,6 @@ namespace for (uint32_t ii = 0, num = gl->ncalls; ii < num; ++ii) { struct GLNVGcall* call = &gl->calls[ii]; - nanovg_filterstack fs = call->filterStack; // CHECK: did we want to do something with this? const GLNVGblend* blend = &call->blendFunc; gl->state = BGFX_STATE_BLEND_FUNC_SEPARATE(blend->srcRGB, blend->dstRGB, blend->srcAlpha, blend->dstAlpha) diff --git a/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.cpp b/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.cpp index 4b8612a45..874be9a18 100644 --- a/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.cpp +++ b/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.cpp @@ -85,7 +85,7 @@ bool nanovg_filterstack::ValidString(const std::string& string) void nanovg_filterstack::ParseString(const std::string& string) { - stackElements.clear(); + stackElementCount = 0; std::smatch match; if (std::regex_match(string, match, blurRegex)) @@ -101,12 +101,12 @@ void nanovg_filterstack::ParseString(const std::string& string) // TODO: convert non-px radius } - if (radius > 0) + assert(stackElementCount < MAX_STACK_SIZE); + if (radius > 0 && stackElementCount < MAX_STACK_SIZE) { - StackElement element = {}; + StackElement& element = stackElements[stackElementCount++]; element.type = SE_BLUR; element.blurElement = {radius, radius}; - stackElements.push_back(element); } } else @@ -165,15 +165,13 @@ void nanovg_filterstack::Render( std::function release ) { - if (stackElements.empty()) + if (!stackElementCount) { // no filter, render straight into final framebuffer firstPass(firstProg, finalFrameBuffer); } else { - assert(stackElements.size() > 0); - Babylon::Graphics::FrameBuffer* prevBuf = nullptr; Babylon::Graphics::FrameBuffer* nextBuf = acquire(); bgfx::ProgramHandle lastProg = firstProg; @@ -184,12 +182,13 @@ void nanovg_filterstack::Render( nextBuf = nullptr; int i = 0; - for (auto& element : stackElements) + for (int iStackElement = 0; iStackElement < stackElementCount; iStackElement++) { + auto& element = stackElements[iStackElement]; assert(prevBuf != nullptr); assert(nextBuf == nullptr); - const bool lastElement = (i == stackElements.size() - 1); + const bool lastElement = (i == stackElementCount - 1); if (element.type == SE_BLUR) { diff --git a/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h b/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h index a01e332e3..0535bfb36 100644 --- a/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h +++ b/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h @@ -40,22 +40,11 @@ class nanovg_filterstack void ParseString(const std::string& string); static bool ValidString(const std::string& string); - nanovg_filterstack& operator=(const nanovg_filterstack& other) - { - if (this != &other) - { - this->stackElements = other.stackElements; - } - return *this; - } void AddDropShadow() { // break down shadow as blur + color } - void Clear() - { - stackElements.clear(); // deallocate memory - } + protected: enum StackElementTypes @@ -79,12 +68,17 @@ class nanovg_filterstack }; struct StackElement { - StackElementTypes type; - SepiaElement sepiaElement; - Contrast contrastElement; - Blur blurElement; + union + { + StackElementTypes type; + SepiaElement sepiaElement; + Contrast contrastElement; + Blur blurElement; + }; }; - std::vector stackElements; + int stackElementCount; + static const int MAX_STACK_SIZE = 32; + StackElement stackElements[MAX_STACK_SIZE]; private: std::vector CalculateGaussianKernel(float sigma, int kernelSize); From 5db4de69503e7accd896f9a7b0e7d4c124739cad Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Wed, 19 Nov 2025 16:56:53 +0100 Subject: [PATCH 27/47] conflict --- Apps/UnitTests/JavaScript/webpack.config.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Apps/UnitTests/JavaScript/webpack.config.js b/Apps/UnitTests/JavaScript/webpack.config.js index 3034eeb6b..b66eade9a 100644 --- a/Apps/UnitTests/JavaScript/webpack.config.js +++ b/Apps/UnitTests/JavaScript/webpack.config.js @@ -6,17 +6,12 @@ module.exports = { mode: 'development', // or 'production' devtool: false, entry: { -<<<<<<< HEAD:Apps/UnitTests/webpack.config.js - tests: './Scripts/tests.ts', - unittests_performance_shadercache: './Scripts/unittests_performance_shadercache.ts' -======= "tests.javaScript.all": './src/tests.javaScript.all.ts', "tests.nativeEngine.shaderCache": './src/tests.nativeEngine.shaderCache.ts', }, externals: { "@babylonjs/core": "BABYLON", "@babylonjs/materials": "BABYLON" ->>>>>>> 4c76fc4efb820f6f793f3165dd5f12f3f59af702:Apps/UnitTests/JavaScript/webpack.config.js }, output: { filename: '[name].js', From e9c3faa93b9ba573688b5d48e1bd761bade99dba Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Thu, 20 Nov 2025 10:13:45 +0100 Subject: [PATCH 28/47] ASAN .dlls --- .github/jobs/win32.yml | 17 +++++++++++++++++ azure-pipelines.yml | 1 + 2 files changed, 18 insertions(+) diff --git a/.github/jobs/win32.yml b/.github/jobs/win32.yml index 2732bfdc5..dc56c58a3 100644 --- a/.github/jobs/win32.yml +++ b/.github/jobs/win32.yml @@ -66,6 +66,23 @@ jobs: displayName: 'Enable Crash Dumps' + - powershell: | + $vs = vswhere -latest -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath + $msvc = Get-ChildItem "$vs\VC\Tools\MSVC" | Sort-Object Name -Descending | Select-Object -First 1 + $asan = "$($msvc.FullName)\bin\Hostx64\x64" + + $destinations = @( + "build${{ variables.solutionName }}\Apps\Playground", + "build${{ variables.solutionName }}\Apps\UnitTests" + ) + + foreach ($dest in $destinations) { + Get-ChildItem "$asan\clang_rt.asan_*.dll" | + Copy-Item -Destination $dest + } + displayName: "Copy ASAN runtime DLLs" + condition: eq(variables.SANITIZER_FLAG, 'ON') + - script: | cd build${{ variables.solutionName }}\Apps\Playground cd RelWithDebInfo diff --git a/azure-pipelines.yml b/azure-pipelines.yml index f485091d9..5fc29d2cb 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -72,6 +72,7 @@ jobs: name: Win32_x64_D3D12_Sanitizers vmImage: 'windows-latest' platform: x64 + graphics_api: D3D12 enableSanitizers: true - template: .github/jobs/win32.yml From c220203493bbe6cb673f3fefc0ef1a4d1ccc8989 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Thu, 20 Nov 2025 10:36:03 +0100 Subject: [PATCH 29/47] asan dll destination path fix --- .github/jobs/win32.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/jobs/win32.yml b/.github/jobs/win32.yml index dc56c58a3..57fd9623b 100644 --- a/.github/jobs/win32.yml +++ b/.github/jobs/win32.yml @@ -72,8 +72,8 @@ jobs: $asan = "$($msvc.FullName)\bin\Hostx64\x64" $destinations = @( - "build${{ variables.solutionName }}\Apps\Playground", - "build${{ variables.solutionName }}\Apps\UnitTests" + "build${{ variables.solutionName }}\Apps\Playground\RelWithDebInfo", + "build${{ variables.solutionName }}\Apps\UnitTests\RelWithDebInfo" ) foreach ($dest in $destinations) { From 50bee8667d2735b5d30074334b772dd74b3476b1 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet Date: Thu, 20 Nov 2025 12:21:22 +0100 Subject: [PATCH 30/47] ASAN suppress list for Linux --- .github/asan_suppress.txt | 6 ++++++ .github/jobs/linux.yml | 16 +++++++++++++++- CMakeLists.txt | 1 - 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 .github/asan_suppress.txt diff --git a/.github/asan_suppress.txt b/.github/asan_suppress.txt new file mode 100644 index 000000000..91a8d344e --- /dev/null +++ b/.github/asan_suppress.txt @@ -0,0 +1,6 @@ +# Suppress leaks from dbus +leak:bmalloc_allocate_casual +leak:reallocate_for_length +leak:dbus_message_new_empty_header +# Display opened and terminated still listed as a leak +leak:bgfx::gl::GLContext::create \ No newline at end of file diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index 19a58b46e..dc555b2b8 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -36,6 +36,13 @@ jobs: cd build/Apps/Playground xvfb-run ./Playground app:///Scripts/validation_native.js displayName: 'Validation Tests' + condition: eq(variables.SANITIZER_FLAG, 'OFF') + + - script: | + cd build/Apps/Playground + ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./Playground app:///Scripts/validation_native.js + displayName: 'Validation Tests with ASAN' + condition: eq(variables.SANITIZER_FLAG, 'ON') - task: PublishBuildArtifacts@1 inputs: @@ -53,4 +60,11 @@ jobs: - script: | cd build/Apps/UnitTests xvfb-run ./UnitTests - displayName: 'Unit Tests' \ No newline at end of file + displayName: 'Unit Tests' + condition: eq(variables.SANITIZER_FLAG, 'OFF') + + - script: | + cd build/Apps/UnitTests + ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./UnitTests + displayName: 'Unit Tests with ASAN' + condition: eq(variables.SANITIZER_FLAG, 'ON') \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 69db9b7a8..1bcc5f588 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,7 +130,6 @@ if(ENABLE_SANITIZERS) elseif(MSVC) # MSVC only supports AddressSanitizer add_compile_options(/fsanitize=address /Zi /Od) - add_link_options(/fsanitize=address) else() message(WARNING "Sanitizers not supported on this compiler.") endif() From 47cede9846cdf8135f86cb247ca633c01a11b275 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Thu, 20 Nov 2025 12:37:37 +0100 Subject: [PATCH 31/47] job parameter consistency --- .github/jobs/android.yml | 2 +- .github/jobs/linux.yml | 2 +- .github/jobs/macos.yml | 2 +- .github/jobs/win32.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/jobs/android.yml b/.github/jobs/android.yml index 6c7d59c7e..2fe2a7258 100644 --- a/.github/jobs/android.yml +++ b/.github/jobs/android.yml @@ -11,7 +11,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF') }} + SANITIZER_FLAG: ${{ if eq(parameters.enableSanitizers, true) }}ON${{ else }}OFF steps: - template: cmake.yml diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index dc555b2b8..ee71a9fac 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -13,7 +13,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.enableSanitizers), 'True', 'ON'), 'OFF') }} + SANITIZER_FLAG: ${{ if eq(parameters.enableSanitizers, true) }}ON${{ else }}OFF CC: ${{ parameters.CC }} CXX: ${{ parameters.CXX }} diff --git a/.github/jobs/macos.yml b/.github/jobs/macos.yml index 748dd4bb4..f58ca74e9 100644 --- a/.github/jobs/macos.yml +++ b/.github/jobs/macos.yml @@ -10,7 +10,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.enableSanitizers), 'True', 'ON'), 'OFF') }} + SANITIZER_FLAG: ${{ if eq(parameters.enableSanitizers, true) }}ON${{ else }}OFF steps: - template: cmake.yml diff --git a/.github/jobs/win32.yml b/.github/jobs/win32.yml index 57fd9623b..5f248b93a 100644 --- a/.github/jobs/win32.yml +++ b/.github/jobs/win32.yml @@ -25,7 +25,7 @@ jobs: pool: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.enableSanitizers), 'True', 'ON'), 'OFF') }} + SANITIZER_FLAG: ${{ if eq(parameters.enableSanitizers, true) }}ON${{ else }}OFF ${{ if eq(parameters.napiType, 'jsi') }}: napiSuffix: '_JSI' jsEngineDefine: '-DNAPI_JAVASCRIPT_ENGINE=JSI' From 68b827d3f530f3e4efad56ebb8fc1687e98d1827 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Thu, 20 Nov 2025 12:42:32 +0100 Subject: [PATCH 32/47] more on job parameters --- .github/jobs/android.yml | 2 +- .github/jobs/linux.yml | 6 +++--- .github/jobs/macos.yml | 2 +- .github/jobs/win32.yml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/jobs/android.yml b/.github/jobs/android.yml index 2fe2a7258..6c7d59c7e 100644 --- a/.github/jobs/android.yml +++ b/.github/jobs/android.yml @@ -11,7 +11,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: ${{ if eq(parameters.enableSanitizers, true) }}ON${{ else }}OFF + SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF') }} steps: - template: cmake.yml diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index ee71a9fac..f09507df3 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -13,7 +13,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: ${{ if eq(parameters.enableSanitizers, true) }}ON${{ else }}OFF + SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.enableSanitizers), 'True', 'ON'), 'OFF') }} CC: ${{ parameters.CC }} CXX: ${{ parameters.CXX }} @@ -36,7 +36,7 @@ jobs: cd build/Apps/Playground xvfb-run ./Playground app:///Scripts/validation_native.js displayName: 'Validation Tests' - condition: eq(variables.SANITIZER_FLAG, 'OFF') + condition: not(eq(variables.SANITIZER_FLAG, 'ON')) - script: | cd build/Apps/Playground @@ -61,7 +61,7 @@ jobs: cd build/Apps/UnitTests xvfb-run ./UnitTests displayName: 'Unit Tests' - condition: eq(variables.SANITIZER_FLAG, 'OFF') + condition: not(eq(variables.SANITIZER_FLAG, 'ON')) - script: | cd build/Apps/UnitTests diff --git a/.github/jobs/macos.yml b/.github/jobs/macos.yml index f58ca74e9..748dd4bb4 100644 --- a/.github/jobs/macos.yml +++ b/.github/jobs/macos.yml @@ -10,7 +10,7 @@ jobs: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: ${{ if eq(parameters.enableSanitizers, true) }}ON${{ else }}OFF + SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.enableSanitizers), 'True', 'ON'), 'OFF') }} steps: - template: cmake.yml diff --git a/.github/jobs/win32.yml b/.github/jobs/win32.yml index 5f248b93a..57fd9623b 100644 --- a/.github/jobs/win32.yml +++ b/.github/jobs/win32.yml @@ -25,7 +25,7 @@ jobs: pool: vmImage: ${{ parameters.vmImage }} variables: - SANITIZER_FLAG: ${{ if eq(parameters.enableSanitizers, true) }}ON${{ else }}OFF + SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.enableSanitizers), 'True', 'ON'), 'OFF') }} ${{ if eq(parameters.napiType, 'jsi') }}: napiSuffix: '_JSI' jsEngineDefine: '-DNAPI_JAVASCRIPT_ENGINE=JSI' From b4050c3dba00e2fc3778dc926034b2e3bb7c98ce Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Thu, 20 Nov 2025 13:33:01 +0100 Subject: [PATCH 33/47] condition --- .github/jobs/linux.yml | 8 ++++---- .github/jobs/win32.yml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index f09507df3..4862266ac 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -36,13 +36,13 @@ jobs: cd build/Apps/Playground xvfb-run ./Playground app:///Scripts/validation_native.js displayName: 'Validation Tests' - condition: not(eq(variables.SANITIZER_FLAG, 'ON')) + condition: ${{ parameters.enableSanitizers }} - script: | cd build/Apps/Playground ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./Playground app:///Scripts/validation_native.js displayName: 'Validation Tests with ASAN' - condition: eq(variables.SANITIZER_FLAG, 'ON') + condition: ${{ parameters.enableSanitizers }} - task: PublishBuildArtifacts@1 inputs: @@ -61,10 +61,10 @@ jobs: cd build/Apps/UnitTests xvfb-run ./UnitTests displayName: 'Unit Tests' - condition: not(eq(variables.SANITIZER_FLAG, 'ON')) + condition: ${{ parameters.enableSanitizers }} - script: | cd build/Apps/UnitTests ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./UnitTests displayName: 'Unit Tests with ASAN' - condition: eq(variables.SANITIZER_FLAG, 'ON') \ No newline at end of file + condition: ${{ parameters.enableSanitizers }} \ No newline at end of file diff --git a/.github/jobs/win32.yml b/.github/jobs/win32.yml index 57fd9623b..5f73daf6b 100644 --- a/.github/jobs/win32.yml +++ b/.github/jobs/win32.yml @@ -81,7 +81,7 @@ jobs: Copy-Item -Destination $dest } displayName: "Copy ASAN runtime DLLs" - condition: eq(variables.SANITIZER_FLAG, 'ON') + condition: ${{ parameters.enableSanitizers }} - script: | cd build${{ variables.solutionName }}\Apps\Playground From 9fb5fa201559ac96e24d55cebd6bebe8d9b2a2d1 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Thu, 20 Nov 2025 14:10:42 +0100 Subject: [PATCH 34/47] condition --- .github/jobs/linux.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index 4862266ac..7f794a1f8 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -36,7 +36,7 @@ jobs: cd build/Apps/Playground xvfb-run ./Playground app:///Scripts/validation_native.js displayName: 'Validation Tests' - condition: ${{ parameters.enableSanitizers }} + condition: ${{ not(parameters.enableSanitizers) }} - script: | cd build/Apps/Playground @@ -61,7 +61,7 @@ jobs: cd build/Apps/UnitTests xvfb-run ./UnitTests displayName: 'Unit Tests' - condition: ${{ parameters.enableSanitizers }} + condition: ${{ not(parameters.enableSanitizers) }} - script: | cd build/Apps/UnitTests From 114239399cc58fbbe58a28f94c62253159dcf0c1 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Thu, 20 Nov 2025 14:28:27 +0100 Subject: [PATCH 35/47] condition --- azure-pipelines.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5fc29d2cb..9920d1d1a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -115,6 +115,7 @@ jobs: CC: clang CXX: clang++ JSEngine: JavaScriptCore + enableSanitizers: false - template: .github/jobs/linux.yml parameters: @@ -123,6 +124,7 @@ jobs: CC: gcc CXX: g++ JSEngine: JavaScriptCore + enableSanitizers: false - template: .github/jobs/linux.yml parameters: From 1a52baa938f34e8defbb7cdcc7a410e43d02947b Mon Sep 17 00:00:00 2001 From: Cedric Guillemet Date: Thu, 20 Nov 2025 14:43:14 +0100 Subject: [PATCH 36/47] leaking display --- Apps/UnitTests/X11/App.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Apps/UnitTests/X11/App.cpp b/Apps/UnitTests/X11/App.cpp index f14e27561..09836bf3a 100644 --- a/Apps/UnitTests/X11/App.cpp +++ b/Apps/UnitTests/X11/App.cpp @@ -53,5 +53,7 @@ int main() Babylon::DebugTrace::EnableDebugTrace(true); Babylon::DebugTrace::SetTraceOutput([](const char* trace) { printf("%s\n", trace); fflush(stdout); }); - return RunTests(config); + int ret = RunTests(config); + XCloseDisplay(display); + return ret; } \ No newline at end of file From 25d7ce00126d0d7bde8f7f3afeead588ddf08ee8 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Thu, 20 Nov 2025 14:48:28 +0100 Subject: [PATCH 37/47] typo --- .github/asan_suppress.txt | 2 +- .github/jobs/linux.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/asan_suppress.txt b/.github/asan_suppress.txt index 91a8d344e..799e9089c 100644 --- a/.github/asan_suppress.txt +++ b/.github/asan_suppress.txt @@ -3,4 +3,4 @@ leak:bmalloc_allocate_casual leak:reallocate_for_length leak:dbus_message_new_empty_header # Display opened and terminated still listed as a leak -leak:bgfx::gl::GLContext::create \ No newline at end of file +leak:bgfx::gl::GlContext::create \ No newline at end of file diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index 7f794a1f8..63b3b2228 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -36,7 +36,7 @@ jobs: cd build/Apps/Playground xvfb-run ./Playground app:///Scripts/validation_native.js displayName: 'Validation Tests' - condition: ${{ not(parameters.enableSanitizers) }} + condition: ${{ parameters.enableSanitizers == false }} - script: | cd build/Apps/Playground @@ -61,7 +61,7 @@ jobs: cd build/Apps/UnitTests xvfb-run ./UnitTests displayName: 'Unit Tests' - condition: ${{ not(parameters.enableSanitizers) }} + condition: ${{ parameters.enableSanitizers == false}} - script: | cd build/Apps/UnitTests From 097313c03a1eea11b5a3379d59bd1733cc2787b0 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Thu, 20 Nov 2025 14:52:25 +0100 Subject: [PATCH 38/47] removed condition --- .github/jobs/linux.yml | 18 ++---------------- azure-pipelines.yml | 2 -- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index 63b3b2228..ec9453ab9 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -32,17 +32,10 @@ jobs: ninja -C build displayName: 'Build X11' - - script: | - cd build/Apps/Playground - xvfb-run ./Playground app:///Scripts/validation_native.js - displayName: 'Validation Tests' - condition: ${{ parameters.enableSanitizers == false }} - - script: | cd build/Apps/Playground ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./Playground app:///Scripts/validation_native.js - displayName: 'Validation Tests with ASAN' - condition: ${{ parameters.enableSanitizers }} + displayName: 'Validation Tests' - task: PublishBuildArtifacts@1 inputs: @@ -57,14 +50,7 @@ jobs: displayName: 'Publish Tests ${{ parameters.name }} Errors' condition: failed() - - script: | - cd build/Apps/UnitTests - xvfb-run ./UnitTests - displayName: 'Unit Tests' - condition: ${{ parameters.enableSanitizers == false}} - - script: | cd build/Apps/UnitTests ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./UnitTests - displayName: 'Unit Tests with ASAN' - condition: ${{ parameters.enableSanitizers }} \ No newline at end of file + displayName: 'Unit Tests' diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 9920d1d1a..5fc29d2cb 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -115,7 +115,6 @@ jobs: CC: clang CXX: clang++ JSEngine: JavaScriptCore - enableSanitizers: false - template: .github/jobs/linux.yml parameters: @@ -124,7 +123,6 @@ jobs: CC: gcc CXX: g++ JSEngine: JavaScriptCore - enableSanitizers: false - template: .github/jobs/linux.yml parameters: From 39d2ebd270d089ae9bc24c5e21d47f6a4c9bc270 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Thu, 20 Nov 2025 15:19:04 +0100 Subject: [PATCH 39/47] suppress comment, move unittest before VT --- .github/asan_suppress.txt | 4 ++-- .github/jobs/linux.yml | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/asan_suppress.txt b/.github/asan_suppress.txt index 799e9089c..2abe1f6e3 100644 --- a/.github/asan_suppress.txt +++ b/.github/asan_suppress.txt @@ -1,6 +1,6 @@ -# Suppress leaks from dbus +# Suppress leaks from dbus. No direct leak visible with BN. leak:bmalloc_allocate_casual leak:reallocate_for_length leak:dbus_message_new_empty_header -# Display opened and terminated still listed as a leak +# false positive : Display opened and terminated still listed as a leak. leak:bgfx::gl::GlContext::create \ No newline at end of file diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index ec9453ab9..44ba723d6 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -32,6 +32,11 @@ jobs: ninja -C build displayName: 'Build X11' + - script: | + cd build/Apps/UnitTests + ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./UnitTests + displayName: 'Unit Tests' + - script: | cd build/Apps/Playground ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./Playground app:///Scripts/validation_native.js @@ -49,8 +54,3 @@ jobs: pathtoPublish: 'build/Apps/Playground/Errors' displayName: 'Publish Tests ${{ parameters.name }} Errors' condition: failed() - - - script: | - cd build/Apps/UnitTests - ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./UnitTests - displayName: 'Unit Tests' From e3274453999dc18943ddfd1b120d80c319d9dd4a Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Thu, 20 Nov 2025 15:47:17 +0100 Subject: [PATCH 40/47] test with higherlevel function to suppress reported leaks --- .github/asan_suppress.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/asan_suppress.txt b/.github/asan_suppress.txt index 2abe1f6e3..3adb3b187 100644 --- a/.github/asan_suppress.txt +++ b/.github/asan_suppress.txt @@ -3,4 +3,5 @@ leak:bmalloc_allocate_casual leak:reallocate_for_length leak:dbus_message_new_empty_header # false positive : Display opened and terminated still listed as a leak. -leak:bgfx::gl::GlContext::create \ No newline at end of file +# Using a bit broader function because of unexplained reported leaks with isTextureFormatValid +leak:bgfx::rendererCreate \ No newline at end of file From b121c085f2d5dbacf086f21f7c4d740678349cc1 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Thu, 20 Nov 2025 15:53:54 +0100 Subject: [PATCH 41/47] fix union --- Apps/Playground/Android/BabylonNative/build.gradle | 1 - Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Apps/Playground/Android/BabylonNative/build.gradle b/Apps/Playground/Android/BabylonNative/build.gradle index 9082ed1fd..11486d023 100644 --- a/Apps/Playground/Android/BabylonNative/build.gradle +++ b/Apps/Playground/Android/BabylonNative/build.gradle @@ -20,7 +20,6 @@ def unity_build = "false" if (project.hasProperty("UNITY_BUILD")) { unity_build = project.property("UNITY_BUILD") } - def arcore_libpath = "${buildDir}/arcore-native" configurations { natives } diff --git a/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h b/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h index 0535bfb36..6b30cc08e 100644 --- a/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h +++ b/Polyfills/Canvas/Source/nanovg/nanovg_filterstack.h @@ -68,9 +68,9 @@ class nanovg_filterstack }; struct StackElement { + StackElementTypes type; union { - StackElementTypes type; SepiaElement sepiaElement; Contrast contrastElement; Blur blurElement; From 60ff4409b38e9064013e9ddddfe97a9f9c0b50ae Mon Sep 17 00:00:00 2001 From: Cedric Guillemet Date: Thu, 20 Nov 2025 16:26:43 +0100 Subject: [PATCH 42/47] try to suppress lib jsc from reported leaks --- .github/asan_suppress.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/asan_suppress.txt b/.github/asan_suppress.txt index 3adb3b187..66a43f0a5 100644 --- a/.github/asan_suppress.txt +++ b/.github/asan_suppress.txt @@ -4,4 +4,5 @@ leak:reallocate_for_length leak:dbus_message_new_empty_header # false positive : Display opened and terminated still listed as a leak. # Using a bit broader function because of unexplained reported leaks with isTextureFormatValid -leak:bgfx::rendererCreate \ No newline at end of file +leak:bgfx::rendererCreate +leak:libjavascriptcoregtk-4.1.so From b329df2cb75653dd7e793340684c093cfe5ce585 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet Date: Thu, 20 Nov 2025 17:01:49 +0100 Subject: [PATCH 43/47] suppress libdbus --- .github/asan_suppress.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/asan_suppress.txt b/.github/asan_suppress.txt index 66a43f0a5..2ec0ba7ac 100644 --- a/.github/asan_suppress.txt +++ b/.github/asan_suppress.txt @@ -5,4 +5,4 @@ leak:dbus_message_new_empty_header # false positive : Display opened and terminated still listed as a leak. # Using a bit broader function because of unexplained reported leaks with isTextureFormatValid leak:bgfx::rendererCreate -leak:libjavascriptcoregtk-4.1.so +leak:libdbus-1.so.3 From e497429203ea183637f4e208b9c9cca5d9d5dd24 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Thu, 20 Nov 2025 17:27:42 +0100 Subject: [PATCH 44/47] DBus --- .github/asan_suppress.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/asan_suppress.txt b/.github/asan_suppress.txt index 2ec0ba7ac..40810f721 100644 --- a/.github/asan_suppress.txt +++ b/.github/asan_suppress.txt @@ -5,4 +5,4 @@ leak:dbus_message_new_empty_header # false positive : Display opened and terminated still listed as a leak. # Using a bit broader function because of unexplained reported leaks with isTextureFormatValid leak:bgfx::rendererCreate -leak:libdbus-1.so.3 +leak:DBus From eb9e0d53823e50207cbd63ec5835736a3f6a8e69 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Fri, 21 Nov 2025 09:37:37 +0100 Subject: [PATCH 45/47] almost ready --- .github/asan_suppress.txt | 4 ---- .github/jobs/linux.yml | 11 +++++++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/asan_suppress.txt b/.github/asan_suppress.txt index 40810f721..382b3e9de 100644 --- a/.github/asan_suppress.txt +++ b/.github/asan_suppress.txt @@ -2,7 +2,3 @@ leak:bmalloc_allocate_casual leak:reallocate_for_length leak:dbus_message_new_empty_header -# false positive : Display opened and terminated still listed as a leak. -# Using a bit broader function because of unexplained reported leaks with isTextureFormatValid -leak:bgfx::rendererCreate -leak:DBus diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index 44ba723d6..aa98b832e 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -32,14 +32,21 @@ jobs: ninja -C build displayName: 'Build X11' +# Memory leaks on CI is disabled due to memory leaks reported with xvfb and impossible to add to ignore list. +# See https://github.com/BabylonJS/BabylonNative/issues/1575 + - script: | cd build/Apps/UnitTests - ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./UnitTests + # uncomment next line to enable ASAN memory leak detection on CI + # ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./UnitTests + xvfb-run ./UnitTests displayName: 'Unit Tests' - script: | cd build/Apps/Playground - ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./Playground app:///Scripts/validation_native.js + # uncomment next line to enable ASAN memory leak detection on CI + # ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./Playground app:///Scripts/validation_native.js + xvfb-run ./Playground app:///Scripts/validation_native.js displayName: 'Validation Tests' - task: PublishBuildArtifacts@1 From 260aa88b6583bdb964c91be1d70d8cd87f3abcae Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Fri, 21 Nov 2025 10:13:14 +0100 Subject: [PATCH 46/47] no asan for CI --- .github/asan_suppress.txt | 3 +++ .github/jobs/linux.yml | 7 ------- azure-pipelines.yml | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.github/asan_suppress.txt b/.github/asan_suppress.txt index 382b3e9de..bf0d445f3 100644 --- a/.github/asan_suppress.txt +++ b/.github/asan_suppress.txt @@ -1,4 +1,7 @@ # Suppress leaks from dbus. No direct leak visible with BN. +# command to dump leaks and suppress annecessary : +# ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt ./UnitTests +# ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./Playground app:///Scripts/validation_native.js leak:bmalloc_allocate_casual leak:reallocate_for_length leak:dbus_message_new_empty_header diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index aa98b832e..3be2bcb64 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -32,20 +32,13 @@ jobs: ninja -C build displayName: 'Build X11' -# Memory leaks on CI is disabled due to memory leaks reported with xvfb and impossible to add to ignore list. -# See https://github.com/BabylonJS/BabylonNative/issues/1575 - - script: | cd build/Apps/UnitTests - # uncomment next line to enable ASAN memory leak detection on CI - # ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./UnitTests xvfb-run ./UnitTests displayName: 'Unit Tests' - script: | cd build/Apps/Playground - # uncomment next line to enable ASAN memory leak detection on CI - # ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./Playground app:///Scripts/validation_native.js xvfb-run ./Playground app:///Scripts/validation_native.js displayName: 'Validation Tests' diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5fc29d2cb..448567794 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -124,14 +124,16 @@ jobs: CXX: g++ JSEngine: JavaScriptCore - - template: .github/jobs/linux.yml - parameters: - name: Ubuntu_Clang_JavaScriptCore_Sanitizers - vmImage: 'ubuntu-latest' - CC: clang - CXX: clang++ - JSEngine: JavaScriptCore - enableSanitizers: true +# Memory leaks on CI is disabled due to memory leaks reported with xvfb and impossible to add to ignore list. +# See https://github.com/BabylonJS/BabylonNative/issues/1575 +# - template: .github/jobs/linux.yml +# parameters: +# name: Ubuntu_Clang_JavaScriptCore_Sanitizers +# vmImage: 'ubuntu-latest' +# CC: clang +# CXX: clang++ +# JSEngine: JavaScriptCore +# enableSanitizers: true # Android - template: .github/jobs/android.yml From f5e5002db9a64dd1827caee59f5958223ece1ae0 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Fri, 21 Nov 2025 10:18:35 +0100 Subject: [PATCH 47/47] command line doc --- .github/jobs/linux.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index 3be2bcb64..484210c36 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -32,6 +32,9 @@ jobs: ninja -C build displayName: 'Build X11' +# Memory leaks on CI is disabled due to memory leaks reported with xvfb and impossible to add to ignore list. +# See https://github.com/BabylonJS/BabylonNative/issues/1575 + - script: | cd build/Apps/UnitTests xvfb-run ./UnitTests @@ -39,6 +42,8 @@ jobs: - script: | cd build/Apps/Playground + # Command line to suppress false positive memory leaks : + # ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=../../../.github/asan_suppress.txt xvfb-run ./Playground app:///Scripts/validation_native.js xvfb-run ./Playground app:///Scripts/validation_native.js displayName: 'Validation Tests'