SDLNet sending structs with vectors segFault

122 views Asked by At

I am currently working in making a game with online, a simple game, my first time with SDLNet. I was thinking on each client sending structs with the position to the server and the server handle sending it to the others clients. The problem comes when tryng to send structs that contains vectors. If the structs only contains ints there isn't any segfault. I will leave some of the code:

struct STRUCT_TO_SEND {
    std::vector <int> posXs;
    std::vector <int> posYs;
};
int buffer_zise = 200;
char buffer[buffer_zise];

//From the client side
STRUCT_TO_SEND test; 
test.posXs.push_back(2);
test.posYs.push_back(2);
memcpy(buffer, &test, sizeof(test));
SDLNet_TCP_Send( client, buffer, buffer_zise );

//From the server side
SDLNet_TCP_Recv(clientSocket[i], buffer, buffer_zise);
STRUCTURA_TO_SEND tmp;
memcpy(&tmp, buffer, sizeof(STRUCT_TO_SEND)); //<--Getting segfault
std::cout << tmp.posXs[0] << " " << tmp.posYs[0] << std::endl; //<--Getting segfault
0

There are 0 answers