Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Crash on LoadFromFile
Crash on LoadFromFile [message #11914] Mon, 01 October 2007 03:54 Go to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

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:

index.php?t=getfile&id=757&private=0



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?
  • Attachment: upp2.jpg
    (Size: 20.21KB, Downloaded 512 times)

[Updated on: Mon, 01 October 2007 03:56]

Report message to a moderator

Re: Crash on LoadFromFile [message #11916 is a reply to message #11914] Mon, 01 October 2007 09:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
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:

index.php?t=getfile&id=757&private=0



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

Mirek
Re: Crash on LoadFromFile [message #11923 is a reply to message #11916] Mon, 01 October 2007 13:39 Go to previous message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Finally I`ve got it, yes, SerializeRaw solved the problem. Looks so easy when it`s done. Certainly, need to get used to U++.
Thanx again.
Previous Topic: Transfer Semantics - Initializer list and copy constructors
Next Topic: is there a function to stop the program N milliseconds?
Goto Forum:
  


Current Time: Sat Apr 20 16:55:17 CEST 2024

Total time taken to generate the page: 1.03887 seconds