Are you absolutely sure there are only “4000 little buildings”? One mistake with grafting will instantly turn that into 16 million little buildings. I find it useful to substantially reduce the geometry count until I am certain the code is working correctly before increasing the count.
Without posting any code, it’s impossible to determine the reason the code crashes.
3. Attach minimal versions of all the relevant files