Skip to content

Backends: Metal: use a dedicated bufferCacheLock to avoid crash#9367

Closed
andygrundman wants to merge 1 commit into
ocornut:masterfrom
andygrundman:andyg.metal-bufferCacheLock
Closed

Backends: Metal: use a dedicated bufferCacheLock to avoid crash#9367
andygrundman wants to merge 1 commit into
ocornut:masterfrom
andygrundman:andyg.metal-bufferCacheLock

Conversation

@andygrundman
Copy link
Copy Markdown
Contributor

I ran into a crash that was caused by using bufferCache for @synchronized() at the same time as it's replaced by a new object via self.bufferCache = [survivors mutableCopy]; The crash showed up as Collection <__NSArrayM: 0x8c0fd14d0> was mutated while being enumerated.

I also removed the dispatch onto main when adding the finished buffers back into the cache. This operation should be fine to run on any thread as long as it's inside the sync block. I also fixed the data type of double now = GetMachAbsoluteTimeInSeconds(); The uint64_t was fine since it only checks once a second, but this felt better since every other time variable is a double/CFTimeInterval.

…en bufferCache is replaced by a new object while being used for @synchronize().

This also removes the dispatch onto main when adding the finished buffers back into the cache. This operation should be fine to run on any thread as long as it's inside the sync block.
ocornut pushed a commit that referenced this pull request Apr 14, 2026
…en bufferCache is replaced by a new object while being used for synchronize(). (#9367)

This also removes the dispatch onto main when adding the finished buffers back into the cache. This operation should be fine to run on any thread as long as it's inside the sync block.
@ocornut
Copy link
Copy Markdown
Owner

ocornut commented Apr 14, 2026

I'll be dishonest pretending I understand half of what you said and your changes, since I don't know ObjC properly.
So as with many OSX related code I'm merging this blindly based on your explanation and profile. Thank you!

@ocornut ocornut closed this Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants