Your comments

I would test removing the ! but it looks like this is intentional. It doesn't make sense to me so I won't try changing any code until you tell me to.

nope, when i said valid colours I meant many different colours as would  be expected of a leaf texture.

background colour is 0,0,0,0.68, the array contains all sorts of different values. it is taking a valid screenshot.  but as i said, the line 1971 appears to be asking for
!(col.r == background.r && col.g == background.g && col.b == background.b)

and then replacing with an empty pixel if true. so it's changing any colour that is different from the background colour into a transparent black pixel. I don't know the entirety of the script so this may be intentional but it seems to me that this line is effectively deleting all my leaf pixels. 

maybe I'm missing something but line 1971 in shadowtextureloop seems to be telling the script to delete the pixels if they are different from the background pixels...

okay, here is what I've ascertained. 
screenshotpic_nobark.getpixels yields an array full of valid colours. 
when it comes to the foreach loop at 2199 though, the array it is drawing from is full of empty colours.
This can only mean that for some reason, line 2195 is not resulting  in an array of the necessary colours. I can't say for sure because I can't check every value of the array, but totalpixelcount is definitely zero and that is causing the divide by zero error.

I don't like visual studio, I'm used to mono. but it appears to have a breakpoint function, so I'm just trying to locate the variables bit while running through it.

I've never used breakpoints before, I usually use debug log, so I'll just need to do some reading and I'll get back to you later once I've managed it.

Maybe this could help, I tried running the scene with single trees, the first tree made divide by zero errors, the second bush didn't, the third tree did, i gave up there. 

The output file appears to be successful but I'm not entirely certain as the thumbnail of the billboard tree looks like a close up of the leaves in a criss cross pattern. I don't know if that's normal. 

on each tree, the two materials it creates are using 'Tree Creator Leaves Optimized' and 'Tree Creator Bark Optimized'

It names them automatically as far as I can tell..  It's generated the two materials, Bark and Leaf.

Ok thanks, I'll wait for your reply. I am reluctant to upgrade to 2018.1 because I am certain there will be many things that would get messed up and I would have to fix.