unsigned char * data = new unsigned char[screenw*screenh];
glReadPixels(0,0,screenw,screenh,GL_STENCIL_INDEX,GL_UNSIGNED_BYTE,data);
delete [] data;
this doesn’t crash in my case. so check your allocation and deallocation, check “w” and “h” values twice, if it’s ok - something is wrong with surrounding code(and you, probably, should submit some to get help).
And as usual when a question about stencil not working is asked, we should always ask: did you ensure you created a Window which has stencil capabilities ?