Mindtraveller wrote on Sun, 30 September 2007 21:54
Proceeding with U++ usage led me to another strange moment, which I couldn`t solve with docs&forum search.
Loading config in a closest to examples manner, crashes application with assert in debug mode:
May be I`m doing something wrong, but I don`t see any difference between my code and docs-how-it`s-done-right:
#define CONFIG_FILE "config."
struct Config
{
wxBaud baud;
wxParity parity;
int com;
int wordlen;
int stopbits;
int addr;
void Serialize(Stream& s)
{
s.Put(&baud, sizeof(baud));
s.Put(&parity, sizeof(parity));
s % com % wordlen % stopbits % addr;
}
};
Config config;
void Kran::LoadAndInit()
{
if (!LoadFromFile(config, ConfigFile(CONFIG_FILE)))
{
config.baud = wxBAUD_38400;
config.com = 1;
config.parity = wxPARITY_NONE;
config.wordlen = 8;
config.stopbits = 1;
config.addr = 1;
}
This code causes assertion in LoadFromFile.
Could you please help with this?
You cannot Put (in Serialize) when LoadFromFile...
The issue is a little bit complex, but the quick fix is to use SerializeRaw instead of Put (that will provide raw binary load if loading and raw binary write if storing).