Skip to content

Commit

Permalink
fix: Attempt to fix null pointer passed to rust
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark committed Jul 21, 2024
1 parent 5c072b5 commit a369786
Showing 1 changed file with 109 additions and 98 deletions.
207 changes: 109 additions & 98 deletions packages/tosu/src/entities/GamePlayData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export class GamePlayData extends AbstractEntity {
isDefaultState: boolean = true;
isKeyOverlayDefaultState: boolean = true;

PerformanceAttributes: rosu.PerformanceAttributes;
GradualPerformance: rosu.GradualPerformance | null;
PerformanceAttributes: rosu.PerformanceAttributes | undefined;
GradualPerformance: rosu.GradualPerformance | undefined;

Retries: number;
PlayerName: string;
Expand Down Expand Up @@ -115,7 +115,6 @@ export class GamePlayData extends AbstractEntity {
this.isReplayUiHidden = false;

this.previousPassedObjects = 0;
this.GradualPerformance = null;

// below is gata that shouldn't be reseted on retry
if (isRetry === true) {
Expand Down Expand Up @@ -557,113 +556,125 @@ export class GamePlayData extends AbstractEntity {
}

private updateStarsAndPerformance() {
const t1 = performance.now();
if (!config.calculatePP) {
wLogger.debug(
'GD(updateStarsAndPerformance) pp calculation disabled'
);
return;
}
try {
const t1 = performance.now();
if (!config.calculatePP) {
wLogger.debug(
'GD(updateStarsAndPerformance) pp calculation disabled'
);
return;
}

const { allTimesData, beatmapPpData, menuData } =
this.osuInstance.getServices([
'allTimesData',
'beatmapPpData',
'menuData'
]);
const { allTimesData, beatmapPpData, menuData } =
this.osuInstance.getServices([
'allTimesData',
'beatmapPpData',
'menuData'
]);

if (!allTimesData.GameFolder) {
wLogger.debug(
'GD(updateStarsAndPerformance) game folder not found'
);
return;
}
if (!allTimesData.GameFolder) {
wLogger.debug(
'GD(updateStarsAndPerformance) game folder not found'
);
return;
}

const currentBeatmap = beatmapPpData.getCurrentBeatmap();
if (!currentBeatmap) {
wLogger.debug(
"GD(updateStarsAndPerformance) can't get current map"
);
return;
}
const currentBeatmap = beatmapPpData.getCurrentBeatmap();
if (!currentBeatmap) {
wLogger.debug(
"GD(updateStarsAndPerformance) can't get current map"
);
return;
}

const currentState = `${menuData.MD5}:${menuData.MenuGameMode}:${this.Mods}:${menuData.MP3Length}`;
const isUpdate = this.previousState !== currentState;

// update precalculated attributes
if (
isUpdate ||
!this.GradualPerformance ||
!this.PerformanceAttributes
) {
if (this.GradualPerformance) this.GradualPerformance.free();
if (this.PerformanceAttributes) this.PerformanceAttributes.free();

const difficulty = new rosu.Difficulty({ mods: this.Mods });
this.GradualPerformance = new rosu.GradualPerformance(
difficulty,
currentBeatmap
);
const currentState = `${menuData.MD5}:${menuData.MenuGameMode}:${this.Mods}:${menuData.MP3Length}`;
const isUpdate = this.previousState !== currentState;

this.PerformanceAttributes = new rosu.Performance({
mods: this.Mods
}).calculate(currentBeatmap);
// update precalculated attributes
if (
isUpdate ||
!this.GradualPerformance ||
!this.PerformanceAttributes
) {
if (this.GradualPerformance) this.GradualPerformance.free();
if (this.PerformanceAttributes)
this.PerformanceAttributes.free();

const difficulty = new rosu.Difficulty({ mods: this.Mods });
this.GradualPerformance = new rosu.GradualPerformance(
difficulty,
currentBeatmap
);

this.previousState = currentState;
}
this.PerformanceAttributes = new rosu.Performance({
mods: this.Mods
}).calculate(currentBeatmap);

if (!this.GradualPerformance && !this.PerformanceAttributes) return;

const passedObjects = calculatePassedObjects(
this.Mode,
this.Hit300,
this.Hit100,
this.Hit50,
this.HitMiss,
this.HitKatu,
this.HitGeki
);

const offset = passedObjects - this.previousPassedObjects;
if (offset <= 0) return;

const scoreParams: rosu.ScoreState = {
maxCombo: this.MaxCombo,
misses: this.HitMiss,
n50: this.Hit50,
n100: this.Hit100,
n300: this.Hit300,
nKatu: this.HitKatu,
nGeki: this.HitGeki
};
this.previousState = currentState;
}

const curPerformance = this.GradualPerformance.nth(
scoreParams,
offset - 1
)!;
if (!this.GradualPerformance && !this.PerformanceAttributes) return;

const fcPerformance = new rosu.Performance({
mods: this.Mods,
misses: 0,
accuracy: this.Accuracy
}).calculate(this.PerformanceAttributes);
const t2 = performance.now();

if (curPerformance) {
beatmapPpData.updateCurrentAttributes(
curPerformance.difficulty.stars,
curPerformance.pp
const passedObjects = calculatePassedObjects(
this.Mode,
this.Hit300,
this.Hit100,
this.Hit50,
this.HitMiss,
this.HitKatu,
this.HitGeki
);
}

if (fcPerformance) {
beatmapPpData.currAttributes.fcPP = fcPerformance.pp;
}
const offset = passedObjects - this.previousPassedObjects;
if (offset <= 0) return;

const scoreParams: rosu.ScoreState = {
maxCombo: this.MaxCombo,
misses: this.HitMiss,
n50: this.Hit50,
n100: this.Hit100,
n300: this.Hit300,
nKatu: this.HitKatu,
nGeki: this.HitGeki
};

this.previousPassedObjects = passedObjects;
const curPerformance = this.GradualPerformance.nth(
scoreParams,
offset - 1
)!;

const fcPerformance = new rosu.Performance({
mods: this.Mods,
misses: 0,
accuracy: this.Accuracy
}).calculate(this.PerformanceAttributes);
const t2 = performance.now();

if (curPerformance) {
beatmapPpData.updateCurrentAttributes(
curPerformance.difficulty.stars,
curPerformance.pp
);
}

if (fcPerformance) {
beatmapPpData.currAttributes.fcPP = fcPerformance.pp;
}

this.previousPassedObjects = passedObjects;

wLogger.debug(
`GD(updateStarsAndPerformance) [${(t2 - t1).toFixed(2)}ms] elapsed time`
);

wLogger.debug(
`GD(updateStarsAndPerformance) [${(t2 - t1).toFixed(2)}ms] elapsed time`
);
this.resetReportCount('GD(updateStarsAndPerformance)');
} catch (exc) {
this.reportError(
'GD(updateStarsAndPerformance)',
10,
`GD(updateStarsAndPerformance) ${(exc as any).message}`
);
wLogger.debug(exc);
}
}
}

0 comments on commit a369786

Please sign in to comment.