[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 20:28:20 PDT 2023


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

--- Comment #6 from fishel.feng at zoom.us ---
(In reply to Said Abou-Hallawa from comment #4)
> 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.

Thank you for the reply. In our business, I must use getImageData to capture video frames, so it is unavoidable to use this API. I also noticed this issue is related to some memory not being released, but I'm not sure where exactly the problem is.

As you mentioned, I need to get rid of existing ImageData objects immediately. I want to confirm whether this refers to releasing references to the ImageData objects that have been acquired, or releasing resources of the canvas element itself.

I tried some release logic previously but it didn't work. This should be an issue in my code. I just want to confirm what call I should use to ensure the resource release logic is correct.

-- 
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/20230907/96d28b43/attachment.htm>


More information about the webkit-unassigned mailing list