# gpui_macos: Fix stale atlas key causing crash on None texture lookup \(\#51996\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/34807eb14693e1f40207726ef6bcb1e3ab3b0103)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 34807eb14693e1f40207726ef6bcb1e3ab3b0103

Requested commit: 34807eb14693e1f40207726ef6bcb1e3ab3b0103

Commit: 34807eb14693e1f40207726ef6bcb1e3ab3b0103

Tree: 46f91fb0eca5609c68cfb1441da2e61f551d36f4

Author: Lukas Wirth

Committer: GitHub

## Message

```
gpui_macos: Fix stale atlas key causing crash on None texture lookup (#51996)

MetalAtlas::remove() used tiles_by_key.get(key) to look up the texture
ID but only called tiles_by_key.remove(key) when the texture became
fully unreferenced. When a tile was removed while other tiles remained
on the same texture, the key stayed in tiles_by_key as a stale entry.

Once subsequent removals deleted the texture, get_or_insert_with could
return the stale tile referencing a now-deleted texture slot, causing an
unwrap panic in MetalAtlasState::texture().

Fix: change .get(key) to .remove(key) unconditionally, matching the WGPU
and DirectX atlas implementations which already do this correctly.

Closes ZED-5KV

Release Notes:

- N/A or Added/Fixed/Improved ...
```

## Parents

- [95852d4c716348e0621b6d074d0a6694391cbb77](https://git.cafe/gitcafe/zed/commit/95852d4c716348e0621b6d074d0a6694391cbb77?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/34807eb14693e1f40207726ef6bcb1e3ab3b0103?format=markdown)
