Crashing with sampleImage Expression once adding > 30 layers
AE 23.1.0 (build 83)
My Composition - animates shapes in a wave like fashion altering rotation and scale on thhe Scale X property. Here is an image which works fine with the 30 shape layers included.

Now the moment I try and add more shapes AE crashes. (See below for the setup and expressions)
I worked out the 30+ number as I added 5 extra at a time till it crashed. So it's really somewhere between 30 and 35 it crashes but thats not super important as i am a long way off where I need to get to. I want at least 144 more would be nice but i'd settle with that I think. I did find if I changed the project setting to Mercury GPU rather then software I could get more layers without crashing. Mind you I also get crashing with the 30 Layers if I duplicate and try to do other things. But I can get it to render if Open it up fresh and I don't do anything else.
to me it feels like a RAM problem. I tried turning off multi frame rendering in prefs and interestingly i got this error "After Effects Warning: Unable to set clip. GDi Status: Generic Error" Mind you I had to close AE as the error kept coming up & I couldn't do anyhting else but I did manage to increase layers and get a preview going. I got up to like 49 layers before crashing with Muti-Frame turned off.
I am hoping someone can help. And importantly I hope that Adobe devs address this error and my issue. I am happy to provide more info to the devs etc to get these problems looked at. I am not holding my breath though. Hoping to be proved wrong.
Anyone know how I can prevent the crashing with this comp and get my layers up to 144. TIA.
Comp Setup -
Null Layer -> Control w various Expression Controls
Shape layer(s) -> rectangle expressions on Rotation & Scale
Pre Comp with a turb noise
rotation expression
sampleLayer = thisComp.layer("Control").effect("Sample Layer")("Layer");
sampleSize = thisComp.layer("Control").effect("Sample Size (pixels square)")("Slider");
sampleSize = [sampleSize,sampleSize];
samplePosition = transform.position;
/*
use if wanting to control time offset and/or post effects on sample layer
sampleEffects = parseInt(thisComp.layer("Control").effect("Dropdown Menu Control")("Menu"));
sampleEffects == 1 ? postEffect = 0 : postEffect =1;
sampleTimeOffset = thisComp.layer("Control").effect("Sample TIme Offset (s)")("Slider");
sampleTime = time-sampleTimeOffset;
samplePosition = samplePosition + thisComp.layer("Control").effect("Sample position Offset")("Point");
*/
displaceMin = thisComp.layer("Control").effect("Rotation Min")("Angle");
displaceMax = thisComp.layer("Control").effect("Rotation Max")("Angle");
a = sampleLayer.sampleImage(samplePosition,sampleSize)
/*
use if wanting to control time offset and/or post effects on sample layer
a = sampleLayer.sampleImage(samplePosition,sampleSize,postEffect,sampleTime)
*/
// b = (a[0]+a[1]+a[2])/3;
b = a[0];
c = linear(b,0,1,displaceMin,displaceMax)
value + c
Scale Expression
sampleLayer = thisComp.layer("Control").effect("Sample Layer")("Layer");
sampleSize = thisComp.layer("Control").effect("Sample Size (pixels square)")("Slider");
sampleSize = [sampleSize,sampleSize];
samplePosition = transform.position;
/*
use if wanting to control time offset and/or post effects on sample layer
sampleEffects = parseInt(thisComp.layer("Control").effect("Dropdown Menu Control")("Menu"));
sampleEffects == 1 ? postEffect = 0 : postEffect =1;
sampleTimeOffset = thisComp.layer("Control").effect("Sample TIme Offset (s)")("Slider");
sampleTime = time-sampleTimeOffset;
samplePosition = samplePosition + thisComp.layer("Control").effect("Sample position Offset")("Point");
*/
displaceMin = thisComp.layer("Control").effect("Scale Min")("Slider");
displaceMax = thisComp.layer("Control").effect("Scale Max")("Slider");
a = sampleLayer.sampleImage(samplePosition,sampleSize)
/*
use if wanting to control time offset and/or post effects on sample layer
a = sampleLayer.sampleImage(samplePosition,sampleSize,postEffect,sampleTime)
*/
// b = (a[0]+a[1]+a[2])/3;
b = a[0]
c = linear(b,0,1,displaceMin,displaceMax)
value + [c,0]
