Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

wrong initial frame when loading my c++ plugin

Contributor ,
Nov 20, 2020 Nov 20, 2020

Dear AE fellows,

I have the following problem with testing my AE c++ plugin.

When I load it (regadless from visual studio or independently)

it always initially shows  the shape rendered from the very first session.

Only when I start moving my sliders, the plugin gets back to the correct shape. 

But the same happens with the last frame!

 

Do you know how to fix this strange behavior?

Yaroslav.

 

 

TOPICS
SDK
848
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 21, 2020 Nov 21, 2020

i think what you're seeing is AE's dynamic resolution feature. it automatically reduces the comp's resolution to help keep interactive speeds up. you can check if that's the case by switching it off in the comp window's settings. (the lightning icon)

however, if that is indeed the case then you probably have not yet taken into account the downsample factors passed in the in_data struct. you should to that... it's a coomon practice for AE users and you can't avoid it.

Translate
Community Expert ,
Nov 20, 2020 Nov 20, 2020

There is no way to tell without having access to your plug-in or the code. We need details.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 21, 2020 Nov 21, 2020

Thanks for responding, Rick!

 

Here are principle details and parts of my code.

 

First of all, I use cairo library. Naturally, I need functions which sned from cairo buffer into AE buffer.

here they are:

struct cairoRefcon
{
	PF_EffectWorld output;
	unsigned char* data;
	int stride;
};


PF_Pixel* sampleIntegral8(PF_EffectWorld& def, int x, int y) {
	return (PF_Pixel*)((char*)def.data +
		(y * def.rowbytes) +
		(x * sizeof(PF_Pixel)));
}


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)
		{
			worldPtr->red = A_u_char(rowP[x] >> 16) / worldPtr->alpha * PF_MAX_CHAN8;
			worldPtr->green = A_u_char(rowP[x] >> 8) / worldPtr->alpha * PF_MAX_CHAN8;
			worldPtr->blue = A_u_char(rowP[x] >> 0) / worldPtr->alpha * PF_MAX_CHAN8;
		}

		worldPtr++;
	}

	return err;
}

 

Then I add a simple circle into my render function:

static PF_Err 
Render (
	PF_InData		*in_data,
	PF_OutData		*out_data,
	PF_ParamDef		*params[],
	PF_LayerDef		*output )
{
	PF_Err				err		= PF_Err_NONE;
	AEGP_SuiteHandler	suites(in_data->pica_basicP);


	

	PF_FILL(NULL, NULL, output); // I clean the canvas, at the beginning, as far as I understands.

	PF_FpLong radius = params[SKELETON_RADIUS]->u.fs_d.value;  // the radius of the circle

///////////////////// Drawing the circle in cairo ///////////////////////////////////

	cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, output->width, output->height);
	cairo_t* cr = cairo_create(surface);

	cairo_set_source_rgba(cr, 1, 0.2, 0.2, 0.8);

	cairo_arc(cr, double(output->width) * 0.5, double(output->height) * 0.5, radius, 0, 2 * PF_PI);

	cairo_set_source_rgba(cr, 1, 0.2, 0.2, 1);
	cairo_fill_preserve(cr);
	cairo_set_source_rgb(cr, 0, 1, 0);
	cairo_stroke(cr);

///////////////////////////////////////////////////////////////////////////////
	
	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));



	return err;
}

 

The point is, when I draw this circle (move slider) sometimes I see already deleted geometrical elements from my previous code. So, it seems some kind of cache is not cleaned properly.

Does anyone have some idea what is going on? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 21, 2020 Nov 21, 2020

Here is what I see instead of a red circle at the end position of radius slider (= 100).

 

All those additional shapes from my previous render functions! Isn't it strange? 

 

a1.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 21, 2020 Nov 21, 2020

The problem is partially alliviated if I clear cache manually in After Effects in Preferences > Media & Disk Cache, disable the Disk Cache.

 

But this is awkward. I'm sure one can do this using plugin inner code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2020 Nov 21, 2020

this is really odd. it could very well be a bug with AE.

try implementing samrtFX and reporting back a GUID during SmartPreRender that would tell AE the frame differs from what it already has cached.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 21, 2020 Nov 21, 2020

Thank you, Shachar,

I'll try to go for smartFX.

 

The other peculiar thing  is as follows.

When I  change parameters of my generated shape (e.g. I move its position with PF_ADD_POINT )

the shape gets recomputed and  during this time it gets enlarged on the canvas (see attached video).

It happens only with complicated shapes. With simple ones (like arcs or somth) everything is fine.

How one could avoid this?

 

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2020 Nov 21, 2020

i think what you're seeing is AE's dynamic resolution feature. it automatically reduces the comp's resolution to help keep interactive speeds up. you can check if that's the case by switching it off in the comp window's settings. (the lightning icon)

however, if that is indeed the case then you probably have not yet taken into account the downsample factors passed in the in_data struct. you should to that... it's a coomon practice for AE users and you can't avoid it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 21, 2020 Nov 21, 2020
LATEST

Indeed, Shachar,

you were right. The downsampling feature was turned on. 

My solution is as as follows (apart from turning off the downsampling feature).

 

The scale of my shape is controlled by the float parameter  scale.

I introduce a compensating factor:

float scale2 = in_data->downsample_x.den;

and then my new scale is

 scale/scale2

 

I know I don't take into acount a possible non 1:1 pixel aspect ratio, but for now it works very well.

Yaroslav.

 

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines