Skip to content

Commit c7f1835

Browse files
committed
fix(canvas): v8 objects leak, view scaling
1 parent 473d452 commit c7f1835

79 files changed

Lines changed: 5980 additions & 5648 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.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,22 @@ pub extern "system" fn nativeReleaseWebGLNormal(_env: JNIEnv, _: JClass, context
482482
let _ = unsafe { Box::from_raw(context) };
483483
}
484484

485+
#[no_mangle]
486+
pub extern "system" fn nativeRelease2DContext(context: jlong) {
487+
if context == 0 {
488+
return;
489+
}
490+
canvas_c::canvas_native_context_release(context as *mut canvas_c::CanvasRenderingContext2D);
491+
}
492+
493+
#[no_mangle]
494+
pub extern "system" fn nativeRelease2DContextNormal(_env: JNIEnv, _: JClass, context: jlong) {
495+
if context == 0 {
496+
return;
497+
}
498+
canvas_c::canvas_native_context_release(context as *mut canvas_c::CanvasRenderingContext2D);
499+
}
500+
485501
#[no_mangle]
486502
pub extern "system" fn nativeMakeWebGLCurrent(gl_context: jlong) -> jboolean {
487503
if gl_context == 0 {

crates/canvas-android/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use log::LevelFilter;
1818
// #[cfg(feature = "vulkan")]
1919
use crate::jni_compat::org_nativescript_canvas_NSCCanvas::{nativeCreate2dContextVulkan, nativeGetVulkanVersion, nativeContext2DSetRenderFunc, nativeContext2DClearRenderFunc};
2020

21-
use crate::jni_compat::org_nativescript_canvas_NSCCanvas::{nativeContext2DPathTest, nativeContext2DPathTestNormal, nativeContext2DRender, nativeContext2DTest, nativeContext2DTestNormal, nativeCreate2DContext, nativeCustomWithBitmapFlush, nativeInitWebGL, nativeInitWebGLNoSurface, nativeInitWebGPU, nativeMakeWebGLCurrent, nativeMakeWebGLCurrentNormal, nativeReleaseWebGL, nativeReleaseWebGLNormal, nativeResizeWebGPU, nativeUpdate2DSurface, nativeUpdate2DSurfaceNoSurface, nativeUpdate2DSurfaceNoSurfaceNormal, nativeUpdateGLNoSurface, nativeUpdateWebGLNoSurfaceNormal, nativeUpdateWebGLSurface, nativeWebGLC2DRender, nativeWriteCurrentWebGLContextToBitmap, nativeContext2DConicTest};
21+
use crate::jni_compat::org_nativescript_canvas_NSCCanvas::{nativeContext2DPathTest, nativeContext2DPathTestNormal, nativeContext2DRender, nativeContext2DTest, nativeContext2DTestNormal, nativeCreate2DContext, nativeCustomWithBitmapFlush, nativeInitWebGL, nativeInitWebGLNoSurface, nativeInitWebGPU, nativeMakeWebGLCurrent, nativeMakeWebGLCurrentNormal, nativeRelease2DContext, nativeRelease2DContextNormal, nativeReleaseWebGL, nativeReleaseWebGLNormal, nativeResizeWebGPU, nativeUpdate2DSurface, nativeUpdate2DSurfaceNoSurface, nativeUpdate2DSurfaceNoSurfaceNormal, nativeUpdateGLNoSurface, nativeUpdateWebGLNoSurfaceNormal, nativeUpdateWebGLSurface, nativeWebGLC2DRender, nativeWriteCurrentWebGLContextToBitmap, nativeContext2DConicTest};
2222
use crate::jni_compat::org_nativescript_canvas_NSCCanvasRenderingContext2D::{nativeCreatePattern, nativeDrawAtlasWithBitmap, nativeDrawImageDxDyDwDhWithAsset, nativeDrawImageDxDyDwDhWithBitmap, nativeDrawImageDxDyWithAsset, nativeDrawImageDxDyWithBitmap, nativeDrawImageWithAsset, nativeDrawImageWithBitmap, nativeScale};
2323
use crate::jni_compat::org_nativescript_canvas_NSCImageAsset::{nativeCreateImageAsset, nativeDestroyImageAsset, nativeGetDimensions, nativeGetError, nativeLoadFromBitmap, nativeLoadFromBuffer, nativeLoadFromBytes, nativeLoadFromEncodedBuffer, nativeLoadFromEncodedBytes, nativeLoadFromPath, nativeLoadFromUrl};
2424
use crate::jni_compat::org_nativescript_canvas_NSCImageBitmap::{nativeLoadBitmapFromBuffer, nativeLoadBitmapFromBufferOptions, nativeLoadBitmapFromBufferRectOptions, nativeLoadBitmapFromBytes, nativeLoadBitmapFromBytesOptions, nativeLoadBitmapFromBytesRectOptions};
@@ -83,6 +83,7 @@ pub extern "system" fn JNI_OnLoad(vm: JavaVM, _reserved: *const c_void) -> jint
8383
"nativeUpdate2DSurfaceNoSurface",
8484
"nativeUpdateWebGLNoSurface",
8585
"nativeReleaseWebGL",
86+
"nativeRelease2DContext",
8687
"nativeMakeWebGLCurrent",
8788
"nativeWriteCurrentWebGLContextToBitmap",
8889
"nativeInitContextWithCustomSurface",
@@ -114,6 +115,7 @@ pub extern "system" fn JNI_OnLoad(vm: JavaVM, _reserved: *const c_void) -> jint
114115
"(IIJ)V",
115116
"(IIJ)V",
116117
"(J)V",
118+
"(J)V",
117119
"(J)Z",
118120
"(JLandroid/graphics/Bitmap;)V",
119121
"(IIFZIFII)J",
@@ -147,6 +149,7 @@ pub extern "system" fn JNI_OnLoad(vm: JavaVM, _reserved: *const c_void) -> jint
147149
"!(IIJ)V",
148150
"!(IIJ)V",
149151
"!(J)V",
152+
"!(J)V",
150153
"!(J)Z",
151154
"!(JLandroid/graphics/Bitmap;)V",
152155
"!(IIFZIFII)J",
@@ -183,6 +186,7 @@ pub extern "system" fn JNI_OnLoad(vm: JavaVM, _reserved: *const c_void) -> jint
183186
nativeUpdate2DSurfaceNoSurface as *mut c_void,
184187
nativeUpdateGLNoSurface as *mut c_void,
185188
nativeReleaseWebGL as *mut c_void,
189+
nativeRelease2DContext as *mut c_void,
186190
nativeMakeWebGLCurrent as *mut c_void,
187191
nativeWriteCurrentWebGLContextToBitmap as *mut c_void,
188192
nativeInitContextWithCustomSurface as *mut c_void,
@@ -206,6 +210,7 @@ pub extern "system" fn JNI_OnLoad(vm: JavaVM, _reserved: *const c_void) -> jint
206210
nativeUpdate2DSurfaceNoSurfaceNormal as *mut c_void,
207211
nativeUpdateWebGLNoSurfaceNormal as *mut c_void,
208212
nativeReleaseWebGLNormal as *mut c_void,
213+
nativeRelease2DContextNormal as *mut c_void,
209214
nativeMakeWebGLCurrentNormal as *mut c_void,
210215
nativeWriteCurrentWebGLContextToBitmap as *mut c_void,
211216
nativeInitContextWithCustomSurfaceNormal as *mut c_void,

crates/canvas-c/src/c2d/context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ pub extern "C" fn canvas_native_raf_release(value: *mut crate::Raf) {
311311
if value.is_null() {
312312
return;
313313
}
314-
canvas_native_raf_stop_and_clear(value, 100);
314+
let raf = unsafe { &*value };
315+
raf.0.stop();
316+
raf.0.clear_callback();
315317
unsafe {
316318
drop(Box::from_raw(value));
317319
}

crates/canvas-ios/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ pub extern "C" fn canvas_native_ios_release_webgl(context: i64) {
200200
let _ = unsafe { Box::from_raw(context) };
201201
}
202202

203+
#[no_mangle]
204+
pub extern "C" fn canvas_native_ios_release_2d_context(context: i64) {
205+
if context == 0 {
206+
return;
207+
}
208+
let context = context as *mut CanvasRenderingContext2D;
209+
let _ = unsafe { Box::from_raw(context) };
210+
}
211+
203212
#[no_mangle]
204213
pub extern "C" fn canvas_native_ios_gl_make_current(context: i64) {
205214
if context == 0 {

packages/canvas-babylon/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/canvas-babylon",
3-
"version": "2.0.29",
3+
"version": "2.0.30",
44
"description": "",
55
"main": "index",
66
"typings": "index.d.ts",

packages/canvas-chartjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/canvas-chartjs",
3-
"version": "2.0.17",
3+
"version": "2.0.18",
44
"description": "ChartJS",
55
"main": "index",
66
"typings": "index.d.ts",

packages/canvas-media/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/canvas-media",
3-
"version": "2.0.29",
3+
"version": "2.0.30",
44
"description": "Canvas media",
55
"main": "index",
66
"typings": "index.d.ts",

packages/canvas-phaser-ce/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/canvas-phaser-ce",
3-
"version": "2.0.29",
3+
"version": "2.0.30",
44
"description": "Tools for using Phaser-ce to build native 2D games in NativeScript 👾",
55
"main": "index",
66
"typings": "index.d.ts",

packages/canvas-phaser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/canvas-phaser",
3-
"version": "2.0.29",
3+
"version": "2.0.30",
44
"description": "Build awesome 2D games with Phaser.js and NativeScript",
55
"main": "index",
66
"typings": "index.d.ts",

packages/canvas-pixi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/canvas-pixi",
3-
"version": "2.0.29",
3+
"version": "2.0.30",
44
"description": "Plugin for using pixi.js in NativeScript",
55
"main": "index",
66
"typings": "index.d.ts",

0 commit comments

Comments
 (0)