The function below returns crashes with failed assertion at return of the function. This only occurs in visual studiol; when I run it in linux with cmake, everything works great. The issue occurs in both debug and assertion mode.
I am using Visual Studio 2015 with OpenCV 3.1.0. The OpenCV files are included correctly I'm sure because the program doesn't crash at the OpenCV functions.
function:
void detectFace(Mat frame, Scalar &face_colour) {
    printf("1\n");
    vector<Rect> faces;
    Mat frame_gray;
    Scalar main_face_colour;
    printf("2\n");
    cvtColor(frame, frame_gray, CV_BGR2GRAY);
    equalizeHist(frame_gray, frame_gray);
    printf("3\n");
    Rect main_face = Rect(0, 0, 0, 0);  // hold the main face to be recognized
    // Detect faces using the cascade
    face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(80, 80));
    printf("4\n");
    for (size_t i = 0; i < faces.size(); i++) {
        printf("5\n");
        if (faces[i].width * faces[i].height > main_face.width * main_face.height) {
            main_face.x = faces[i].x;
            main_face.y = faces[i].y;
            main_face.width = faces[i].width;
            main_face.height = faces[i].height;
        }
        printf("6\n");
        rectangle(frame, Point(faces[i].x, faces[i].y), Point(faces[i].x + faces[i].width, faces[i].y + faces[i].height), Scalar(229, 181, 51), 4);
        printf("7\n");
    }
    //int col = frame.at<int>(main_face.x + main_face.width / 2, main_face.y + main_face.height / 2);  // TODO: Average the colour of the pixels in the face region
        //toColour(col, face_colour);
    printf("8\n");
    main_face_colour = mean(frame(main_face));
    circle(frame, Point(main_face.x + main_face.width / 2, main_face.y + main_face.height / 2), 4, face_colour, 4);
    printf("9\n");
    if (main_face != Rect(0, 0, 0, 0))  // Send to mask maker
        //makeMesh(frame(main_face), main_face);
    printf("10\n");
    rectangle(frame, main_face, main_face_colour, 5);  // Indicate main face
    showUserId(frame, main_face_colour, faces.size());
    //cout << face_colour << endl;
    printf("11\n");
}
Assertion Message:
Debug Assertion Failed!
Program: ...\Documents\GitHub\Face Recognition\Debug\Face Recognition.exe
File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp
Line: 892
Expression: is_block_type_valid(header->_block_use)
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
Update:
The error is occuring because of the face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(80, 80)); line.
