Metal: Fix race condition in ghost context destruction routines
Found when running with ASAN on through Xcode. Crashed on exit. Multiple threads can release their own context at the same time and thus release the `metal_layer_` multiple times, resulting in use after free. Pull Request: https://projects.blender.org/blender/blender/pulls/147972
This commit is contained in:
committed by
Clément Foucault
parent
633102c219
commit
909b682547
@@ -21,6 +21,7 @@
|
|||||||
#import <QuartzCore/QuartzCore.h>
|
#import <QuartzCore/QuartzCore.h>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <mutex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
static const MTLPixelFormat METAL_FRAMEBUFFERPIXEL_FORMAT_EDR = MTLPixelFormatRGBA16Float;
|
static const MTLPixelFormat METAL_FRAMEBUFFERPIXEL_FORMAT_EDR = MTLPixelFormatRGBA16Float;
|
||||||
@@ -121,6 +122,10 @@ GHOST_ContextMTL::GHOST_ContextMTL(const GHOST_ContextParams &context_params,
|
|||||||
|
|
||||||
GHOST_ContextMTL::~GHOST_ContextMTL()
|
GHOST_ContextMTL::~GHOST_ContextMTL()
|
||||||
{
|
{
|
||||||
|
/* Multiple threads can release their own context at the same time. */
|
||||||
|
static std::mutex mutex;
|
||||||
|
std::scoped_lock lock(mutex);
|
||||||
|
|
||||||
metalFree();
|
metalFree();
|
||||||
|
|
||||||
if (owns_metal_device_) {
|
if (owns_metal_device_) {
|
||||||
|
|||||||
Reference in New Issue
Block a user