Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#3149 closed defect (fixed)

[PATCH] Clicking CC in Observer mode causes undefined mirage error

Reported by: elexis Owned by: leper
Priority: Nice to Have Milestone: Alpha 19
Component: UI & Simulation Keywords: patch
Cc: Patch:

Description

Each time I click a civic centre as observer, the following error appears. This happens on svn, a17 and a18.

WARNING: JavaScript warning: simulation/components/Fogging.js line 160
reference to undefined property this.miraged[player]

Reproduce by hosting and joining as observer in a second instance of 0ad and then clicking the CC.

Attachments (1)

ticket3149_observer_undefined_mirage.patch (1.2 KB) - added by elexis 4 years ago.
sry typo in last patch

Download all attachments as: .zip

Change History (9)

comment:1 Changed 4 years ago by elexis

The error appears only the first time one clicks the CC in observer mode. The error also appears if the CC is not built yet (nomad map).

comment:2 Changed 4 years ago by elexis

The error occurs in the last line of this function in simulation/components/Fogging.js

Fogging.prototype.IsMiraged = function(player)
{
	if (player >= this.mirages.length)
		return false;

	return this.miraged[player];
};

comment:3 Changed 4 years ago by elexis

This error also happens if the player is defeated and the CC becomes gaia before it is built (don't ask how that happened...)

In simulation/components/Fogging.js (line 302-309) there is this call to the function above:

	var cmpFogging = Engine.QueryInterface(ent, IID_Fogging);
	if (cmpFogging)
	{
		if (cmpFogging.IsMiraged(player))
			ret.fogging = {"mirage": cmpFogging.GetMirage(player)};
		else
			ret.fogging = {"mirage": null};
	}

If you add the following line before the call to cmpFogging.IsMiraged?(player),

		error("TEST");

then "TEST" will appear right before the error.

comment:4 Changed 4 years ago by elexis

If you change the debug message in simulation/components/Fogging.js to

error("TEST" + player);

then you can see that the player number is -1 (the number of the observer right?).

comment:5 Changed 4 years ago by elexis

Keywords: review added
Summary: Clicking CC in Observer mode causes undefined mirage error[PATCH] Clicking CC in Observer mode causes undefined mirage error

comment:6 Changed 4 years ago by Itms

Component: Core engineUI & Simulation
Keywords: patch added

Hello elexis, the patch should fix the error, but it would be better to fix WasSeen, GetMirage and OnVisibilityChanged the same way, to avoid other possible failures.

While you're at it, you might change WasSeen to test against this.mirages.length, for consistency with the other functions.

Thanks for working on a patch :)

Changed 4 years ago by elexis

sry typo in last patch

comment:7 Changed 4 years ago by leper

Owner: set to leper
Resolution: fixed
Status: newclosed

In 16484:

Refine checks for invalid player ids for mirages. Patch by elexis. Fixes #3149.

comment:8 Changed 4 years ago by leper

Keywords: review removed

Thanks for the patch.

Note: See TracTickets for help on using tickets.