#Assertion Error

21 messages · Page 1 of 1 (latest)

wide raven
#

(Pictures on side) My error seems to come when I call my inventory the second time (first time also a picture). It opens up what seems to be the compiler or assembly file (named vector, again the picture).

pale cargoBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

wide raven
#

"Unhandled exception at 0x00007FFD5FAC829C (ucrtbased.dll) in notworkngwhatshappening.exe: An invalid parameter was passed to a function that considers invalid parameters fatal." It says it's an invalid parameter yet it fails half-way through the function (at cin >>)

#

#else // ^^^ _ITERATOR_DEBUG_LEVEL == 0 / _ITERATOR_DEBUG_LEVEL != 0 vvv
const auto _Mycont = static_cast<const _Myvec*>(this->_Getcont());
_STL_VERIFY(_Off == 0 || _Ptr, "cannot seek value-initialized vector iterator");
_STL_VERIFY(_Off == 0 || _Mycont, "cannot seek invalidated vector iterator");
if (_Off < 0) {
_STL_VERIFY(_Off >= _Mycont->_Myfirst - _Ptr, "cannot seek vector iterator before begin");
}

    if (_Off > 0) {
        _STL_VERIFY(_Off <= _Mycont->_Mylast - _Ptr, "cannot seek vector iterator after end");
    }

#endif // _ITERATOR_DEBUG_LEVEL == 0
The bug area

#

int inv(std::vectorstd::string inv) {

std::cout << "\nYou scuffle through your bag, finding these: \n";

int grab; // Item to take from inv

// Prints inventory
for (int i = 0; i < inv.size(); i++) {
    std::cout << i + 1 << ": " << inv[i] << " ";
}


std::cout << "Take item: ";
std::cin >> grab;

inv.erase(inv.begin() + (grab - 1)); // Erase taken inventory spot

return grab; // Return taken item

}
It fails here the second time it's called, it fails at std::cin >> grab;, and the only reason I can think of is int grab; might keep some memory or something

#

Second call: int chosenWeapon;
chosenWeapon = inv(inventory);

First call: int returned = 0;
returned = inv(inventory);

#

And the vector it's referencing:
std::vectorstd::string inventory = { "An unlit torch", "a rusty dagger", "a bottle half full of whiskey", "a coin bag with what's left of your life savings" };

wide raven
#

Assertion Error

shrewd umbra
#

@wide raven can you give full code please ?

wide raven
#

I'll give the points that deal with it

#

std::vector<std::string> inventory = { "An unlit torch", "a rusty dagger", "a bottle half full of whiskey", "a coin bag with what's left of your life savings"}; // Inventory vector

...

#
std::cout << "You realize you might need a torch. Enter 'i' to open your inventory\n\n";

    char input; // Throwable variable for inventory input
    int returned = 0; // For later seeing if torch equipped - perhaps switch to other vari and use for next inv
    std::cin >> input;
    if (input == 'i') { // Make this a string with equipped item ? Or just for the shrine dude - Take away torch when used
        returned = inv(inventory); // Even without this it doesn't let me input anything

        if (returned == 1) {
            std::cout << "\nYou grab a torch from your bag and light it, easing the darkness\n\n";

        }
        else {
            std::cout << "\nYou decide to save the torch\n\n";

        }

    } else { 

        std::cout << "\nYou decide to let your eyes adjust instead\n\n";
    }

system("pause");
system("cls");

...

#
        std::cout << "You come across an arch leading into the next room. You see shadows moving in it.\n";

        
        {
            int search;
            std::cout << "1: Search for another route    2: Go in\n\n";
            std::cin >> search;
            int chosenWeapon = 0;

            if (search == 1) {
                std::cout << "You search the hallway to no avail. Find a weapon in your bag (i to access it).\n";

                std::cin >> search; // Make this a separate throwaway var, add if i isn't pressed - also make it do something

                chosenWeapon = inv(inventory);

                std::cout << "You hesitantly enter the room\n";
            }
            else {
                std::cout << "Find a weapon in your bag (i)\n";

                std::cin >> search; // Make this a separate throwaway var, add if i isn't pressed

                chosenWeapon = inv(inventory);

                std::cout << "\nYou enter the room.\n";
            }

            if (chosenWeapon == 1) {
                std::cout << "A rusty dagger shall do fine";
                weapon = "Rusty dagger";
                weaponDmg = 5;
            }
            else {

                std::cout << "It would be a waste to spend your dagger on a small pest";
                weapon = "Fists";
                weaponDmg = 1;

            } // Stops before next code
            ```

...
#
int inv(std::vector<std::string> inv) { // Perhaps make void and just assign vari to memory point? * and &

    std::cout << "\nYou scuffle through your bag, finding these: \n";

    int grab; // Item to take from inv
    
    // Prints inventory
    for (int i = 0; i < inv.size(); i++) { 
        std::cout << i + 1 << ": " << inv[i] << " ";
    }


    std::cout << "Take item: ";
    std::cin >> grab;

    inv.erase(inv.begin() + (grab - 1)); // Erase taken inventory spot

    return grab; // Return taken item
}

int dmg(int hp, int def, int dmg) { // Takes in current health, defense, and damage being received (returns the hp with the damage taken)

    //attack*(100 / (100 + defense))
    int attDmg = dmg * (100 / (100 + def)); // Attack damage to return
    hp -= attDmg;

    return hp;

}
#

And it stops when 'inv' is being called for the second time, at the cin >> it pops up the error and any input doesn't show up

#

I'm goin to sleep

wide raven
#

Found the problem, had to clear my output buffer

#

!solved