BUGFIX: Solved server failure
Cause: server/server_application.cpp: line 93 The last argument to std::pair was simply a call to WorldRoom's contructor. This created a temporary object that fufilled this line, but after the new std::pair object was added to worldRoomMap, this WorldRoom object went out of scope. server/server_application.cpp: line 96 When OpenRoom() was called using an object that was out of scope, the entire server simply failed. Solution: Changed worldRoomMap to hold a pointer to a WorldRoom object, rather than the object itself. The new and delete operators should be used to create and delete WorldRoom objects respectfully.
This commit is contained in:
@@ -90,20 +90,14 @@ void ServerApplication::Init(int argc, char** argv) {
|
||||
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;
|
||||
worldRoomMap.insert( pair<int, WorldRoom*>(worldRoomCounter++, new WorldRoom(playerMap)));
|
||||
|
||||
for (auto& it : worldRoomMap) {
|
||||
it.second.OpenRoom();
|
||||
it.second->OpenRoom();
|
||||
}
|
||||
cout << "DEBUG: Finished initialization" << endl;
|
||||
}
|
||||
|
||||
void ServerApplication::Loop() {
|
||||
//debugging
|
||||
|
||||
NetworkPacket packet;
|
||||
|
||||
while(running) {
|
||||
@@ -127,7 +121,8 @@ void ServerApplication::Loop() {
|
||||
void ServerApplication::Quit() {
|
||||
//close the rooms
|
||||
for (auto& it : worldRoomMap) {
|
||||
it.second.CloseRoom();
|
||||
it.second->CloseRoom();
|
||||
delete it.second;
|
||||
}
|
||||
worldRoomMap.clear();
|
||||
|
||||
@@ -143,7 +138,7 @@ void ServerApplication::Quit() {
|
||||
void ServerApplication::HandlePacket(NetworkPacket packet) {
|
||||
//debgging
|
||||
for (auto& it : worldRoomMap) {
|
||||
it.second.GetInQueue()->PushBack(packet);
|
||||
it.second->GetInQueue()->PushBack(packet);
|
||||
}
|
||||
|
||||
switch(packet.meta.type) {
|
||||
|
||||
Reference in New Issue
Block a user