file read exception handle : I am getting this error "Exception thrown at 0x0FC04AFF (vcruntime140d.dll) in Ergasia.exe: 0xC0000005: Access violation writing location 0x00000020.

If there is a handler for this exception, the program may be safely continued.".

Which takes me to this part of my code :

    for (unsigned int i = 0; i < width*height * 3; i = i + 3) {

        file.read((char *)cR, 1);
        file.read((char *)cG, 1);
        file.read((char *)cB, 1);

        buffer[i] = cR / 255.0f;
        buffer[i + 1] = cG / 255.0f;
        buffer[i + 2] = cB / 255.0f;
    }
I tried using try/catch and some other if checks but neither worked. Anyone knows what's causing it?