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

sourceRectAtTime on text layer crashes.

New Here ,
Jun 04, 2021 Jun 04, 2021

I have been getting many crashes using this expression and would love to figure out why. The expression measures the lenght of the text and if it exceeds a certain amount, splits the text into two and adds a line break in the middle. It seems to work fine but has been causin insta-crashes on my whenever I try to change anything on the text layer - font size, add a position text animator and start scrubbing, etc. Thanks in advance for any help.

I included all the different crashes that I received in the past hour while working on this project. Using OSX 11.3.1 and AE 18.2.0

The expression is:

maxWidth = 880;
layerWidth = thisLayer.sourceRectAtTime(time,false).width;
if(layerWidth > maxWidth){
layerText = value
words = layerText.split(" ") mid = Math.round(words.length / 2)
value = words.slice(0,mid).join(" ") + "\r" + words.slice(mid).join(" ") }
else{ value }

TOPICS
Crash , Expressions
492
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
LEGEND ,
Jun 05, 2021 Jun 05, 2021

"value" is a reserved keyword revferencing the property value in AE. You cannot arbitrarily use it as a variable name in your own code. And you may also want to help matters along by actually writing your code line by line and using semicolons. contrary to what self-proclaimed "web dev geniuses" on YouTube and elsewhere state, these things aren't superfluous, especially since AE is not a web browser and has not many safeguards for bad code.

 

Mylenium

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
New Here ,
Jun 05, 2021 Jun 05, 2021
LATEST

Thanks for the suggestion Mylenium. I've updated the code to below but still crashing just the same. Any ideas on what I can change in the expression to make it not crash? Or another way to do the same thing?

maxWidth = 880;
layerWidth = thisLayer.sourceRectAtTime(time,false).width;
if(layerWidth > maxWidth){ layerText = thisLayer.text.sourceText;
words = layerText.split(" ");
mid = Math.round(words.length / 2);
twoLines = words.slice(0,mid).join(" ") + "\r" + words.slice(mid).join(" ");
}else{ thisLayer.text.sourceText; }

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