mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-03 22:37:06 +02:00
BUGFIX: Fix "Router called before initialization" race (#1474)
If the game takes long enough to load, certain counters can become eligible to run as soon as Engine.start() runs. When this happens, eventually Router.page() is called, which throws an Error since Router isn't initialized yet. (Dropping a breakpoint before Engine.start() and waiting at least 30 seconds is enough to reliably repro, but I have seen this both live and in tests.) This fixes it so that Router.page() is valid immediately, returning a value of Page.LoadingScreen. It also removes the isInitialized field, since this is now redundant. Trying to switch pages is still an error, but that doesn't happen without user input, whereas checking the current page is quite common. This also consolidates a check for "should we show toasts" behind a function in Router, making the logic central and equal for a few usecases. This means (for instance) that the "autosave is disabled" logic won't run during infiltration. (The toast should have already been suppressed.)
This commit is contained in:
+4
-1
@@ -49,6 +49,7 @@ export enum ComplexPage {
|
||||
Location = "Location",
|
||||
ImportSave = "Import Save",
|
||||
Documentation = "Documentation",
|
||||
LoadingScreen = "Loading Screen", // Has no PageContext, and thus toPage() cannot be used
|
||||
}
|
||||
|
||||
// Using the same name as both type and object to mimic enum-like behavior.
|
||||
@@ -86,6 +87,7 @@ export type PageWithContext =
|
||||
| ({ page: ComplexPage.Location } & PageContext<ComplexPage.Location>)
|
||||
| ({ page: ComplexPage.ImportSave } & PageContext<ComplexPage.ImportSave>)
|
||||
| ({ page: ComplexPage.Documentation } & PageContext<ComplexPage.Documentation>)
|
||||
| { page: ComplexPage.LoadingScreen }
|
||||
| { page: SimplePage };
|
||||
|
||||
export interface ScriptEditorRouteOptions {
|
||||
@@ -95,9 +97,10 @@ export interface ScriptEditorRouteOptions {
|
||||
|
||||
/** The router keeps track of player navigation/routing within the game. */
|
||||
export interface IRouter {
|
||||
isInitialized: boolean;
|
||||
page(): Page;
|
||||
allowRouting(value: boolean): void;
|
||||
/** If messages/toasts are hidden on this page */
|
||||
hidingMessages(): boolean;
|
||||
toPage(page: SimplePage): void;
|
||||
toPage<T extends ComplexPage>(page: T, context: PageContext<T>): void;
|
||||
/** go to a preveious page (if any) */
|
||||
|
||||
Reference in New Issue
Block a user