Skip to content

Commit

Permalink
fix memory leak in GLRewardNode, #153
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Apr 9, 2024
1 parent ccc67e1 commit 6abe67c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 12 additions & 2 deletions js/linegame/view/GLRewardNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import graphingLines from '../../graphingLines.js';
import PointSlopeEquationNode from '../../pointslope/view/PointSlopeEquationNode.js';
import SlopeInterceptEquationNode from '../../slopeintercept/view/SlopeInterceptEquationNode.js';
import NotALine from '../model/NotALine.js';
import { RewardNodeFunction } from './ResultsNode.js';

// constants
const NUMBER_OF_NODES = 150;
Expand All @@ -47,8 +48,17 @@ const AIRPLANE_SCALE = 1.76;

export default class GLRewardNode extends RewardNode {

public constructor( rewardNodes: Node[] ) {
super( { nodes: rewardNodes } );
public constructor( level: number, rewardNodeFunctions: RewardNodeFunction[] ) {

const rewardNodes = rewardNodeFunctions[ level ]();

super( {
nodes: rewardNodes
} );

// Dispose of rewardNodes because they may be linked to LocalizeStringProperty, ProfileColorProperty, etc.
// rewardNodes contains duplicates!
this.disposeEmitter.addListener( () => _.uniq( rewardNodes ).forEach( node => node.dispose() ) );
}

/**
Expand Down
6 changes: 1 addition & 5 deletions js/linegame/view/ResultsNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,8 @@ export default class ResultsNode extends Node {

// game reward, shown for perfect score (or with 'reward' query parameter)
if ( model.isPerfectScore() || GLQueryParameters.showReward ) {

audioPlayer.gameOverPerfectScore();

const level = model.levelProperty.value;
const rewardNodes = rewardNodeFunctions[ level ]();
this.rewardNode = new GLRewardNode( rewardNodes );
this.rewardNode = new GLRewardNode( model.levelProperty.value, rewardNodeFunctions );
this.addChild( this.rewardNode );
}
else {
Expand Down

0 comments on commit 6abe67c

Please sign in to comment.