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.
This commit is contained in:
Kayne Ruse
2013-06-17 09:08:28 +10:00
parent 752dcadfa1
commit 009e7b845b
3 changed files with 6 additions and 14 deletions
+1 -1
View File
@@ -13,10 +13,10 @@ static std::deque<Packet> queue;
int networkQueue(void*) { int networkQueue(void*) {
UDPNetworkUtility* netUtil = ServiceLocator<UDPNetworkUtility>::Get(); UDPNetworkUtility* netUtil = ServiceLocator<UDPNetworkUtility>::Get();
Packet p;
for(;;) { for(;;) {
SDL_SemWait(lock); SDL_SemWait(lock);
while(netUtil->Receive()) { while(netUtil->Receive()) {
Packet p;
memcpy(&p, netUtil->GetInData(), sizeof(Packet)); memcpy(&p, netUtil->GetInData(), sizeof(Packet));
queue.push_back(p); queue.push_back(p);
} }
+2 -2
View File
@@ -81,8 +81,8 @@ struct PlayerMove {
}; };
union Packet { union Packet {
Packet() {}; Packet() { type = PacketType::NONE; };
PacketType type = PacketType::NONE; PacketType type;
Ping ping; Ping ping;
Pong pong; Pong pong;
+3 -11
View File
@@ -1,19 +1,11 @@
#include "packet_type.hpp" #include "packet_type.hpp"
#include "service_locator.hpp"
#include "foobar.hpp"
#include "vector2.hpp"
#include <iostream> #include <iostream>
using namespace std; using namespace std;
int main() { int main() {
ServiceLocator<int>::Set(new int(42)); Packet p;
ServiceLocator<Packet>::Set(new Packet()); cout << int(p.type) << endl;
cout << FooBar() << endl;
ServiceLocator<int>::Set(nullptr);
ServiceLocator<Packet>::Set(nullptr);
return 0; return 0;
} }