[Webkit-unassigned] [Bug 259676] safari throw error "Unable to get image data from canvas. Requested size was 640 x 480"

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Sep 6 15:00:02 PDT 2023


https://bugs.webkit.org/show_bug.cgi?id=259676

Said Abou-Hallawa <sabouhallawa at apple.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sabouhallawa at apple.com

--- Comment #4 from Said Abou-Hallawa <sabouhallawa at apple.com> ---
I think your web page is causing WebKit to reach the memory limit on your device. If you are calling getImageData() very often without getting rid of the existing ones, this will cause this error to be thrown.

CanvasRenderingContext2DBase::getImageData() tries to avoid terminating the MobileSafari by not blindly allocates whatever you are asking for. It tries to allocate the ImageData if it can. If it can't it will return a nil ImageData.

This block of code in this function throws the error you see in your page:

    if (!is<ByteArrayPixelBuffer>(pixelBuffer)) {
        canvasBase().scriptExecutionContext()->addConsoleMessage(MessageSource::Rendering, MessageLevel::Error,
            makeString("Unable to get image data from canvas. Requested size was ", imageDataRect.width(), " x ", imageDataRect.height()));
        return Exception { InvalidStateError };
    }

An ImageData with size 640 x 480 requires 640 x 480 x 4 = 1.23MB which is not big unless your page calls getImageData() for every frame in the video.

The general rule is do not call getImageData() unless you really need it. And if you do, get rid of it as soon as you can. 

But remember JavaScript does not release the unreferenced objects immediately. There is no way to trigger JS garbage collector pragmatically and there is no way also to know when it is going to be triggered.

I am almost sure the garbage collector can't be triggered after drawing every frame from the video.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20230906/321081c7/attachment.htm>


More information about the webkit-unassigned mailing list