Skip to main content
Known Participant
March 18, 2009
Question

AEGP_UtilitySyite5::AEGP_ExecuteScript() doesn't do anything in my effect plugin. why?

  • March 18, 2009
  • 19 replies
  • 11174 views
Bonjoir All of you!,

I'm developing a Effect plugin and I wanted to execute some script using the AEGP_UtilitySyite5::AEGP_ExecuteScript() function. I have supplied all the parameters to this function. this function executing, but not doing anything. If I execute the same script via File -> Scripts -> Run Script File, then its working prefect. Why it doesn't do anyhting if I execute using the above function? what could be the reason for this?? am I missing anything??

Please any suggestions...

Thanks
Manjunath
This topic has been closed for replies.

19 replies

Known Participant
March 31, 2009
hehehehhe :)

I'm implementing it and I will let you know. Thanks
Community Expert
March 30, 2009
ehem...
I read your question 5 times and still found it confusing.
a bit like: How much wood would a woodchuck chuck if a woodchuck would chuck wood?
sorry.
let's try this instead.
these are the steps, in greater detail:
let's refer to the effect as "effect" and the AEGP as, well, "AEGP".

create an AEGP with two elements.
1) a special suite, which will be used to transfer data to the AEGP.
2) an idle_hook, which in idle times runs the needed scripts.

let's call the special suite "theSpecialSuite".
with that suite you create the "LeaveMessage" function, that should look like this:

void LeaveMessage(bool putMessage)
{
haveMessage = putMessage;
}

haveMessage is a global scope variable in the AEGP.
it will shortly be read by the second function of the AEGP, which should look like (in a very simplified way):

void idleHook(AEGP_GlobalRefcon Grefcon, AEGP_IdleRefcon Irefcon, A_long *sleep)
{
if(haveMessage) {
runScript;
haveMessage = FALSE; }//to ensure we only run it once per request.
}

thus far, the AEGP.
now the effect.
at some point your effect will want to run a script.
it doesn't matter if it happens from the render function or the param supervision function.
in any case you do the following:

1) acquire the "theSpecialSuite" suite.
2) leave a message: theSpecialSuite()->LeaveMessage(TRUE);
this will utilize the LeaveMessage at the AEGP.
the actual function. not a copy of it.
therefore the message you left (TRUE), will be stored with the
AEGP.
3) release the "theSpecialSuite" suite.

the process of your effect continues until it exits.
control has not been diverted.
changes were not yet made.
the script has not yet run.

after about one 10th of a second the idleHook function in the AEGP gets a call.
it checks if it has any messages.
it has.
it runs the script, and erases the message.

what was all of that good for?
the script is run by the AEGP while the effect is not in use.
therefore it can do things with it, such as applying another effect or re ordering effects, that would otherwise, if done when the effect is active, make AE crash.
Known Participant
April 16, 2009

Hello Shachar,

I have developed 2 effect plugins:     1. plugin for creating UI only and

                                                    2. plugin for lanching the script only.

You already knew that, My script is purely based on setting expressions to parameters. These params are nothing but UI items in the UI plugin.

some where in the script calls the UI plugin and set the expressions.

So, what I did is:

     1. Loaded /applied the script effect plugin

               this automatically calls UI effect plugin and Ui will be displayed.

     2. UI is displayed in Effects Control Window (ECW) fine.

     3. Exressions are also set byb the script plugin using the script.

     this working fine, i.e., script is launched. No crash.

     but getting an error "After Effects error: Internal verification failure".

     error bmp file attached here.

I observed that:

     1. sometimes script is launched with out any error. 100% working fine.

     2. sometimes getting an error shown in attached bmp file

     3. sometimes getting crash in AE.

     4.  the script file, which is no relation (or communication) with the ECW, then that script file executing with out any errors.

          If the script file is has relation with the ECW( like in our case, set the expressions to ECW UI params), then that script file 

          executing fine sometimes and getting error some times.

[ I think you understand the above 4th point ]

Now tell me, what could be the reson for this getting error?

Community Expert
April 17, 2009

what is the UI in the ECW?

is it an effect?

a custom param?

perhaps a java palette?

for such errors to occur, you must affect the effect stack while it's in use.

either for adding or subtracting data from it.

what are the working components?

and please note which of them is an effect, AEGP, java palette, java script or anything else that might come into mind.

don't dispare,

we'll get it eventually.

:-(

Known Participant
March 30, 2009
Shachar,

I am implemeting above mentioned method.
could you please just confirm my doubts please?

for example my plugin name: ScriptExecute, Script: myScript and newly created plugin name: ScriptHelper.

now..

1) "ScriptHelper" plugin is a AEGP plugin and I have to create a new suite in this and I have to execute "myScript" in this plugin.
am I right??

2) "ScriptExecute" plugin should call the "ScriptHelper" plugin and execute the script in "ScriptHelper" plugin. Right?

