I'm working on my MMO game still, and I've run into a problem. My pseudo-code that works:
Code: Select all
char* OnlinePlayerHat;
void client_thread() {
recv(...); //Receive info from server
if (OnlinePlayerHat != ReceivedData.hatString) {
setHat(RceievedData.hat);
OnlinePlayerHat = ReceivedData.hatString;
}
}
int main() {
bool running = true;
while (running) {
client_thread();
}
}(Of course, this is pseudo-code, so some things are different)
BUT, when I do this; It doesn't work?:
Code: Select all
char* OnlinePlayerHat;
void client_thread() {
bool runThread = true;
while (runThread) {
recv(...); //Receive info from server
if (OnlinePlayerHat != ReceivedData.hatString) {
setHat(RceievedData.hat);
OnlinePlayerHat = ReceivedData.hatString;
}
}
}
int main() {
bool running = true;
CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)client_thread,NULL,NULL,NULL);
}But online, it doesn't even display the mesh at all. The client just crashes.
It's a bit strange, and I don't see the problem.
Here's why I'm trying to use the thread instead of the looped from main code:
When looped in main, the received data seems to work for a while. But after so long, the players just stop updating. So if I moved, no one would see it. Which makes no sense.
Even when I remove hats and only display player locations.
--But when I use the CreateThread, everything seems to work smoothly and without any problems. Other than the hat, of course, which when removed still works as should be.
Any ideas on how to fix this?
Thanks!