SFML community forums

Help => Network => Topic started by: Switchboy on November 02, 2021, 05:19:07 pm

Title: Piece of network conde not compiling in g++ (it does in VS19!)
Post by: Switchboy on November 02, 2021, 05:19:07 pm
The send code

sf::Packet actorDataPacket;
        sf::Uint8 actorDataHeader = dataType::actorsBlob;
        actorDataPacket << actorDataHeader;
        size_t amountOfActors = listOfActors.size();
        actorDataPacket << amountOfActors;

        for (actors& a : listOfActors) {
            int x = a.getActorCords().x;
            int y = a.getActorCords().y;
            int team = a.getTeam();
            int type = a.getType();
            actorDataPacket << x << y << team << type;
        }
        currentConnection.getTcpSocket()->send(actorDataPacket);

 
The recieve code:
sf::Packet recievePacket;
sf::Socket::Status statusOfSocket = currentConnection.getTcpSocket()->receive(recievePacket);
if (statusOfSocket == sf::Socket::Done) {
        sf::Uint8 recievedHeader;
        recievePacket >> recievedHeader;
        switch (recievedHeader) {

                case dataType::actorsBlob:
                    size_t amountOfActors;
                    recievePacket >> amountOfActors;
                    for (int i = 0; i < amountOfActors; i++) {
                        int x;
                        int y;
                        int team;
                        int type;
                        recievePacket >> x;
                        recievePacket >> y;
                        recievePacket >> team;
                        recievePacket >> type;
                        listOfActors.push_back(actors(type, { x, y }, team, static_cast<int>(listOfActors.size())));
                    }
                    actorBlobRecieved = true;

                    break;
}

On windows using Visual Studio Community 2019 this compiles just fine

On linux using g++ with VSCode and sfml-vscode-boilerplate it does not comile:
Error: invalid conversion from 'size_t'  {aka 'long unsigned int' to 'wchart_t*' [-fpermissive]

When turning on '-fpermissive' I believe it tries to use sf::bool, sf::string, sf::Uint8 to 64 and fails.

Am I right te presume that I am trying to do something undefined by putting a size_t into a SFML packet? And it was dumb luck it worked on windows?

Which sf:: datatype corresponds to a long unsigned int? So I could use that datatype instead to make this piece of code work.
Title: Re: Piece of network conde not compiling in g++ (it does in VS19!)
Post by: eXpl0it3r on November 03, 2021, 08:06:36 am
std::size_t is implementation defined with the constraint to be at least as large as unsigned int or similar. As such, it's not really a good candidate of a type to be used for transferring over the network or between different clients, as every compiler can have it implemented differently.
I'm unsure how the compiler thinks long unsigned int is best converted to wchar_t*, but I guess there's a (good) reason for it.

What you can do is cast it to the more well-defined type (e.g. unsigned int or sf::Unit32).