wxColor and binary files do not like each other

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
nicoverduin
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Mar 07, 2017 2:11 pm

wxColor and binary files do not like each other

Postby nicoverduin » Sun Mar 19, 2017 3:32 pm

Hi,
I developed an application under Windows 7 with CodeBlocks and wxWidgets. Then I tried to port it to Ubuntu 32bits. That can be be quite challenging. One interesting phenomena I noticed was the following:
a) I have a struct contiaining char arrays, ints and a few wxColour objects. This is my settings file. Under windows it works fine but under Ubuntu the program crashes (return status = -1) when I try to access the wxColor objects in my loaded settings struct.
b) If I convert the wxColor objects to uint32_t (using GetRGB() ) and store these numbers in the settings and convert them back to wxColor it works fine.

I am using:
a) wxWidgets 3.0.2 under Ubuntu
b) CodeBlocks 16.1
all 32 bits.

Regards
Nico

User avatar
doublemax
Moderator
Moderator
Posts: 11291
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxColor and binary files do not like each other

Postby doublemax » Sun Mar 19, 2017 6:33 pm

Although you didn't show code, i can probably guess what you're doing wrong.

You can't just take the pointer to any struct/class and sizeof(your_struct) to read/write the binary data from/to a file. This can work, but most of the time it won't, because you can't know what the class does internally. E.g. it could allocate some memory on the heap and just store the pointer.
Use the source, Luke!

nicoverduin
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Mar 07, 2017 2:11 pm

Re: wxColor and binary files do not like each other

Postby nicoverduin » Mon Mar 20, 2017 6:57 am

That does make sense. I never dug into the wxColor class. So converting them to uint32_t makes them plain variables. Now the struct contains standard variable types (char arrays, uints etc) and works fine. Although it is funny that Windows gives no problems and Ubuntu does. But anyway, solved.... It is al part of the learning process :D


Return to “Platform Related Issues”

Who is online

Users browsing this forum: No registered users and 1 guest