all articles

canvas crashes when repeatedly repainted

2015-07-05 @sunderls

android4.2.2 canvas clearRect js


on android 4.2.2, if canvas is repeatedly repainted, which calls clearRect() very often, it may cause the canvas to crash.

This may reproduce if you implement something like a reader, when you mimic dragging the content, which have to call clearRect().


when calling clearRect(), rather than passing the real size of canvas, you should pass bigger size.


in common case, you just call:

clearRect(0, 0, width, height)

but for something like Android4.2.2:

you should do something like:

clearRect(0, 0, width + 1, height + 1);

other links