Skip to content
Draft
7 changes: 5 additions & 2 deletions .github/jobs/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ jobs:
timeoutInMinutes: 45
pool:
vmImage: ${{ parameters.vmImage }}


variables:
SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF') }}

steps:
- template: cmake.yml
parameters:
Expand All @@ -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 }}'
4 changes: 3 additions & 1 deletion .github/jobs/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ parameters:
CC: ''
CXX: ''
JSEngine: ''
Sanitizers: false

jobs:
- job: ${{ parameters.name }}
Expand All @@ -12,6 +13,7 @@ jobs:
vmImage: ${{ parameters.vmImage }}

variables:
SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF') }}
CC: ${{ parameters.CC }}
CXX: ${{ parameters.CXX }}

Expand All @@ -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'

Expand Down
7 changes: 5 additions & 2 deletions .github/jobs/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ jobs:
timeoutInMinutes: 30
pool:
vmImage: ${{ parameters.vmImage }}


variables:
SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.Sanitizers), 'True', 'ON'), 'OFF') }}

steps:
- template: cmake.yml
parameters:
Expand All @@ -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: |
Expand Down
7 changes: 7 additions & 0 deletions Apps/Playground/Android/BabylonNative/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ 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)

Expand Down
7 changes: 6 additions & 1 deletion Apps/Playground/Android/BabylonNative/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion Apps/UnitTests/Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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}"
)
}
}
Expand Down
7 changes: 7 additions & 0 deletions Apps/UnitTests/Android/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ 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)
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})
else()
message(WARNING "Sanitizers not supported on this compiler.")
endif()
endif()

# --------------------------------------------------

if(ANDROID)
Expand Down
17 changes: 9 additions & 8 deletions Polyfills/Canvas/Source/Gradient.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <bgfx/bgfx.h>
#include <map>
#include <cmath>
#include "Canvas.h"
#include "Context.h"
#include "Gradient.h"
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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::sqrt((rn * rn) * (dx * dx + dy * dy) - (df * df));
float g = numerator / denominator;

// color = c0 + (c1 - c0)(g - x0)/(x1 - x0)
Expand Down Expand Up @@ -282,12 +283,12 @@ namespace Babylon::Polyfills::Internal
}
else
{
int w = (int)fabsf(g);
int w = (int)std::fabs(g);
if (spreadMode == SPREAD_REPEAT)
{
if (g < 0)
{
g = 1 - (fabs(g) - w);
g = 1 - (std::fabs(g) - w);
}
else
{
Expand All @@ -300,11 +301,11 @@ namespace Babylon::Polyfills::Internal
{
if (w % 2 == 0)
{ // even
g = (fabsf(g) - w);
g = (std::fabs(g) - w);
}
else
{ // odd
g = (1 - (fabsf(g) - w));
g = (1 - (std::fabs(g) - w));
}
}
else
Expand Down
22 changes: 22 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ jobs:
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
Expand Down Expand Up @@ -102,6 +108,15 @@ 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
Sanitizers: true

# Android
- template: .github/jobs/android.yml
parameters:
Expand All @@ -127,6 +142,13 @@ jobs:
vmImage: 'macOS-latest'
JSEngine: V8

- template: .github/jobs/android.yml
parameters:
name: Android_MacOS_V8_Sanitizers
vmImage: 'macOS-latest'
JSEngine: V8
Sanitizers: true

# Installation tests.
- template: .github/jobs/test_install_win32.yml
parameters:
Expand Down
Loading