'OpenGL Expression: Vector subscript out of range

I am in the process of writing a script to draw a circle and draw lines around that circle, call it a low resolution depiction of the Corona Virus. I am using vectors to store the coordinates of the points. For reasons not yet known, I receive a vector subscript out of range debug error. Since it is in run time and not compile time, I do not get the line number for the same error. 24 hours back, I got the same error while using vectors for another problem.

  • Visual Studio 2019
  • OpenGL

Below is the snippet of the Corona Virus program.

vector<double> multiply(vector<vector<double>> mat1, vector<double> mat2) {
    vector<double> product;
    for (int i = 0; i < mat1.size(); i++)
        for (int j = 0; j < mat2.size(); j++)
            product[i] += mat1[i][j] * mat2[j];
    return product;
}

vector<double> rotate(vector<double> P, double theta) {
    vector<vector<double>> R(3, vector<double>(3, 0));
    vector<double> product;
    R[0][0] = cos(theta);
    R[0][1] = -sin(theta);
    R[1][0] = sin(theta);
    R[1][1] = cos(theta);
    product = multiply(R, P);
    return product;
}

void coronaDemo() {
    glClear(GL_COLOR_BUFFER_BIT);
    double theta = 90;
    glColor3f(1, 0, 0);
    drawCircle();
    vector<vector<double>> points = {
        {0, 100, 1},
        {0, 300, 1}
    };
    for (size_t i = 0; i < points.size(); i++)
    {
        for (size_t j = 0; j < points[i].size() - 1; j++)
        {
            cout << points[i][j] << " ";
        }
        cout << "\n";
    }
    glBegin(GL_LINES);
    for (size_t i = 0; i < points.size(); i++)
    {
        vector<double> temp;
        temp = rotate(points[i], theta);
        glVertex2d(temp[0], temp[1]);
        temp.clear();
    }
    glEnd();
    glFlush();
}

int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(HEIGHT, HEIGHT);
    glutCreateWindow("Corona Virus");
    myInit();
    glutDisplayFunc(coronaDemo);
    glutMainLoop();
    return 1;
}

Kindly help me identify the reason for the said error. Do ask any other information that might be required to frame the question better.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source