I think there are big memory leaks in cpp kit
here
void resetPlayerStates ()
{
...
players[0].cities.clear ();
...
}
cities is std::map<std::string, City *>
each turn we make new allocation
this->players[team].cities[cityid] = new lux::City (team, cityid, fuel, lightUpkeep);
but we never do smth like
delete players[team].cities[cityid];
(clear () doesn't do it for dynamic memory)
the same problem with std::vector<CityTile *> citytiles;
because of this, sometimes an error occurs in long games
RuntimeError: abort(RuntimeError: abort(Cannot enlarge memory arrays to size 16781312 bytes (OOM). Either (1) compile with -s INITIAL_MEMORY=X with X higher than the current value 16777216, (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ) at Error
I removed these pointers locally and this solved the problem.
...
std::vector<CityTile *> citytiles;
std::vector citytiles;
...
std::map<std::string, City *> cities;
std::map<std::string, City> cities;
...
Why were they needed?
I think there are big memory leaks in cpp kit here void resetPlayerStates () { ... players[0].cities.clear (); ... }
cities is std::map<std::string, City *> each turn we make new allocation this->players[team].cities[cityid] = new lux::City (team, cityid, fuel, lightUpkeep); but we never do smth like delete players[team].cities[cityid]; (clear () doesn't do it for dynamic memory)
the same problem with std::vector<CityTile *> citytiles;
because of this, sometimes an error occurs in long games RuntimeError: abort(RuntimeError: abort(Cannot enlarge memory arrays to size 16781312 bytes (OOM). Either (1) compile with -s INITIAL_MEMORY=X with X higher than the current value 16777216, (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ) at Error
I removed these pointers locally and this solved the problem. ...
Check it, please