jeudi 30 juin 2016

Lambda function capture by copy results in corruped data

std::vector<Spell*> playerSpells{ new Jump(1), new Arrow() };

for each (auto spell in playerSpells)
{
    spell->icon->onClickEndEH.add([=]() {
        auto a = spell;
        auto b = spell->sprite;
    });

    player->addSpell(spell);
}

First, I checkedspell variable before the add function and it's fields are initialized correctly. When the lambda function is called, the variable b is corrupted. I can provide other parts of the code if that's not enough.

Aucun commentaire:

Enregistrer un commentaire