Skip to content

Creating a smaller buffer for PolygonSelector when selection changes significantly? #955

Closed

Description

@kushalkolar

I was taking a look at how the new mesh positions and indices buffers are set in the polygon selector, a new buffer is allocated if a larger one is required for the new selection. But if the selection is smaller, than a new buffer is not allocated. @almarklein just curious about the reason so I can understand it better. I'm working on the PolygonGraphic.

# Need larger buffer?
if len(value) > geometry.positions.nitems:
arr = np.zeros((geometry.positions.nitems * 2, 3), np.float32)
geometry.positions = gfx.Buffer(arr)
if len(indices) > geometry.indices.nitems:
arr = np.zeros((geometry.indices.nitems * 2, 3), np.int32)
geometry.indices = gfx.Buffer(arr)
geometry.positions.data[: len(value)] = value
geometry.positions.data[len(value) :] = value[-1] if len(value) else (0, 0, 0)
geometry.positions.draw_range = 0, len(value)
geometry.positions.update_full()
geometry.indices.data[: len(indices)] = indices
geometry.indices.data[len(indices) :] = 0
geometry.indices.draw_range = 0, len(indices)
geometry.indices.update_full()

Activity

  1. almarklein commented on Dec 1, 2025

    @almarklein
    Collaborator

    Mmm, that code could indeed be improved. It also fails if the new value is more than twice as large as previous.
    I can make a pr to improve this, so we can use that in the polygongraphic too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions