Jump to content

C++ Errors

Go to solution Solved by fizzlesticks,

Indexing in C++  starts at 0. You declared helms with a size of 8, so 0-7 are the usable indexes. Once you get to helms[8] it goes off the end of the array and breaks.

I am trying to make a program that will find the best combination of armor, horse, lance, and helm in a game I play. Could be used for other application as well in the future. When I am trying to run the program it doesn't do anything and then the error comes up.

 

If my program is needed to understand the problem I can provide that as well.

 

Error Message

 

First-chance exception at 0x57AF31CA (msvcr120d.dll) in RivalKnights.exe: 0xC0000005: Access violation writing location 0xCCCCCCCC.

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

 

Output from Debug

 

'RivalKnights.exe' (Win32): Loaded 'C:\Users\Michael\Documents\Visual Studio 2013\Projects\RivalKnights\Debug\RivalKnights.exe'. Symbols loaded.
'RivalKnights.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Symbols loaded.
'RivalKnights.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Symbols loaded.
'RivalKnights.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Symbols loaded.
'RivalKnights.exe' (Win32): Loaded 'C:\Windows\SysWOW64\apphelp.dll'. Symbols loaded.
SHIMVIEW: ShimInfo(Complete)
'RivalKnights.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp120d.dll'. Symbols loaded.
'RivalKnights.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr120d.dll'. Symbols loaded.
First-chance exception at 0x583231CA (msvcr120d.dll) in RivalKnights.exe: 0xC0000005: Access violation writing location 0xCCCCCCCC.
Unhandled exception at 0x583231CA (msvcr120d.dll) in RivalKnights.exe: 0xC0000005: Access violation writing location 0xCCCCCCCC.

First-chance exception at 0x583231CA (msvcr120d.dll) in RivalKnights.exe: 0xC0000005: Access violation writing location 0xCCCCCCCC.
Unhandled exception at 0x583231CA (msvcr120d.dll) in RivalKnights.exe: 0xC0000005: Access violation writing location 0xCCCCCCCC.

First-chance exception at 0x583231CA (msvcr120d.dll) in RivalKnights.exe: 0xC0000005: Access violation writing location 0xCCCCCCCC.
Unhandled exception at 0x583231CA (msvcr120d.dll) in RivalKnights.exe: 0xC0000005: Access violation writing location 0xCCCCCCCC.

The thread 0x1784 has exited with code -1073741510 (0xc000013a).
The program '[8168] RivalKnights.exe' has exited with code -1073741510 (0xc000013a).

 

Link to comment
https://linustechtips.com/topic/231629-c-errors/
Share on other sites

Link to post
Share on other sites

Sounds like an uninitialized pointer, can't help much without the code.

