Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vector of unique_ptr of polymorphic type fails #42

Closed
ghost opened this issue Feb 28, 2019 · 3 comments
Closed

vector of unique_ptr of polymorphic type fails #42

ghost opened this issue Feb 28, 2019 · 3 comments
Labels

Comments

@ghost
Copy link

ghost commented Feb 28, 2019

The following code crashes with version 1.10.2:

#include <iostream>
#include <ThorSerialize/JsonThor.h>
#include <ThorSerialize/SerUtil.h>

using namespace ThorsAnvil::Serialize;
using namespace std;

struct BaseVehicle {
    std::unique_ptr<bool> isPreloaded { nullptr };
    virtual ~BaseVehicle() = default;
    ThorsAnvil_PolyMorphicSerializer(BaseVehicle);
};
ThorsAnvil_MakeTrait(BaseVehicle, isPreloaded);

struct Vehicle : public BaseVehicle {
    std::unique_ptr<int> id { nullptr };
    ~Vehicle() override = default;
    ThorsAnvil_PolyMorphicSerializer(Vehicle);
};
ThorsAnvil_ExpandTrait(BaseVehicle, Vehicle, id);

struct Fleet {
    //! The list of vehicles.
    std::unique_ptr<std::vector<std::unique_ptr<Vehicle>>> vehicles { nullptr };
};
ThorsAnvil_MakeTrait(Fleet, vehicles);

int main()
{
    Fleet t {};
    string str = R"( {"vehicles":[
         {
            "__type": "Vehicle",
            "id":0
         }
      ]})";
    istringstream stream(str);
    stream >> ThorsAnvil::Serialize::jsonImport(t);

    return 0;
}

I get a EXC_BAD_ACCESS in line 280 of Serialize.tpp: https://github.com/Loki-Astari/ThorsSerializer/blob/master/src/Serialize/Serialize.tpp#L280

    object->parsePolyMorphicObject(parent, parser);
@Loki-Astari
Copy link
Owner

Taking a look.

@Loki-Astari
Copy link
Owner

OK. I hove found the issue.
Its around the conversion from T* to std::unique_ptr<T>. I will see if I can create a fix tonight.

@Loki-Astari
Copy link
Owner

Sorry it took so long.
Have a fixed checked in.
The test is here

Brew is build the new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant