proper delayed release fix for 10.16

This commit is contained in:
Stefan Csomor
2020-06-25 11:20:39 +02:00
parent 5e687861c1
commit c7f6feadfd

View File

@@ -504,6 +504,7 @@ protected:
CGFunctionRef CreateGradientFunction(const wxGraphicsGradientStops& stops);
static void CalculateShadingValues (void *info, const CGFloat *in, CGFloat *out);
static void ReleaseComponents (void *info);
bool m_isShading;
CGFunctionRef m_gradientFunction;
@@ -544,7 +545,7 @@ protected:
GradientComponent *comps;
};
GradientComponents m_gradientComponents;
GradientComponents* m_gradientComponents;
};
@@ -564,6 +565,8 @@ wxMacCoreGraphicsPenBrushDataBase::~wxMacCoreGraphicsPenBrushDataBase()
if ( m_shadingMatrix )
delete m_shadingMatrix;
// an eventual existing m_gradientComponents will be deallocated via the CGFunction callback
}
void
@@ -573,6 +576,7 @@ wxMacCoreGraphicsPenBrushDataBase::Init()
m_shading = NULL;
m_isShading = false;
m_shadingMatrix = NULL;
m_gradientComponents = NULL;
}
void
@@ -616,6 +620,13 @@ wxMacCoreGraphicsPenBrushDataBase::CreateRadialGradientShading(
}
}
void wxMacCoreGraphicsPenBrushDataBase::ReleaseComponents(void *info)
{
const GradientComponents* stops = (GradientComponents*) info ;
if ( stops )
delete stops;
}
void wxMacCoreGraphicsPenBrushDataBase::CalculateShadingValues(void *info, const CGFloat *in, CGFloat *out)
{
const GradientComponents& stops = *(GradientComponents*) info ;
@@ -662,26 +673,27 @@ void wxMacCoreGraphicsPenBrushDataBase::CalculateShadingValues(void *info, const
CGFunctionRef
wxMacCoreGraphicsPenBrushDataBase::CreateGradientFunction(const wxGraphicsGradientStops& stops)
{
static const CGFunctionCallbacks callbacks = { 0, &CalculateShadingValues, NULL };
m_gradientComponents = new GradientComponents();
static const CGFunctionCallbacks callbacks = { 0, &CalculateShadingValues, &ReleaseComponents };
static const CGFloat input_value_range [2] = { 0, 1 };
static const CGFloat output_value_ranges [8] = { 0, 1, 0, 1, 0, 1, 0, 1 };
m_gradientComponents.Init(stops.GetCount());
for ( unsigned i = 0; i < m_gradientComponents.count; i++ )
m_gradientComponents->Init(stops.GetCount());
for ( unsigned i = 0; i < m_gradientComponents->count; i++ )
{
const wxGraphicsGradientStop stop = stops.Item(i);
m_gradientComponents.comps[i].pos = stop.GetPosition();
m_gradientComponents->comps[i].pos = stop.GetPosition();
const wxColour col = stop.GetColour();
m_gradientComponents.comps[i].red = (CGFloat) (col.Red() / 255.0);
m_gradientComponents.comps[i].green = (CGFloat) (col.Green() / 255.0);
m_gradientComponents.comps[i].blue = (CGFloat) (col.Blue() / 255.0);
m_gradientComponents.comps[i].alpha = (CGFloat) (col.Alpha() / 255.0);
m_gradientComponents->comps[i].red = (CGFloat) (col.Red() / 255.0);
m_gradientComponents->comps[i].green = (CGFloat) (col.Green() / 255.0);
m_gradientComponents->comps[i].blue = (CGFloat) (col.Blue() / 255.0);
m_gradientComponents->comps[i].alpha = (CGFloat) (col.Alpha() / 255.0);
}
return CGFunctionCreate ( &m_gradientComponents, 1,
return CGFunctionCreate ( m_gradientComponents, 1,
input_value_range,
4,
output_value_ranges,