Skip to main content
Inspiring
December 15, 2021
Answered

c++plugin memory problem when hit play

  • December 15, 2021
  • 1 reply
  • 467 views

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;
}
//**********************************************************************

 

 

This topic has been closed for replies.
Correct answer shachar carmi

are you sure it's a leak? can it be AE caching the rendered frames?

try purging ram after a play or preview. does it return to the level before the play/preview began?

1 reply

shachar carmiCommunity ExpertCorrect answer
Community Expert
December 15, 2021

are you sure it's a leak? can it be AE caching the rendered frames?

try purging ram after a play or preview. does it return to the level before the play/preview began?

Inspiring
December 28, 2021

Thanks, Shachar!

After purging the memory it does return to the same level. 

Do you know if it is possible to purge memory from within the plugin when the user changes some parameter in the plugin UI?

(In my case, when the user changes theword to be written onscreen)

Community Expert
December 28, 2021

i guess it is possible using javascipt which you can trigger from the C API using ExecuteScript.

app.executeCommand(2370);

that should do the trick, HOWEVER, i would strongly advie against it... purging ram can infuriate users how need to cache all other timlines or portions of the current timeline all over again.

changing a param value should invalidate all cached frames where the current effect instance is part of the comp render. is that not the case for you?

you could also change the value of some invisible param to force an invalidation of cached frames if your situation is such that some user input doesn't manifist as a regular param change.