I am trying to serialize SFML shapes for a 2D ms paint like program. I am getting an assertion error during build but everything online I can find it is a result of not marking a function with the template class. Here is the only place in my code where I am ussing the library, can someone help me find my issue? Thank you!
#pragma once
#include <SFML/Graphics.hpp>
#include <cereal/cereal.hpp>
namespace cereal {
template <class Archive>
void serialize(Archive& ar, sf::Vector2f& vector) {
ar(CEREAL_NVP(vector.x), CEREAL_NVP(vector.y));
}
template <class Archive>
void serialize(Archive& ar, sf::RectangleShape& shape) {
sf::Vector2f position = shape.getPosition();
sf::Vector2f size = shape.getSize();
sf::Color fillColor = shape.getFillColor();
sf::Color outlineColor = shape.getOutlineColor();
float outlineThickness = shape.getOutlineThickness();
ar(CEREAL_NVP(position), CEREAL_NVP(size), CEREAL_NVP(fillColor), CEREAL_NVP(outlineColor), CEREAL_NVP(outlineThickness));
shape.setPosition(position);
shape.setSize(size);
shape.setFillColor(fillColor);
shape.setOutlineColor(outlineColor);
shape.setOutlineThickness(outlineThickness);
}
template <class Archive>
void serialize(Archive& ar, sf::CircleShape& circle) {
std::size_t pointCount = circle.getPointCount();
sf::Vector2f position = circle.getPosition();
float radius = circle.getRadius();
sf::Color fillColor = circle.getFillColor();
sf::Color outlineColor = circle.getOutlineColor();
float outlineThickness = circle.getOutlineThickness();
ar(CEREAL_NVP(position), CEREAL_NVP(radius), CEREAL_NVP(fillColor), CEREAL_NVP(outlineColor), CEREAL_NVP(outlineThickness));
circle.setPointCount(pointCount);
circle.setPosition(position);
circle.setRadius(radius);
circle.setFillColor(fillColor);
circle.setOutlineColor(outlineColor);
circle.setOutlineThickness(outlineThickness);
}
}
template void cereal::serialize<cereal::BinaryOutputArchive>(cereal::BinaryOutputArchive&, sf::Vector2f&);
template void cereal::serialize<cereal::BinaryOutputArchive>(cereal::BinaryOutputArchive&, sf::RectangleShape&);
template void cereal::serialize<cereal::BinaryOutputArchive>(cereal::BinaryOutputArchive&, sf::CircleShape&);
Here is the output log:
Build started at 7:21 PM...
1>------ Build started: Project: Simple2D-DrawingApplication, Configuration: Debug Win32 ------
1>DrawingDataSaver.cpp
1>D:\Dev\LocalRepos\Simple2D-DrawingApplication\Src\SFMLSerialization.h(51,112): warning C4667: 'void cereal::serialize(cereal::BinaryOutputArchive &,sf::RectangleShape &)': no function template defined that matches forced instantiation
1>D:\Dev\LocalRepos\Simple2D-DrawingApplication\Src\SFMLSerialization.h(52,109): warning C4667: 'void cereal::serialize(cereal::BinaryOutputArchive &,sf::CircleShape &)': no function template defined that matches forced instantiation
1>D:\Dev\LocalRepos\Simple2D-DrawingApplication\cereal-1.3.2\include\cereal\cereal.hpp(570,87): error C2338: static_assert failed: 'cereal could not find any output serialization functions for the provided type and archive combination.
1> Types must either have a serialize function, load/save pair, or load_minimal/save_minimal pair (you may not mix these).
1> Serialize functions generally have the following signature:
1> template<class Archive>
1> void serialize(Archive & ar)
1> {
1> ar( member1, member2, member3 );
1> }
1> '
1>D:\Dev\LocalRepos\Simple2D-DrawingApplication\cereal-1.3.2\include\cereal\cereal.hpp(444,13): message : see reference to function template instantiation 'ArchiveType &cereal::OutputArchive<ArchiveType,1>::processImpl<std::shared_ptr<sf::Shape>,(cereal::traits::detail::sfinae)0>(const T &)' being compiled
1> with
1> [
1> ArchiveType=cereal::BinaryOutputArchive,
1> T=std::shared_ptr<sf::Shape>
1> ]
1>D:\Dev\LocalRepos\Simple2D-DrawingApplication\cereal-1.3.2\include\cereal\cereal.hpp(333,13): message : see reference to function template instantiation 'void cereal::OutputArchive<cereal::BinaryOutputArchive,1>::process<const std::shared_ptr<sf::Shape>&>(T)' being compiled
1> with
1> [
1> T=const std::shared_ptr<sf::Shape> &
1> ]
1>D:\Dev\LocalRepos\Simple2D-DrawingApplication\Src\DrawingDataSaver.cpp(19,3): message : see reference to function template instantiation 'ArchiveType &cereal::OutputArchive<ArchiveType,1>::operator ()<const std::shared_ptr<sf::Shape>&>(const std::shared_ptr<sf::Shape> &)' being compiled
1> with
1> [
1> ArchiveType=cereal::BinaryOutputArchive
1> ]
1>D:\Dev\LocalRepos\Simple2D-DrawingApplication\Src\DrawingDataSaver.cpp(19,10): message : see the first reference to 'cereal::OutputArchive<cereal::BinaryOutputArchive,1>::operator ()' in 'DrawingDataSaver::Save'
1>DrawingApp.cpp
1>D:\Dev\LocalRepos\Simple2D-DrawingApplication\Src\SFMLSerialization.h(51,112): warning C4667: 'void cereal::serialize(cereal::BinaryOutputArchive &,sf::RectangleShape &)': no function template defined that matches forced instantiation
1>D:\Dev\LocalRepos\Simple2D-DrawingApplication\Src\SFMLSerialization.h(52,109): warning C4667: 'void cereal::serialize(cereal::BinaryOutputArchive &,sf::CircleShape &)': no function template defined that matches forced instantiation
1>D:\Dev\LocalRepos\Simple2D-DrawingApplication\Src\SFMLSerialization.h(10,3): error C2064: term does not evaluate to a function taking 2 arguments
1>D:\Dev\LocalRepos\Simple2D-DrawingApplication\Src\SFMLSerialization.h(50,23): message : see reference to function template instantiation 'void cereal::serialize<cereal::BinaryOutputArchive>(cereal::BinaryOutputArchive &,sf::Vector2f &)' being compiled
1>Generating Code...
1>Done building project "Simple2D-DrawingApplication.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 7:21 PM and took 05.360 seconds ==========