mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 09:09:43 +00:00
LibWeb: Null-check surface before allocating painter for context2d
Fixes https://github.com/LadybirdBrowser/ladybird/issues/2755
This commit is contained in:
parent
1081a7f3e2
commit
72f093ba9f
Notes:
github-actions[bot]
2024-12-04 15:59:49 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 72f093ba9f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2758
Reviewed-by: https://github.com/gmta ✅
3 changed files with 17 additions and 3 deletions
|
@ -199,8 +199,9 @@ void CanvasRenderingContext2D::did_draw(Gfx::FloatRect const&)
|
||||||
|
|
||||||
Gfx::Painter* CanvasRenderingContext2D::painter()
|
Gfx::Painter* CanvasRenderingContext2D::painter()
|
||||||
{
|
{
|
||||||
if (!canvas_element().surface()) {
|
allocate_painting_surface_if_needed();
|
||||||
allocate_painting_surface_if_needed();
|
auto surface = canvas_element().surface();
|
||||||
|
if (!m_painter && surface) {
|
||||||
canvas_element().document().invalidate_display_list();
|
canvas_element().document().invalidate_display_list();
|
||||||
m_painter = make<Gfx::PainterSkia>(*canvas_element().surface());
|
m_painter = make<Gfx::PainterSkia>(*canvas_element().surface());
|
||||||
}
|
}
|
||||||
|
@ -217,7 +218,7 @@ void CanvasRenderingContext2D::set_size(Gfx::IntSize const& size)
|
||||||
|
|
||||||
void CanvasRenderingContext2D::allocate_painting_surface_if_needed()
|
void CanvasRenderingContext2D::allocate_painting_surface_if_needed()
|
||||||
{
|
{
|
||||||
if (m_surface)
|
if (m_surface || m_size.is_empty())
|
||||||
return;
|
return;
|
||||||
auto skia_backend_context = canvas_element().navigable()->traversable_navigable()->skia_backend_context();
|
auto skia_backend_context = canvas_element().navigable()->traversable_navigable()->skia_backend_context();
|
||||||
m_surface = Gfx::PaintingSurface::create_with_size(skia_backend_context, canvas_element().bitmap_size_for_canvas(), Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied);
|
m_surface = Gfx::PaintingSurface::create_with_size(skia_backend_context, canvas_element().bitmap_size_for_canvas(), Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied);
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
PASS (didn't crash!)
|
|
@ -0,0 +1,12 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<canvas id="myCanvas" width="0" height="0"></canvas>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
const canvas = document.getElementById('myCanvas');
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
ctx.fillStyle = 'red';
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
println("PASS (didn't crash!)");
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue