CanvasKit `drawOnce` Err: Uncaught RuntimeError: index out of bounds

83 views
Skip to first unread message

Acbox Sky

unread,
Mar 8, 2024, 6:54:44 AM3/8/24
to skia-discuss
I'm making a animation engine and recently I'm trying to use CanvasKit to replace HTML Canvas, but when I use the latest version(v0.39.1) to draw things on canvas, it errs:
Uncaught RuntimeError: index out of bounds
Is this a bug?

Данил Буланов

unread,
Mar 8, 2024, 7:17:47 AM3/8/24
to skia-discuss
From what I can see you have a call of drawOnce(), which is supposed to be used once, beacause it deisposes the surface, but you seem to continue using this surface further.
пятница, 8 марта 2024 г. в 14:54:44 UTC+3, acbo...@gmail.com:

Acbox Sky

unread,
Mar 8, 2024, 7:49:09 AM3/8/24
to skia-discuss
Oh! Thanks! I solved it!

Acbox Sky

unread,
Mar 8, 2024, 10:22:25 AM3/8/24
to skia-discuss
Emm...My solve way is that create a new surface when the last surface is disposed, but it seems it has a big problem that the animation will be very lag, do you have better way to solve this problem?
this is my code related to this problem

car.surface.drawOnce((canvas) => {
canvas.clear(car.canvaskit.BLACK);
for (const object of car.scene.objects) {
object.update(car.paint, canvas, car.canvaskit, car.element);
object.updated(car);
car.surface = car.canvaskit.MakeWebGLCanvasSurface(car.element);
}
});
On Friday 8 March 2024 at 20:17:47 UTC+8 blnv...@gmail.com wrote:

Данил Буланов

unread,
Mar 8, 2024, 10:31:11 AM3/8/24
to skia-discuss
Is there a specific reason why you use drawOnce() here? You can just use requestAnimationFrame(drawFrame: (_: Canvas) => void): number;  which does not dispose the surface, and you can continue using the same surface.

пятница, 8 марта 2024 г. в 18:22:25 UTC+3, acbo...@gmail.com:

Acbox Sky

unread,
Mar 8, 2024, 10:46:07 AM3/8/24
to skia-discuss
I do it as yours, but it gets stuck as same.

Acbox Sky

unread,
Mar 8, 2024, 11:00:44 AM3/8/24
to skia-discuss
In most of case, requestAnimationFrame should get 60 frames per second, but I just get 40 per second. I analyze from backend, discovering that the CPU, GPU and Memory are used by a low level, but it still get slow. How to solve it?

Данил Буланов

unread,
Mar 8, 2024, 11:42:28 AM3/8/24
to skia-discuss
I think you need to remove this code since you do not need to recreate surface
car.surface = car.canvaskit.MakeWebGLCanvasSurface(car.element);
пятница, 8 марта 2024 г. в 19:00:44 UTC+3, acbo...@gmail.com:

Acbox Sky

unread,
Mar 8, 2024, 11:51:46 PM3/8/24
to skia-discuss

Oh! My mistake, Thank you!!!!!!!!!!!!!!!!!!!!!!!!
Reply all
Reply to author
Forward
0 new messages