Page 1 of 1

AE is crashing

Posted: March 11th, 2017, 4:02 am
by HTN3D
I am writing a script with interface that creates a comps contain text and shape layers. I have been testing the script by creating one comp every time I testing it as I am writing the code  and everything was normal until I accidentally tried to create multiple comps then it crashed. I check everything but it keeps crashing whenever i create more than one comp.
I am using Git so I backed couple versions and I found that the problem started occur when I started splitting the code to multiple libraries to keep it maintainable because its fairly long and contains many functions and modules, so I am wandering if there are any limitations to the number of libraries or variables or loops that I can use in AE script. And also if there is a way to debug the crash and understand what's going on. I am using Atom on Mac and not showing anything.

I have been learning and writing script for few months now.. so I will be very grateful for any advice.

Re: AE is crashing

Posted: March 11th, 2017, 4:16 am
by HTN3D
I tried to test the script on Windows and it's same problem but the difference is showing legitimate message which says:
"After Effects: Memory allocation of 12.3 GB exceeds internal limits. Decrease the memory requirements for the rendering of this frame. (12802). For more information, see"

It sounds a memory problem so maybe something wrong with variables scope or the loops i'm using? I have few global vars waiting util I finish to put them inside a main function but could they causing this problem?

Re: AE is crashing

Posted: March 11th, 2017, 5:03 pm
by runegan
Are you able to create some sample code that reproduces the problem?

How are you importing your libraries? Are you using @include/#include?

Using multiple files should not be a problem. I have been dealing with 30+ files without any trouble.

I'm thinking it may be a problem with the resolution or duration of the comps. If they are big and long, I'm guessing they may become a problem for AE.

Re: AE is crashing

Posted: March 11th, 2017, 9:26 pm
by HTN3D
Thanks Runegan for your response!
I am using #include and I don't think the comp resolution or duration is the problem. I ran many tests and I think the problem occur in the objects that I am passing by the function arguments. I am not sure but I think they're kind of not releasing the memory after the function is done and keep staking the data(not sure just personal thought). So I did some research about the memory management in JavaScript and I'm reading about memory leak and how to avoid it but still not sure if I need to clear this objects manually every time I use them?

briefly my script is a UI that generated by long "resourceString" and by onClick button it passes couple of objects as arguments to multiple functions to create the comp. these objects are a parameters that have been collected from the UI. the script creates first and second comp normally but crashes the AE on the third comp. sometimes ExtendScript showes the object is "undefined" before it crashes.

Re: AE is crashing

Posted: March 13th, 2017, 8:55 am
by HTN3D
the problem finally solved and I would like to share what it was. 
After I inspected every single function in the script I was suspicious about one function that creates the GUI. I used Mathias Möhl approach but it contains some statements I wasn't sure if they were necessary to have. I tried to search about it and I liked David Torno approach of how he build the GUI in AE. So I used it after a little tweaks and the problem solved.

so the old code I was using to building the GUI was like this:

Code: Select all

function createUserInterface (thisObj,userInterfaceString,scriptName){
  var pal = (thisObj instanceof Panel) ? thisObj : new Window("palette", scriptName,  undefined,{resizeable: true});
  if (pal == null) return pal;

  var UI=pal.add(userInterfaceString);

  pal.onResizing = pal.onResize = function () {
  if ((pal != null) && (pal instanceof Window)) {;
  return UI;
And I replaced it with the following code and it solved the problem: 

Code: Select all

function createUserInterface (thisObj,scriptName){
  var UI = (thisObj instanceof Panel) ? thisObj : new Window ("palette",scriptName,undefined, {resizeable:true});
  resourceString = "whatever string...";
  UI.mainPanel = UI.add(resourceString);
  if ((UI != null) && (UI instanceof Window)){;;
    return UI;
I am glad that I ran through this problem because that pushed me to search a lot about the internal memory management in JS and learn how possible small mistake could lead to memory leak..