Opened 9 years ago

Closed 9 years ago

Last modified 9 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 9 years ago.
sry typo in last patch

Download all attachments as: .zip

Change History (9)

comment:1 by elexis, 9 years ago

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 by elexis, 9 years ago

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 by elexis, 9 years ago

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 by elexis, 9 years ago

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 by elexis, 9 years ago

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 by Itms, 9 years ago

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 :)

by elexis, 9 years ago

sry typo in last patch

comment:7 by leper, 9 years ago

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 by leper, 9 years ago

Keywords: review removed

Thanks for the patch.

Note: See TracTickets for help on using tickets.