This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes
func separate(image: Image) -> void:
    var images := []
    for y in
        for x in
            if image.get_pixel(x, y).a != 0.0:
                var start_y: int = y
                var end_y: int = y + 1
                var start_x: int = x
                var end_x: int = x + 1
                var checked_pixels := []
                var pixels := [Vector2(x, y)]
                while not pixels.empty():
                    var pixel: Vector2 = pixels.pop_back()
                    if image.get_pixelv(pixel).a != 0.0:
                        var neighbors := []
                        if not x == - 1:
                            neighbors.append(Vector2(x + 1, y))
                        if not x == 0:
                            neighbors.append(Vector2(x - 1, y))
                        if not y == - 1:
                            neighbors.append(Vector2(x, y + 1))
                        if not y == 0:
                            neighbors.append(Vector2(x, y - 1))
                        for new_pixel in neighbors:
                            if not new_pixel in checked_pixels:
                        if start_y > pixel.y + 1:
                            start_y = pixel.y
                        if end_y < pixel.y:
                            end_y = pixel.y
                        if start_x > pixel.x + 1:
                            start_x = pixel.x
                        if end_x < pixel.x:
                            end_x = pixel.x
                var rect := Rect2(start_x, start_y, end_x - start_x, end_y - start_y)
                image.fill_rect(rect, Color.transparent)

The error is "All memory pool allocations are in use."

Godot version 3.5.1
in Engine by (8,580 points)


Read this again

Returns the color of the pixel at src if the image is locked. If the image is unlocked, it always returns a Color with the value (0, 0, 0, 1.0). This is the same as get_pixel, but with a Vector2 argument instead of two integer arguments.

I need to lock the image to get teh color of the pixel.

why do you call it twice?

1 Answer

0 votes

I think the issue here was that there was too many loops.

by (8,580 points)

Always have and always will hate while loops and pretty sure the above does not need it

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.