The problem is
uint16_t data[(res+1)*(res+1)];
it is a local array of 416 MB+ that is too big to fit in the stack (usually 1 MB) - you have to create it in the heap with a new statement:
uint16_t* data = new uint16_t[(res+1)*(res+1)];
and then remember to de-allocate it with a delete statement when you don't need it any more:
delete[] data;