etoa / etoa-gui

EtoA Game GUI
https://etoa.ch
GNU Affero General Public License v3.0
10 stars 7 forks source link

eventhandler Config::get returns "-nan" for param1 on nonexisting/default keys #525

Open river-etoa opened 2 years ago

river-etoa commented 2 years ago

std::string Config::get returns -nan and this fucks up Config::nget, which ultimately results in

ERR: MySQL: Unexpected query error: Unknown column 'nan' in 'field list'

it works for value (p0) and param2 for some reason but not for param1.

issue is in default constructor / return values for std::map<std::string, int> sConfig and std::vector<std::vector<std::string> > cConfig due to incorrect assumptions on how c++ container initialization, object assignment and default return values work.

All this gets triggered by the underlying incorrect assumption in the eventhandler that every possible config value has an entry in the DB, whereas the frontend only seems to put non-default config values in the DB and uses the default values from XML in some places(?).

river-etoa commented 2 years ago

this took me 4h to find ffs

A-A-G commented 2 years ago

Wouldn't a better fix be writing also default values to the DB?

river-etoa commented 2 years ago

Yes, but:

the current eventhandler code assumes cConfig is always a vector of size 3, which is broken in Config::get without this patch. better idea would be to refactor the config code.

river-etoa commented 2 years ago

did some code refactor with ee21169. now uses a single map, and the value is a fixed-size array instead of a var-length vector to avoid undefined elements.