Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when Reloading AI in single player #8037

Closed
SamuXarick opened this issue Mar 18, 2020 · 7 comments
Closed

Crash when Reloading AI in single player #8037

SamuXarick opened this issue Mar 18, 2020 · 7 comments

Comments

@SamuXarick
Copy link
Contributor

@SamuXarick SamuXarick commented Mar 18, 2020

Version of OpenTTD

1.10.0-RC1

Expected result

Reload the AI

Actual result

Crash when reloading AI in single player

Steps to reproduce

Start only one AI in single player
Cheat and move to AI company
Let human company bankrupt.
Reload AI -> crash
crash.zip

@SamuXarick
Copy link
Contributor Author

@SamuXarick SamuXarick commented Dec 27, 2020

I can't reproduce this in 1.10.3 downloaded from openttd.org, but still asserts in master. Is it because asserts are disabled?

@James103
Copy link
Contributor

@James103 James103 commented Dec 27, 2020

When I do the following:

  1. Start the first AI
  2. Switch company cheat to AI company
  3. Bankrupt human company
  4. Start the second AI
  5. Reload the first AI

Result: You are automatically switched over to the other AI company. Repeating steps 4-5 reproduces this result again.

@SamuXarick
Copy link
Contributor Author

@SamuXarick SamuXarick commented Dec 27, 2020

That's fine, I suppose. It tries to pick some other company to move you in.

This is where stuff happens:

OpenTTD/src/economy.cpp

Lines 291 to 302 in 4f8e7b2

/* Single player cheated to AI company.
* There are no spectators in single player, so we must pick some other company. */
assert(!_networking);
Backup<CompanyID> cur_company2(_current_company, FILE_LINE);
for (const Company *c : Company::Iterate()) {
if (c->index != old_owner) {
SetLocalCompany(c->index);
break;
}
}
cur_company2.Restore();
assert(old_owner != _local_company);

When there's only one AI company and no human companies, there is no other company to move to when the AI company is reloading. The assert then triggers (in master, but not in 1.10.3).

The Reload AI is located in AI Debug window. It runs 2 commands:

OpenTTD/src/ai/ai_gui.cpp

Lines 1288 to 1293 in 4f8e7b2

case WID_AID_RELOAD_TOGGLE:
if (ai_debug_company == OWNER_DEITY) break;
/* First kill the company of the AI, then start a new one. This should start the current AI again */
DoCommandP(0, CCA_DELETE | ai_debug_company << 16 | CRR_MANUAL << 24, 0, CMD_COMPANY_CTRL);
DoCommandP(0, CCA_NEW_AI | ai_debug_company << 16, 0, CMD_COMPANY_CTRL);
break;

  • bankrupts company
  • start company
@James103
Copy link
Contributor

@James103 James103 commented Dec 27, 2020

The Reload AI is located in AI Debug window.

The same crash occurs if you write reloadai 1, reloadai 2, ... inside the console and hit enter to execute them.

@SamuXarick
Copy link
Contributor Author

@SamuXarick SamuXarick commented Dec 27, 2020

Got it.

OpenTTD/src/console_cmds.cpp

Lines 1236 to 1241 in 4f8e7b2

/* First kill the company of the AI, then start a new one. This should start the current AI again */
DoCommandP(0, CCA_DELETE | company_id << 16 | CRR_MANUAL << 24, 0,CMD_COMPANY_CTRL);
DoCommandP(0, CCA_NEW_AI | company_id << 16, 0, CMD_COMPANY_CTRL);
IConsolePrint(CC_DEFAULT, "AI reloaded.");

@James103
Copy link
Contributor

@James103 James103 commented Jan 18, 2021

The same crash occurs when doing the following:

  1. Start a dedicated server.
  2. Server: Execute startai
  3. Server: Execute save a.sav
  4. Start a client instance.
  5. Client: Open "Load Game" and navigate to where the newly saved a.sav is located.
  6. Client: Load a.sav
  7. Client: Open AI/GS Debug Window
  8. Client: Hit "Reload AI"
  9. Client: Crashes (same error as above)
@glx22
Copy link
Contributor

@glx22 glx22 commented Jan 18, 2021

So based on the steps, it crashes when you restart AI of a company with an active human player.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants