Skip to content

alt.TextLabel.all keeps destroyed labels as null #2439

@MosIbOad

Description

@MosIbOad

Description of the problem

Description:
When a TextLabel is created and later destroyed using .destroy(), the label is not fully removed from memory. Instead, it remains in the alt.TextLabel.all array as null.

This causes errors when using simple filters like:

const labels = alt.TextLabel.all.filter(x => x.hasMeta('myCustomLabel'));

Resulting in the following runtime error:

TypeError: Cannot read properties of null (reading 'hasMeta')

To avoid the error, I must manually check if the entry is not null:

const labels = alt.TextLabel.all.filter(x => x && x.hasMeta('myCustomLabel'));

Reproduction steps

1- Create a TextLabel.
2- Use .setMeta('myCustomLabel', true) on it.
3- Destroy it via .destroy().
4 - Attempt to filter all labels using alt.TextLabel.all.filter(x => x.hasMeta('myCustomLabel')).
5- Observe the error due to null entry.

Sample code:

function createLabel() {
    const labels = alt.TextLabel.all.filter(x => x.hasMeta('myCustomLabel')); // This throws if a destroyed label is in the list
    labels.forEach((x) => {
        if (x.hasMeta('myCustomLabel')) x.destroy();
    });

    const label = new alt.TextLabel('Welcome to alt:V v16', 'Arial', 32, 2, new alt.Vector3(-4.75, 2.497, 71.217), new alt.Vector3(0, 0, -0.253), new alt.RGBA(255, 255, 255, 255), 0.25, new alt.RGBA(0, 0, 0, 80));
    label.setMeta('myCustomLabel', true);

    setTimeout(() => {
        label.destroy(); // Still remains in .all as null
    }, 2500);
}

createLabel();

Expected behaviour

After calling .destroy() on a TextLabel, it should be completely removed from alt.TextLabel.all. This would ensure safe iteration or filtering without needing to check for nulls.

Additional context

No response

Operating system

Ubuntu 24.04

Version

16.4.13 (release)

Crashdump ID

No response

Confirmation of issue's presence

  • By submitting this ticket, I affirm that I have verified the presence of this issue on the latest RC (Release Candidate) version available at the time of writing this ticket.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Class: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions