Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#4152 closed defect (fixed)

[PATCH] Schwarzwald tiny map - tile is undefined

Reported by: elexis Owned by: FeXoR
Priority: Should Have Milestone: Alpha 22
Component: Maps Keywords:
Cc: FeXoR, Niek Patch:

Description

As reported by bb today in irc and comment:12:ticket:2787, this error still occurs on schwarzwald with tiny mapsizes:

ERROR: JavaScript error: maps/random/heightmap/heightmap.js line 128
TypeError: tile is undefined
  distributeEntitiesByHeight@maps/random/heightmap/heightmap.js:128:1
  @maps/random/schwarzwald.js:266:78

Replay:

start {"settings":{"PlayerData":[{"Name":"elexis","Civ":"brit","Color":{"r":46,"g":46,"b":200},"AI":"","AIDiff":3,"Team":0},{"Name":"Player 2","Civ":"mace","Color":{"r":150,"g":20,"b":20},"AI":"","AIDiff":3,"Team":0},{"Name":"Player 3","Civ":"athen","Color":{"r":50,"g":165,"b":5},"AI":"","AIDiff":3,"Team":1}],"Seed":28622,"CheatsEnabled":true,"AISeed":64793,"Size":128,"GameType":"conquest","VictoryScripts":["scripts/TriggerHelper.js","scripts/ConquestCommon.js","scripts/Conquest.js"],"WonderDuration":1,"PopulationCap":300,"Ceasefire":0,"StartingResources":50000,"Name":"Schwarzwald","Description":"A forest heavy map with a lake in the middle and plenty of resources.","RatingEnabled":false,"RevealMap":true,"Script":"schwarzwald.js","BaseTerrain":["temp_grass_plants","temp_plants_bog"],"BaseHeight":0,"Preview":"schwarzwald.png","LockTeams":false,"TriggerScripts":["scripts/TriggerHelper.js","scripts/ConquestCommon.js","scripts/Conquest.js"],"CircularMap":true,"mapType":"random"},"map":"maps/random/schwarzwald","mapType":"random","mapPath":"maps/random/","mapFilter":"default","matchID":"134F4A8798F833C3","gameSpeed":1,"script":"schwarzwald.js","timestamp":"1464660017","engine_version":"0.0.21","mods":["mod","public"]}

Attachments (8)

heightmapFix2016-11-23.patch (1.5 KB ) - added by FeXoR 7 years ago.
Graciously handles arguments that doesn't contain any valid tile in distributeEntitiesByHeight
screenshot0056.jpg (76.1 KB ) - added by FeXoR 7 years ago.
Something's still very wrong
screenshot0057.jpg (72.4 KB ) - added by FeXoR 7 years ago.
For comparrison Aegean Sea, tiny, 2 Players, Seed 0
screenshot0058.jpg (58.0 KB ) - added by FeXoR 7 years ago.
And an empty map resized to tiny in Atlas
heightmapFix2016-11-26.patch (3.5 KB ) - added by FeXoR 7 years ago.
Fixes everything I could find in distributeEntitiesByHeight
heightmapFix2016-12-3.patch (3.4 KB ) - added by FeXoR 7 years ago.
Fixes as suggersted by elexis but the loop
heightmapFix2016-12-5.patch (3.3 KB ) - added by FeXoR 7 years ago.
Early continue suggested by elexis and Vladislav
heightmapFix2016-12-6.patch (3.7 KB ) - added by FeXoR 7 years ago.
Adjusted to mimo's suggestion and added optional argument playerID

Download all attachments as: .zip

Change History (26)

comment:1 by elexis, 8 years ago

Cc: FeXoR Niek added

by FeXoR, 7 years ago

Graciously handles arguments that doesn't contain any valid tile in distributeEntitiesByHeight

by FeXoR, 7 years ago

Attachment: screenshot0056.jpg added

Something's still very wrong

comment:2 by FeXoR, 7 years ago

The heightmap just before ExportMap() is 129x129 and should be correct. It seems the map border shadow is not exactly round. I'll still have to check if the arguments the function is called with in Schwarzwald are actually sane...

