From 9df16fede0919f16d1c8095f8c36a5f791be4c94 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 11 Dec 2013 22:22:01 +1100 Subject: [PATCH] WARNING: Server fails on startup For some reason, when trying to initiate the room thread, the entire server simply fails. There is no crash, no error message, or anything. I have no idea what's wrong. --- server/server_application.cpp | 22 ++++++++++++++++++++++ server/world_room.cpp | 16 +++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/server/server_application.cpp b/server/server_application.cpp index 800f02f..00b0ddf 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -88,6 +88,17 @@ void ServerApplication::Init(int argc, char** argv) { getline(is, script, '\0'); is.close(); sqlite3_exec(database, script.c_str(), nullptr, nullptr, nullptr); + + //open the rooms + cout << "DEBUG: inserting the room..." << endl; + worldRoomMap.insert( pair(worldRoomCounter++, WorldRoom(playerMap))); + + cout << "DEBUG: opening the rooms..." << endl; + + for (auto& it : worldRoomMap) { + it.second.OpenRoom(); + } + cout << "DEBUG: Finished initialization" << endl; } void ServerApplication::Loop() { @@ -114,6 +125,12 @@ void ServerApplication::Loop() { } void ServerApplication::Quit() { + //close the rooms + for (auto& it : worldRoomMap) { + it.second.CloseRoom(); + } + worldRoomMap.clear(); + //members network.Close(); @@ -124,6 +141,11 @@ void ServerApplication::Quit() { } void ServerApplication::HandlePacket(NetworkPacket packet) { + //debgging + for (auto& it : worldRoomMap) { + it.second.GetInQueue()->PushBack(packet); + } + switch(packet.meta.type) { case NetworkPacket::Type::BROADCAST_REQUEST: HandleBroadcastRequest(packet); diff --git a/server/world_room.cpp b/server/world_room.cpp index fd034d7..a012e96 100644 --- a/server/world_room.cpp +++ b/server/world_room.cpp @@ -27,16 +27,22 @@ using namespace std; int worldRoomThread(void* arg) { + cout << "DEBUG: in room thread" << endl; WorldRoom* room = reinterpret_cast(arg); + cout << "DEBUG: Beginning try block" << endl; try { + cout << "DEBUG: Init" << endl; room->Init(); + cout << "DEBUG: Loop" << endl; room->Loop(); + cout << "DEBUG: Quit" << endl; room->Quit(); } catch(exception& e) { cerr << "Fatal room error: " << e.what() << endl; return 1; } + cout << "DEBUG: Successfully ending room thread" << endl; return 0; } @@ -51,12 +57,18 @@ WorldRoom::~WorldRoom() { } void WorldRoom::OpenRoom() { + cout << "DEBUG: In OpenRoom" << endl; if (running) { throw(std::runtime_error("Cannot open a room that is already running")); } running = true; - thread = SDL_CreateThread(worldRoomThread, this); + + cout << "DEBUG: Attempting to create thread" << endl; + if (!(thread = SDL_CreateThread(worldRoomThread, this))) { + throw(std::runtime_error("Failed to open the room thread")); + } + cout << "DEBUG: End of thread call" << endl; } void WorldRoom::CloseRoom() { @@ -74,7 +86,9 @@ void WorldRoom::Init() { } void WorldRoom::Loop() { + cout << "DEBUG: In Loop" << endl; while(running) { + cout << "DEBUG: Top of loop" << endl; while(networkInQueue.Size() > 0) { HandlePacket(networkInQueue.PopFront()); }