Skip to content

Commit f58d704

Browse files
committed
chore: 2.0.28
1 parent 50ee7ff commit f58d704

47 files changed

Lines changed: 894 additions & 777 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/demo/src/plugin-demos/audio-context.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:canvas="@nativescript/canvas" navigatingTo="navigatingTo" class="page audio-page">
1+
<Page enableSwipeBackNavigation="false" xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:canvas="@nativescript/canvas" navigatingTo="navigatingTo" class="page audio-page">
22
<Page.actionBar>
33
<ActionBar title="Audio — WebAudio Demo" class="action-bar" />
44
</Page.actionBar>
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Observable, EventData, Page } from '@nativescript/core';
1+
import { Observable, EventData, Page, Device } from '@nativescript/core';
22
import { DemoSharedCanvasThree } from '@demo/shared';
33
import {} from '@nativescript/canvas-three';
44

@@ -7,4 +7,12 @@ export function navigatingTo(args: EventData) {
77
page.bindingContext = new DemoModel();
88
}
99

10+
export function pageLoaded(args) {
11+
if (__IOS__) {
12+
if (parseFloat(Device.osVersion) >= 26.0) {
13+
args.object.viewController.navigationController.interactiveContentPopGestureRecognizer.enabled = false;
14+
}
15+
}
16+
}
17+
1018
export class DemoModel extends DemoSharedCanvasThree {}

apps/demo/src/plugin-demos/canvas-three.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Page xmlns:canvas="@nativescript/canvas" xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo"
1+
<Page enableSwipeBackNavigation="false" loaded="pageLoaded" xmlns:canvas="@nativescript/canvas" xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo"
22
class="page">
33
<Page.actionBar>
44
<ActionBar title="Canvas Three WebGPU" class="bg-black text-white" >

apps/demo/src/plugin-demos/canvas.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EventData, ImageSource, Page, Screen, View, WebView } from '@nativescript/core';
1+
import { Device, EventData, ImageSource, Page, Screen, View, WebView } from '@nativescript/core';
22
import { DemoSharedCanvas } from '@demo/shared';
33
import { ImageAsset } from '@nativescript/canvas';
44
import { Dom, Group, Rect, drawAsImage } from '@nativescript/canvas/Dom';
@@ -8,6 +8,14 @@ export function navigatingTo(args: EventData) {
88
page.bindingContext = new DemoModel();
99
}
1010

