c++plugin memory problem when hit play
Dear AE fellows,
I created a c++ (effect)plugin which draws some animated shapes (letters) with the help of cairo library.
I have the following problem.
When I hit "play" button, the plugin memory consumption increases drastically.
And even when I remove all the layers with this effect from the scene, the memory usage doesn't drop (!) and stays the same for quite a while.
I think, that is probably a typical problem for an inexperienced developer. Does somebody encountered the same problem (I guess some kind of memory leak)?
Here are principal parts of my code:
struct cairoRefcon
{
PF_EffectWorld output;
unsigned char* data;
int stride;
};
//**Main drawing function(taking data from cairo buffer and turning it into AE //pixels)********************
PF_Err cairoCopy8(void* refcon, A_long threadInd, A_long iterNum, A_long iterTotal)
{
cairoRefcon* data = (cairoRefcon*)refcon;
int i = iterNum;
PF_Err err = PF_Err_NONE;
uint32_t* rowP;
PF_Pixel8* worldPtr = sampleIntegral8(data->output, 0, i);
rowP = (uint32_t*)(data->data + i * data->stride);
for (int x = 0; x < data->output.width; x++)// column
{
worldPtr->alpha = rowP[x] >> 24;
if (worldPtr->alpha)
{
float rf = A_u_char(rowP[x] >> 16) / (float)worldPtr->alpha;
float gf = A_u_char(rowP[x] >> 😎 / (float)worldPtr->alpha;
float bf = A_u_char(rowP[x] >> 0) / (float)worldPtr->alpha;
worldPtr->red = A_u_char(rf * PF_MAX_CHAN8);
worldPtr->green = A_u_char(gf * PF_MAX_CHAN8);
worldPtr->blue = A_u_char(bf * PF_MAX_CHAN8);
}
worldPtr++;
}
return err;
}
//**************************************************************
//************* Render function*********************************
static PF_Err
Render(
PF_InData* in_data,
PF_OutData* out_data,
PF_ParamDef* params[],
PF_LayerDef* output, json& dictionary, std::string word1, bool reg)
{
PF_Err err = PF_Err_NONE;
AEGP_SuiteHandler suites(in_data->pica_basicP);
PF_FILL(NULL, NULL, output);
//************Some slider controls for the shape drawn ****************
std::string font = GetPresetColorValue(params[SKELETON_FLAVOR]->u.pd.value);
PF_FpLong radius = params[SKELETON_RADIUS]->u.fs_d.value;
PF_FpLong scale = params[SKELETON_SCALE]->u.fs_d.value;
PF_FpLong opacity = params[SKELETON_OPACITY]->u.fs_d.value * 0.01;
//*********************************************************************
//**************** Setting up cairo canvas*****************************
cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, output->width, output->height);
cairo_t* cr = cairo_create(surface);
//*********************************************************************
//********************* Drawing the shape itself **********************
word_write(word, radius / 100., 1., x_coord, y_coord, scale / scale2, dictionary, cr);
cairo_set_line_width(cr, 1.0);
cairo_set_source_rgba(cr, color.red, color.green, color.blue, opacity);
cairo_fill_preserve(cr);
//*********************************************************************
//************* Mapping cairo buffer to AE buffer**********************
cairoRefcon cairoRefcon; AEFX_CLR_STRUCT(cairoRefcon);
cairoRefcon.data = cairo_image_surface_get_data(surface);
cairoRefcon.stride = cairo_image_surface_get_stride(surface);
cairoRefcon.output = *output;
ERR(suites.IterateSuite1()->AEGP_IterateGeneric(output->height, &cairoRefcon, cairoCopy8));
//*********************************************************************
cairo_destroy(cr);
cairo_surface_destroy(surface);
return err;
}
//**********************************************************************