3) When "ScriptHelper" plugin execute "myScript", then the "ScriptHelper" plugin will destroy and then control return back to the original "ScriptExecute" plugin. Right??

and finally
- How can we call the "ScriptHelper" plugin from "ScriptExecute" plugin?
Community Expert
March 30, 2009
I was afraid of that...
I had that problem before.
it happened to me when i tried to add an effect to the same stack as the effect that's doing the adding.
no good.
error on AE7 and crash on CS3.
what I'm guessing is happening is that by the time you gain back control, and reach the exit point of you plug-in, it's out_data is no longer valid as it's containing effect stack has changed.

the solution is tricky but it works:

create a separate AEGP plug-in and use it to add a new suite that will allow you to transfer data from you effect plug-in to it.
(check "checkout" and "sweetie" samples to see how that's done)
in addition define an AEGP_RegisterIdleHook in that AEGP.
why do you need that? we'll get to that later.

when you want to trigger the java scripts from your effect, transfer the necessary data to the AEGP via the new suite, and let the effect exit normally.
so far, no script was run.

now the AEGP_RegisterIdleHook kicks in.
this tells AE that the AEGP would like to know when it has some free CPU time.
(when AE isn't rendering, it happens about 10 - 20 times each second)
when the AEGP gets that call, it checks if the effect has left him any messages.
if so, it runs the scripts as asked by the effect.

so what did we get?
the effect enters and exits without losing control, or having it's effect stack tempered with.
the scripts are run from a different plug-in (the AEGP) from outside that stack, and at a time when this stack is not in use.

if indeed the problem that makes your plug-in crash is AE's inability to handle changes in the stack during it's use, then this will be the only way to go.
(at least the only way i found)
Known Participant
March 30, 2009
Hi Shachar,

I tested with MemorySuite1(). now script is launching,
( even with malloc(), script is launching), but now giving crash in AE.

I'm sure that this crash (may be) because of plugin control will gone away and control owned by script. Beacuse after executing the script, it displays UI in the Effect panel, and put a break point on EntryFunc() and click on any param in the UI then NO notification will go into the plugin. plugin control is completely destroyed.

So is there any method to prevent this crash in AE??
Community Expert
March 28, 2009
dude, seriously, don't use malloc.
it goes head to head with AE for RAM.
instead use AEGP_NewMemHandle.
here's an example code:

//code for allocating the memory
char *script[] = {0};
AEGP_MemHandle scriptH = NULL;
AEGP_MemSize sizeOfScript = whateverYourSizeIs;
ERR(suites.MemorySuite1()->AEGP_NewMemHandle( 0,
"text for errors",
sizeOfScript ,
AEGP_MemFlag_CLEAR,//same as memset to 0
&scriptH));
if(scriptH){
ERR(suites.MemorySuite1()->AEGP_LockMemHandle(scriptH , (void**)&script));}

//and the code for releasing it.
if(scriptH){
ERR2(suites.MemorySuite1()->AEGP_UnlockMemHandle(scriptH));
ERR2(suites.MemorySuite1()->AEGP_FreeMemHandle(scriptH));}

as for the control owner you mentioned, yes it can cause a problem.
but so far the symptoms you're describing aren't those of that problem.
try the memory suite instead of malloc, and if that doesn't solve it... let's not worry about that now.
Known Participant
March 28, 2009
forgot to mension, when the script successfully launches, then control is owned by the script, not my plugin. is this might be the reason??
Known Participant
March 28, 2009
I deleted the extra lines and extra spaces in aline and deleted the commentts. Then I executed the code. Its working fine.
and

- some times the pointer returned by malloc() is not a valid ( I see in memory window the pointer had only some bytes not the total size).

- sometimes when I free the allocated memory, it is crashing in that line itself ( I mean at the free() line itself ).

- sometimes after executing the free(), then crash in AE.

- I tried with utilitysuite4, no success. same crash.
Community Expert
March 27, 2009
I used your code do get the script
and then i used:
AEGP_SuiteHandler suites(in_data->pica_basicP);
suites.UtilitySuite5()->AEGP_ExecuteScript(NULL, script, FALSE, NULL, NULL);
to run it.

if you're using AE7 or intend for the plug-in to be compatible to it,
use UtilitySuite4 instead of 5.
it's also good for CS3 and 4.

what change did you make that made it run?
and under what conditions does it crash?

p.s.
in the ReadScriptFromAFile() function you use malloc.
it is highly recommended to avoid using this command as it competes with AE for ram.
use the memory suite's functions instead.
I don't think that this is the reason for the crashes you're having,
but it will make you crash eventually.
Known Participant
March 27, 2009
Finally I made it to run successfully! :)
but now crash in AE.

When I comment the line AEGP_ExecuteScript() then no crash in AE
When I execute the line AEGP_ExecuteScript() then crash in AE

could you please post your code here if possible, please.