int width = 2560;
int height = 1440;
int frameBuffer[width*height];
for (int i = 0; i < width*height; ++i)
frameBuffer[i]=i;
This code locks the process up, even thou I am well within the bounds of 32 bit integers and I have plenty of memory to allocate the array?
BTW Ironic, isn’t it? Asking about a stack overflow error on a site called stackoverflow 🙂
You are probably exceeding the available stack space, causing an overflow. It is not a good idea to have such big arrays on the stack.
Instead of using the non-standard VLA’s (variable-length arrays), you can allocate the buffer yourself:
Also note the usage of
size_trather thanint. You should stick withsize_twhen it comes to allocation sizes, since anintis not always guaranteed to be capable of holding a size large enough.