mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-19 09:17:38 +03:00
PixelPaint: Fix BucketTool out of memory crashes
The BFS implementation for BucketTool's flood-fill had sitations which could result in infinite loop, causing OOM crashes due to the queue growing unbounded. The way to fix this is to keep track of the pixels we have already visited in the flood-fill algorithm and ignore those if we ever encounter them again. This also fixes the crashing issue from #9003. We still need a better way to account for transparency, but that is beyond the scope of this commit, and this issue still exists without any transparent pixels.
This commit is contained in:
parent
522f0841fd
commit
3bf204fd03
Notes:
sideshowbarker
2024-07-18 04:23:21 +09:00
Author: https://github.com/mustafaquraish Commit: https://github.com/SerenityOS/serenity/commit/3bf204fd030 Pull-request: https://github.com/SerenityOS/serenity/pull/9830 Reviewed-by: https://github.com/linusg
@ -7,6 +7,7 @@
|
||||
#include "BucketTool.h"
|
||||
#include "ImageEditor.h"
|
||||
#include "Layer.h"
|
||||
#include <AK/HashTable.h>
|
||||
#include <AK/Queue.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/Label.h>
|
||||
@ -47,8 +48,12 @@ static void flood_fill(Gfx::Bitmap& bitmap, Gfx::IntPoint const& start_position,
|
||||
|
||||
Queue<Gfx::IntPoint> queue;
|
||||
queue.enqueue(start_position);
|
||||
HashTable<Gfx::IntPoint> visited;
|
||||
while (!queue.is_empty()) {
|
||||
auto position = queue.dequeue();
|
||||
if (visited.contains(position))
|
||||
continue;
|
||||
visited.set(position);
|
||||
|
||||
auto pixel_color = bitmap.get_pixel<Gfx::StorageFormat::BGRA8888>(position.x(), position.y());
|
||||
if (color_distance_squared(pixel_color, target_color) > threshold_normalized_squared)
|
||||
|
Loading…
Reference in New Issue
Block a user