From 009e7b845b92a53887ab524fe801c23d0da2865c Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 17 Jun 2013 09:08:28 +1000 Subject: [PATCH] Fixed network error, leaving try block in place for the time being It seems that the union type Packet didn't initialize Packet::type to PacketType::NONE using in class initialization. I've fixed this by moving the initialization of Packet::type to Packet::Packet(). This might actually be a compiler error, I might need to let someone know. --- libs/common/network_queue.cpp | 2 +- libs/common/packet_type.hpp | 4 ++-- test/main.cpp | 14 +++----------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/libs/common/network_queue.cpp b/libs/common/network_queue.cpp index 463dbad..c873732 100644 --- a/libs/common/network_queue.cpp +++ b/libs/common/network_queue.cpp @@ -13,10 +13,10 @@ static std::deque queue; int networkQueue(void*) { UDPNetworkUtility* netUtil = ServiceLocator::Get(); - Packet p; for(;;) { SDL_SemWait(lock); while(netUtil->Receive()) { + Packet p; memcpy(&p, netUtil->GetInData(), sizeof(Packet)); queue.push_back(p); } diff --git a/libs/common/packet_type.hpp b/libs/common/packet_type.hpp index 54845bd..358fc35 100644 --- a/libs/common/packet_type.hpp +++ b/libs/common/packet_type.hpp @@ -81,8 +81,8 @@ struct PlayerMove { }; union Packet { - Packet() {}; - PacketType type = PacketType::NONE; + Packet() { type = PacketType::NONE; }; + PacketType type; Ping ping; Pong pong; diff --git a/test/main.cpp b/test/main.cpp index cf90d1c..4a86fd0 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,19 +1,11 @@ #include "packet_type.hpp" -#include "service_locator.hpp" -#include "foobar.hpp" - -#include "vector2.hpp" #include + using namespace std; int main() { - ServiceLocator::Set(new int(42)); - ServiceLocator::Set(new Packet()); - - cout << FooBar() << endl; - - ServiceLocator::Set(nullptr); - ServiceLocator::Set(nullptr); + Packet p; + cout << int(p.type) << endl; return 0; } \ No newline at end of file