#include <iostream>#include <string.h>using namespace std;int main() {    int league;    const int helms = 8;    const int armors = 6;    const int horses = 6;    const int lances = 7;    struct helm {        int league;        int defense;        int weight;        string name;    } helm[helms]; // total number of helms in game, not just league    struct armor {        int league;        int defense;        int weight;        string name;    } armor[armors]; // total number of armor in game, not just league    struct horse {        int league;        double speed;        int capacity;        string handling;        string name;    } horse[horses]; // total number of horses in game, not just league    struct lance {        int league;        int damage;        int weight;        string aiming;        string name;    } lance[lances]; // total number of lances in game, not just league    helm[1].league = 1;    helm[1].defense = 27;    helm[1].weight = 1;    helm[1].name = "Rustic Helm";    helm[2].league = 1;    helm[2].defense = 29;    helm[2].weight = 1;    helm[2].name = "Dark Teutonic Helm";    helm[3].league = 1;    helm[3].defense = 32;    helm[3].weight = 2;    helm[3].name = "Crux Helm";    helm[4].league = 1;    helm[4].defense = 35;    helm[4].weight = 2;    helm[4].name = "Heavy Iberian Helm";    helm[5].league = 1;    helm[5].defense = 44;    helm[5].weight = 2;    helm[5].name = "Nogai Helm";    helm[6].league = 1;    helm[6].defense = 47;    helm[6].weight = 1;    helm[6].name = "Spagoth Helm";    helm[7].league = 1;    helm[7].defense = 54;    helm[7].weight = 2;    helm[7].name = "Vidin Helm";    helm[8].league = 1;    helm[8].defense = 59;    helm[8].weight = 2;    helm[8].name = "Heavy Thuringian Helm";    armor[1].league = 1;    armor[1].defense = 81;    armor[1].weight = 3;    armor[1].name = "Plated Leather Armor";    armor[2].league = 1;    armor[2].defense = 98;    armor[2].weight = 5;    armor[2].name = "Studded Leather Armor";    armor[3].league = 1;    armor[3].defense = 114;    armor[3].weight = 3;    armor[3].name = "Heavy Leather Armor";    armor[4].league = 1;    armor[4].defense = 133;    armor[4].weight = 3;    armor[4].name = "Padded Nogai Armor";    armor[5].league = 1;    armor[5].defense = 163;    armor[5].weight = 5;    armor[5].name = "Padded Vidin Armor";    armor[6].league = 1;    armor[6].defense = 174;    armor[6].weight = 4;    armor[6].name = "Heavy Studded Armor";    horse[1].league = 1;    horse[1].speed = 16.6;    horse[1].capacity = 11;    horse[1].handling = "Easy";    horse[1].name = "Buckskin Nogai Rouncey";    horse[2].league = 1;    horse[2].speed = 19.3;    horse[2].capacity = 8;    horse[2].handling = "Hard";    horse[2].name = "Bay Jennet";    horse[3].league = 1;    horse[3].speed = 29.7;    horse[3].capacity = 11;    horse[3].handling = "Fair";    horse[3].name = "White Courser";    horse[4].league = 1;    horse[4].speed = 29.8;    horse[4].capacity = 11;    horse[4].handling = "Easy";    horse[4].name = "Bay Nogai Hobby";    horse[5].league = 1;    horse[5].speed = 34.8;    horse[5].capacity = 8;    horse[5].handling = "Hard";    horse[5].name = "Dapple-Gray Palfrey";    horse[6].league = 1;    horse[6].speed = 33.1;    horse[6].capacity = 12;    horse[6].handling = "Fair";    horse[6].name = "Black Destrier";    lance[1].league = 1;    lance[1].damage = 107;    lance[1].weight = 4;    lance[1].aiming = "Easy";    lance[1].name = "Basic Lance";    lance[2].league = 1;    lance[2].damage = 131;    lance[2].weight = 7;    lance[2].aiming = "Fair";    lance[2].name = "Rustic Lance";    lance[3].league = 1;    lance[3].damage = 174;    lance[3].weight = 4;    lance[3].aiming = "Fair";    lance[3].name = "Light Pinewood Lance";    lance[4].league = 1;    lance[4].damage = 176;    lance[4].weight = 4;    lance[4].aiming = "Easy";    lance[4].name = "Hollowed Lance";    lance[5].league = 1;    lance[5].damage = 215;    lance[5].weight = 7;    lance[5].aiming = "Hard";    lance[5].name = "Heavy Rustic Lance";    lance[6].league = 1;    lance[6].damage = 214;    lance[6].weight = 4;    lance[6].aiming = "Fair";    lance[6].name = "Fine Lance";    lance[7].league = 1;    lance[7].damage = 190;    lance[7].weight = 4;    lance[7].aiming = "Fair";    lance[7].name = "Red Velvet Lance";    cout << "What league are you in: ";    cin >> league;    for (int h = 1; h < helms + 1; h++) {        for (int a = 1; a < armors + 1; a++) {            for (int s = 1; s < horses + 1; s++) {                for (int l = 1; l < lances + 1; l++) {                    if (helm[h].league == armor[a].league == horse[s].league == lance[l].league) {                        if (helm[h].weight + armor[a].weight + lance[l].weight <= horse[s].capacity) {                            cout << "true";                        }                        else {                            cout << "false";                        }                    }                }            }        }    }    cin.get();    return 0;}
Link to comment
https://linustechtips.com/topic/231629-c-errors/#findComment-3167043
Share on other sites

Link to post
Share on other sites

Indexing in C++  starts at 0. You declared helms with a size of 8, so 0-7 are the usable indexes. Once you get to helms[8] it goes off the end of the array and breaks.

Oh, thanks. I thought I got to choose as long as it didn't have more than 8 things in it.

Link to comment
https://linustechtips.com/topic/231629-c-errors/#findComment-3167074
Share on other sites

Link to post
Share on other sites

I see horses in that code! :o

Case: NZXT Phantom PSU: EVGA G2 650w Motherboard: Asus Z97-Pro (Wifi-AC) CPU: 4690K @4.2ghz/1.2V Cooler: Noctua NH-D15 Ram: Kingston HyperX FURY 16GB 1866mhz GPU: Gigabyte G1 GTX970 Storage: (2x) WD Caviar Blue 1TB, Crucial MX100 256GB SSD, Samsung 840 SSD Wifi: TP Link WDN4800

 

Donkeys are love, Donkeys are life.                    "No answer means no problem!" - Luke 2015

 

Link to comment
https://linustechtips.com/topic/231629-c-errors/#findComment-3167112
Share on other sites

Link to post
Share on other sites

    for (int h = 1; h < helms + 1; h++) {        for (int a = 1; a < armors + 1; a++) {            for (int s = 1; s < horses + 1; s++) {                for (int l = 1; l < lances + 1; l++) {                    if (helm[h].league == armor[a].league == horse[s].league == lance[l].league) {                        if (helm[h].weight + armor[a].weight + lance[l].weight <= horse[s].capacity) {                            cout << "true";                        }                        else {                            cout << "false";                        }                    }                }            }        }    }

 

A tip: too many levels. And with many levels comes eye strain @_@

Link to comment
https://linustechtips.com/topic/231629-c-errors/#findComment-3175046
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×