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
wxColor and binary files do not like each other
-
- 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
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.
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!
-
- 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
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