Jack
Jack

Reputation: 3

Unhandled exception at (msvcr120d.dll)

Have written some code for university coursework. This code compiles and runs well on the machines at university - but does not run on my personal laptop. I'm using Visual Studio 2013 (same as at Uni), running windows 10 via bootcamp on a 2015 Macbook.

Code compiles fine - prints the first few lines in console - then crashes, with the following error.

"Unhandled exception at 0x56BEA9E8 (msvcr120d.dll) in ConsoleApplication3.exe: 0xC0000005: Access violation reading location 0xCCCCCCC0."

int main()
{
    string wheel1[3], wheel2[3], wheel3[3];

    for (int counter = 0; counter < 4; counter++) { wheel1[counter] = getSuit(); }
    for (int counter = 0; counter < 4; counter++) { wheel2[counter] = getSuit(); }
    for (int counter = 0; counter < 4; counter++) { wheel3[counter] = getSuit(); }

    return 0;
}

Have tried searching for solutions - but these generally seem to point towards some bad coding.

Have looked through for anything similar to the other errors I found, but nothing's jumping out at me.

Also unsure as to why this code would work flawlessly on one machine, and not on another...

All help much appreciated..!

Upvotes: 0

Views: 2126

Answers (1)

bashrc
bashrc

Reputation: 4835

Your array wheel1,wheel2 and wheel3 allocates memory for 3 string objects while in the for loop you will try to access the 4th element for which space hasn't been allocated.

for (int counter = 0; counter < 4; counter++) { wheel1[counter] = getSuit(); }

At some point counter will become 3 and then your code will try to access a memory block illegally. Either modify your loop so that counter goes till 3 or increase the size of the array by 1.

Upvotes: 1

Related Questions