Effectively the problem was the uint32 was overflowing when calculating the buffer size: (d*(d-1))/2 ) with d~500000
A mistake I do constantly
Thanks for the replies!