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.
This commit is contained in:
@@ -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<int, WorldRoom>(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);
|
||||
|
||||
+15
-1
@@ -27,16 +27,22 @@
|
||||
using namespace std;
|
||||
|
||||
int worldRoomThread(void* arg) {
|
||||
cout << "DEBUG: in room thread" << endl;
|
||||
WorldRoom* room = reinterpret_cast<WorldRoom*>(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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user