Assign g_GameConsole ptr only 1 time, Fixed variable initialization, fixed overlay.cpp crash with free call.

This commit is contained in:
IcePixelx 2021-07-19 14:31:12 +02:00
parent d8ba5a3740
commit 2f239760ad
2 changed files with 36 additions and 13 deletions

View File

@ -182,10 +182,11 @@ public:
////////////////////
std::vector<std::string> MapsList;
std::string* SelectedMap = nullptr;
std::string HostRequestMessage;
ImVec4 HostRequestMessageColor;
std::string HostRequestMessage = "";
ImVec4 HostRequestMessageColor = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
char ServerNameBuffer[64] = { 0 };
bool StartAsDedi;
bool StartAsDedi = false;
bool BroadCastServer = false;
void SetSection(ESection section)
{

View File

@ -246,7 +246,7 @@ void CGameConsole::ProcessCommand(const char* command_line)
{
if (Stricmp(History[i], command_line) == 0)
{
free(History[i]);
delete History[i];
History.erase(History.begin() + i);
break;
}
@ -384,6 +384,9 @@ void CCompanion::UpdateHostingStatus()
}
case EHostStatus::Hosting:
{
if (!BroadCastServer) // Do we wanna broadcast server to the browser?
break;
SendHostingPostRequest(GameGlobals::HostState->m_levelName);
break;
}
@ -559,6 +562,8 @@ void CCompanion::ServerBrowserSection()
void CCompanion::HostServerSection()
{
static std::string ServerNameErr = "";
ImGui::InputTextWithHint("Server Name##ServerHost_ServerName", "Required Field", ServerNameBuffer, IM_ARRAYSIZE(ServerNameBuffer));
ImGui::Spacing();
if (ImGui::BeginCombo("Map##ServerHost_MapListBox", SelectedMap->c_str()))
@ -576,22 +581,36 @@ void CCompanion::HostServerSection()
ImGui::Checkbox("Start as dedicated server (HACK)##ServerHost_DediCheckbox", &StartAsDedi);
ImGui::SameLine();
ImGui::Checkbox("Broadcast Server to Server Browser", &BroadCastServer);
ImGui::Separator();
if (ImGui::Button("Start The Server##ServerHost_StartServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
{
UpdateHostingStatus();
std::stringstream cmd;
cmd << "map " << SelectedMap->c_str();
g_GameConsole->ProcessCommand(cmd.str().c_str());
if (StartAsDedi)
if (strlen(ServerNameBuffer) != 0)
{
ToggleDevCommands();
ServerNameErr = std::string();
UpdateHostingStatus();
std::stringstream cmd;
cmd << "map " << SelectedMap->c_str();
g_GameConsole->ProcessCommand(cmd.str().c_str());
if (StartAsDedi)
{
ToggleDevCommands();
}
}
else
{
HostRequestMessage = "No Server Name assigned.";
HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
}
}
ImGui::TextColored(ImVec4(1.00f, 0.00f, 0.00f, 1.00f), ServerNameErr.c_str());
ImGui::TextColored(HostRequestMessageColor, HostRequestMessage.c_str());
if (StartAsDedi)
@ -696,7 +715,10 @@ void Strtrim(char* s)
void DrawConsole()
{
static CGameConsole console;
g_GameConsole = &console;
static bool AssignPtr = []() {
g_GameConsole = &console;
return true;
} ();
console.Draw("Console");
}