11+
export function pageLoaded(args) {
12+
if (__IOS__) {
13+
if (parseFloat(Device.osVersion) >= 26.0) {
14+
args.object.viewController.navigationController.interactiveContentPopGestureRecognizer.enabled = false;
15+
}
16+
}
17+
}
18+
1119
export function loaded(args) {
1220
const view = <WebView>args.object;
1321
view.src = `

apps/demo/src/plugin-demos/canvas.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Page xmlns:canvas="@nativescript/canvas" xmlns:ui="@nativescript/canvas/dom/index" xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">
1+
<Page loaded="pageLoaded" enableSwipeBackNavigation="false" xmlns:canvas="@nativescript/canvas" xmlns:ui="@nativescript/canvas/dom/index" xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">
22
<Page.actionBar>
33
<ActionBar title="Canvas 2.0" icon="" class="action-bar">
44
</ActionBar>

crates/canvas-android/src/jni_compat/org_nativescript_canvas_NSCCanvas.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,20 @@ pub extern "system" fn nativeInitWebGPU(
6464
width: jint,
6565
height: jint,
6666
) -> jlong {
67+
if instance == 0 || width <= 0 || height <= 0 {
68+
return 0;
69+
}
70+
6771
unsafe {
6872
let interface = env.get_native_interface();
6973
if let Some(window) = NativeWindow::from_surface(interface, surface) {
70-
let ptr = window.ptr().as_ptr();
74+
let Some(ptr) = NonNull::new(window.ptr().as_ptr() as *mut c_void) else {
75+
return 0;
76+
};
7177
let instance: *mut CanvasWebGPUInstance = instance as _;
7278
let ret = canvas_c::webgpu::gpu_canvas_context::canvas_native_webgpu_context_create(
7379
instance,
74-
ptr as *mut c_void,
80+
ptr.as_ptr(),
7581
width as u32,
7682
height as u32,
7783
);
@@ -91,16 +97,22 @@ pub extern "system" fn nativeResizeWebGPU(
9197
width: jint,
9298
height: jint,
9399
) {
100+
if context == 0 || width <= 0 || height <= 0 {
101+
return;
102+
}
103+
94104
unsafe {
95105
let interface = env.get_native_interface();
96106
if let Some(window) = NativeWindow::from_surface(interface, surface) {
97-
let ptr = window.ptr().as_ptr();
107+
let Some(ptr) = NonNull::new(window.ptr().as_ptr() as *mut c_void) else {
108+
return;
109+
};
98110
let context: *mut canvas_c::webgpu::gpu_canvas_context::CanvasGPUCanvasContext =
99111
context as _;
100112
#[cfg(any(target_os = "android"))]
101113
canvas_c::webgpu::gpu_canvas_context::canvas_native_webgpu_context_resize(
102114
context,
103-
ptr as *mut c_void,
115+
ptr.as_ptr(),
104116
width as u32,
105117
height as u32,
106118
);
@@ -170,6 +182,9 @@ pub extern "system" fn nativeInitWebGL(
170182
unsafe {
171183
let interface = env.get_native_interface();
172184
if let Some(window) = NativeWindow::from_surface(interface, surface) {
185+
if window.width() <= 0 || window.height() <= 0 {
186+
return 0;
187+
}
173188
if version == 2 && !GLContext::has_gl2support() {
174189
return 0;
175190
}
@@ -226,6 +241,9 @@ pub extern "system" fn nativeInitWebGLNoSurface(
226241
return 0;
227242
}
228243

244+
let width = width.max(1);
245+
let height = height.max(1);
246+
229247
if let Ok(power_preference) = PowerPreference::try_from(power_preference) {
230248
let context = canvas_c::canvas_native_webgl_create_no_window(
231249
width,
@@ -718,8 +736,9 @@ pub extern "system" fn nativeCustomWithBitmapFlush(
718736
let context = context as *mut canvas_c::CanvasRenderingContext2D;
719737
let context = unsafe { &mut *context };
720738

721-
let mut surface =
722-
skia_safe::surfaces::wrap_pixels(&info, image_data, None, None).unwrap();
739+
let Some(mut surface) = skia_safe::surfaces::wrap_pixels(&info, image_data, None, None) else {
740+
return;
741+
};
723742
let canvas = surface.canvas();
724743
let mut paint = skia_safe::Paint::default();
725744
paint.set_anti_alias(true);

crates/canvas-c/src/webgpu/gpu_canvas_context.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ pub unsafe extern "C" fn canvas_native_webgpu_context_create(
424424
width: u32,
425425
height: u32,
426426
) -> *const CanvasGPUCanvasContext {
427-
if instance.is_null() {
427+
if instance.is_null() || window.is_null() || width == 0 || height == 0 {
428428
return std::ptr::null_mut();
429429
}
430430

@@ -434,8 +434,11 @@ pub unsafe extern "C" fn canvas_native_webgpu_context_create(
434434

435435
let display_handle = RawDisplayHandle::Android(raw_window_handle::AndroidDisplayHandle::new());
436436

437-
let handle =
438-
raw_window_handle::AndroidNdkWindowHandle::new(std::ptr::NonNull::new_unchecked(window));
437+
let Some(window_handle_ptr) = std::ptr::NonNull::new(window) else {
438+
return std::ptr::null_mut();
439+
};
440+
441+
let handle = raw_window_handle::AndroidNdkWindowHandle::new(window_handle_ptr);
439442
let window_handle = RawWindowHandle::AndroidNdk(handle);
440443

441444
match global.instance_create_surface(Some(display_handle), window_handle, None) {
@@ -467,7 +470,7 @@ pub unsafe extern "C" fn canvas_native_webgpu_context_resize(
467470
width: u32,
468471
height: u32,
469472
) {
470-
if context.is_null() {
473+
if context.is_null() || window.is_null() || width == 0 || height == 0 {
471474
return;
472475
}
473476

@@ -479,8 +482,11 @@ pub unsafe extern "C" fn canvas_native_webgpu_context_resize(
479482

480483
let display_handle = RawDisplayHandle::Android(raw_window_handle::AndroidDisplayHandle::new());
481484

482-
let handle =
483-
raw_window_handle::AndroidNdkWindowHandle::new(std::ptr::NonNull::new_unchecked(window));
485+
let Some(window_handle_ptr) = std::ptr::NonNull::new(window) else {
486+
return;
487+
};
488+
489+
let handle = raw_window_handle::AndroidNdkWindowHandle::new(window_handle_ptr);
484490
let window_handle = RawWindowHandle::AndroidNdk(handle);
485491

486492
let mut surface = context.surface.lock();

crates/canvas-core/src/gpu/gl/android.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ struct Dimensions {
9090
height: i32,
9191
}
9292

93+
#[inline]
94+
fn non_zero_size(value: i32) -> NonZeroU32 {
95+
let clamped = value.max(1) as u32;
96+
NonZeroU32::new(clamped).expect("clamped dimension must be non-zero")
97+
}
98+
9399
#[derive(Default)]
94100
pub(crate) struct GLContextInner {
95101
surface: Option<SurfaceHelper>,
@@ -366,8 +372,8 @@ impl GLContext {
366372
glutin::surface::SurfaceAttributesBuilder::<WindowSurface>::new()
367373
.build(
368374
window,
369-
NonZeroU32::try_from(width as u32).unwrap(),
370-
NonZeroU32::try_from(height as u32).unwrap(),
375+
non_zero_size(width),
376+
non_zero_size(height),
371377
);
372378

373379
let surface = display
@@ -542,8 +548,8 @@ impl GLContext {
542548
glutin::surface::SurfaceAttributesBuilder::<WindowSurface>::new()
543549
.build(
544550
window,
545-
NonZeroU32::try_from(width as u32).unwrap(),
546-
NonZeroU32::try_from(height as u32).unwrap(),
551+
non_zero_size(width),
552+
non_zero_size(height),
547553
);
548554

549555
let surface = display
@@ -730,8 +736,8 @@ impl GLContext {
730736
glutin::surface::SurfaceAttributesBuilder::<WindowSurface>::new()
731737
.build(
732738
window,
733-
NonZeroU32::try_from(width as u32).unwrap(),
734-
NonZeroU32::try_from(height as u32).unwrap(),
739+
non_zero_size(width),
740+
non_zero_size(height),
735741
);
736742

737743
let surface = display
@@ -790,8 +796,8 @@ impl GLContext {
790796
let cfg = cfg
791797
.with_surface_type(ConfigSurfaceTypes::PBUFFER)
792798
.with_pbuffer_sizes(
793-
(width as u32).try_into().unwrap(),
794-
(height as u32).try_into().unwrap(),
799+
non_zero_size(width),
800+
non_zero_size(height),
795801
)
796802
.build();
797803

@@ -829,8 +835,8 @@ impl GLContext {
829835

830836
let surface_attr =
831837
glutin::surface::SurfaceAttributesBuilder::<PbufferSurface>::new().build(
832-
NonZeroU32::try_from(width as u32).unwrap(),
833-
NonZeroU32::try_from(height as u32).unwrap(),
838+
non_zero_size(width),
839+
non_zero_size(height),
834840
);
835841

836842
let surface = display
@@ -871,8 +877,8 @@ impl GLContext {
871877
let cfg = cfg
872878
.with_surface_type(ConfigSurfaceTypes::PBUFFER)
873879
.with_pbuffer_sizes(
874-
(width as u32).try_into().unwrap(),
875-
(height as u32).try_into().unwrap(),
880+
non_zero_size(width),
881+
non_zero_size(height),
876882
)
877883
.build();
878884

@@ -946,8 +952,8 @@ impl GLContext {
946952
let cfg = cfg
947953
.with_surface_type(ConfigSurfaceTypes::PBUFFER)
948954
.with_pbuffer_sizes(
949-
(width as u32).try_into().unwrap(),
950-
(height as u32).try_into().unwrap(),
955+
non_zero_size(width),
956+
non_zero_size(height),
951957
)
952958
.build();
953959

@@ -988,8 +994,8 @@ impl GLContext {
988994
let surface_attr =
989995
glutin::surface::SurfaceAttributesBuilder::<PbufferSurface>::new()
990996
.build(
991-
NonZeroU32::try_from(width as u32).unwrap(),
992-
NonZeroU32::try_from(height as u32).unwrap(),
997+
non_zero_size(width),
998+
non_zero_size(height),
993999
);
9941000

9951001
let surface = display

packages/audio-context/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/audio-context",
3-
"version": "1.1.7",
3+
"version": "1.1.8",
44
"description": "Web Audio API for NativeScript",
55
"main": "index",
66
"types": "index.d.ts",
56 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)