Coder Social home page Coder Social logo

Game crashes at a given time about openloco HOT 11 OPEN

ilmoro93 avatar ilmoro93 commented on May 27, 2024
Game crashes at a given time

from openloco.

Comments (11)

duncanspumpkin avatar duncanspumpkin commented on May 27, 2024 2

So the question then begins how does it get an offset of 2 for the order insert position. The caller is sub_486ECF which is an ai function. Now if we look at sub_486ECF it is inserting orders for all the stations of an AiThought. And it doesn't bother to check if the order insert was successful! And if it was not successful then it will send an invalid order offset! So we now know why it is sending an offset 2. Its because there is a order insert that has failed. So now we need to find out why the first insert failed.

from openloco.

duncanspumpkin avatar duncanspumpkin commented on May 27, 2024 2

When we look at previous failed order inserts there is a curious failure just before with a vehicle trying to insert an order for a station it doesn't own! This sounds like our problem order. The station it is trying to insert an order for is station id 0. 0 is always a high chance for issues! Sounds like the ai doesn't have its stations correct in its thoughts.

from openloco.

duncanspumpkin avatar duncanspumpkin commented on May 27, 2024 2

Now the question becomes is the station id being incorrect in the ai a vanilla ai mistake or a OpenLoco mistake. The ai hasn't been fully implemented yet so its always slightly hard to diagnose but from what we have implemented you can see how a value of 0 could get set for the station id. It could happen if _lastPlacedTrackStationId is null. And that could happen if a station placement failed for some reason.

from openloco.

LeftofZen avatar LeftofZen commented on May 27, 2024 1

tested this on latest master, it crashes in OpenLoco::Vehicles::OrderManager::shiftOrdersRight()

its an out of bounds memory access, looks like it's caused from stack corruption.

in the frame of the calling function, OpenLoco::Vehicles::OrderManager::insertOrder(), shiftOrdersRight is called with params (0+2, 2) which is just (2, 2). in the frame of shiftOrdersRight however, the offsetToShiftFrom is 280, not 2, which is causing the problem. not sure what is causing it though, other than some funky stack corruption

from openloco.

duncanspumpkin avatar duncanspumpkin commented on May 27, 2024 1

One question: what is it an order? Is it when a company purchases a vehicle? And the order table?

Orders are what you give a vehicle to describe its route. It will be things like stop at this waypoint, stop at this station, wait for this type, unload this type. All the orders for every vehicle are stored in one big table this is split into individual slots for each vehicle. Annoyingly even though you can only have 64 orders per vehicle the order table for a vehicle is variable size. So you need to shift everyone's order around whenever you insert or remove an order. If you mess this up you get issues...

In this save a vehicle with a size 1 order table (i.e. no orders) is trying to insert an order at offset 2 which is impossible the only insert position is offset 0.

from openloco.

ilmoro93 avatar ilmoro93 commented on May 27, 2024

I have lost some autosaves because they were overwritten, but I have this slightly older save which doesn't crash: 2nd october.zip.
However, I can't understand the difference between the two saves which produces the crash.

from openloco.

ilmoro93 avatar ilmoro93 commented on May 27, 2024

I have tried to debug as far as I can and I get that when the crash happens:

  • the head parameter in insertOrder() has vehicletype tram
  • in OpenLoco::GameCommands::sub_470312(), which is called by the command createVehicle, head->orderTableOffset = OrderManager::orderTableLength(); which is 278

I noticed that the crash happens when the company called Thin Lines is building a tram track near Finway. The track seems finished. I think that maybe Thin Lines is trying to build a passenger stop in the same point where Finway Transport already has one (Finway West). I don't know if this can be related to the problem.

However, at this point I imagine Thin Lines is going to create a tram and at this point the game crashes.

One question: what is it an order? Is it when a company purchases a vehicle? And the order table?

P.S. In the saved game here:

I have lost some autosaves because they were overwritten, but I have this slightly older save which doesn't crash: 2nd october.zip. However, I can't understand the difference between the two saves which produces the crash.

Thin Lines is not building that tram track and the game is not crashing. This is not a proof but maybe an hint.

from openloco.

ilmoro93 avatar ilmoro93 commented on May 27, 2024

Thanks @duncanspumpkin for all the details! In the end it seems something like this is happening:

I think that maybe Thin Lines is trying to build a passenger stop in the same point where Finway Transport already has one (Finway West).

So we need to understand what happens when one ai tries to place something which is in conflict with another ai.
Usually when you as a player build something near one ai, you are restricted to build where the ai is planning to build, so I think that every ai reserves all the blocks it needs to build its route. I imagine that also one ai can't plan a route where another ai has reserved some blocks.

The peculiar fact in this save is that there are no conflicts in the route, since both ai can use the same road, but only in the station placement. It could be that the stations conflict is not checked when Thin Lines ai is planning its station.

from openloco.

ilmoro93 avatar ilmoro93 commented on May 27, 2024

I still have one older save of that game. I've created this save Thin Lines 11th October.zip because Thin Lines starts building Tram Track near Finway on 12th October, so maybe this can be useful. I have tried to look into // 0x00430762 void aiThink(const CompanyId id) and put some breakpoints but I can't find anything about the route planning.

from openloco.

duncanspumpkin avatar duncanspumpkin commented on May 27, 2024

I still have one older save of that game. I've created this save Thin Lines 11th October.zip because Thin Lines starts building Tram Track near Finway on 12th October, so maybe this can be useful. I have tried to look into // 0x00430762 void aiThink(const CompanyId id) and put some breakpoints but I can't find anything about the route planning.

Unfortunately we've not implemented the function that does the insert order code. But we need to i think to investigate the station creation ai code. Afair there are multiple bits of ai code that does station creation so it's really not easy to work out.

from openloco.

ilmoro93 avatar ilmoro93 commented on May 27, 2024

I wrote route previously but what I mean is the road/rail line with the stations, not the route as the sequence of orders. I imagine that at some point there should be an object containing the stations and the array of road/rail sections needed to connect them and that this object is validated. But this is only my idea.

from openloco.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.