by FeXoR, 7 years ago

Attachment: screenshot0057.jpg added

For comparrison Aegean Sea, tiny, 2 Players, Seed 0

by FeXoR, 7 years ago

Attachment: screenshot0058.jpg added

And an empty map resized to tiny in Atlas

comment:3 by FeXoR, 7 years ago

Keywords: patch added; simple removed

comment:4 by FeXoR, 7 years ago

That map border shadow issue is likely a problem of my hardware

Last edited 7 years ago by FeXoR (previous) (diff)

by FeXoR, 7 years ago

Fixes everything I could find in distributeEntitiesByHeight

comment:5 by FeXoR, 7 years ago

The function distributeEntitiesByHeight is a lot faster now for later tries (splices points that became invalid due to placement) if the number of tries are high and the number of valid points is low. It is safe to say that at least one other function (getStartLocationsByHeightmap) is not entirely accurate (mixes tile coordinates with points so off by 0.5 tile width/2 horizontal engine space units). I'm not sure if that may produce errors (the error in the ticked didn't come from it but I fixed it anyways) but I'd like to fix those missmatches in this commit too. Any opinions?

comment:6 by FeXoR, 7 years ago

I'd say it's ready for review since the patch fixes all issues within that function.

comment:7 by FeXoR, 7 years ago

Keywords: review added

comment:8 by elexis, 7 years ago

Milestone: BacklogWork In Progress

Just few style things:

  • where != were
  • // Maybe better to -> would be nice to figure that out before and either remove the comment or replace it with a // TODO:
  • Comments should be on a separate line (recall the 80 character per line recommendation of @wiki:Coding_Conventions)
  • Those 2 if statements inside the loop could become inverted ("early continue")

comment:9 by FeXoR, 7 years ago

@elexis: Which 2 if statements (There are 2 for loops with 2+ if's in them ;p)

comment:10 by FeXoR, 7 years ago

Summary: Schwarzwald tiny map - tile is undefined[PATCH] Schwarzwald tiny map - tile is undefined

by FeXoR, 7 years ago

Attachment: heightmapFix2016-12-3.patch added

Fixes as suggersted by elexis but the loop

comment:11 by Stan, 7 years ago

Why don't you use let checkPointIndex ?

comment:12 by FeXoR, 7 years ago

@stanislas69: Huh? It's used twice AFAICS?

by FeXoR, 7 years ago

Attachment: heightmapFix2016-12-5.patch added

Early continue suggested by elexis and Vladislav

comment:13 by FeXoR, 7 years ago

Owner: set to FeXoR
Status: newassigned

comment:14 by mimo, 7 years ago

Not a review as I've not checked the functionnalities, but as regards the code:

line 126 to 136 could be replaced by

if (avoidPoints.every(ap => getDistance(x + 0.5, y + 0.5, ap.x, ap.y) > minDistance))
validPoints.push({ "x": x + 0.5, "y": y + 0.5 });

as every returns as soon as one of the elements does not fulfil the condition.

I don't see the full code for lines 153 to 166, but maybe we could also use every or some there too.

Personnally, i would move 140 to 147, and replace 145 by "return []". And the code is clear enough, so the comment line 141 could be removed.

by FeXoR, 7 years ago

Attachment: heightmapFix2016-12-6.patch added

Adjusted to mimo's suggestion and added optional argument playerID

comment:15 by elexis, 7 years ago

Keywords: review removed

comment:16 by FeXoR, 7 years ago

Resolution: fixed
Status: assignedclosed

In 19288:

Fixes a bug that caused an error when distributeEntitiesByHeight() in hightmap.js was called with arguments that didn't result in any return value.

Differential Revision: https://code.wildfiregames.com/D114
Revieved by: elexis
Fixed #4152.

comment:17 by FeXoR, 7 years ago

Keywords: patch removed

comment:18 by elexis, 7 years ago

Milestone: Work In ProgressAlpha 22

Thanks for the patch, that map is actually interesting to play on tiny mapsizes!

Note: See TracTickets for help on using tickets.