Hi! I'm using HGE for my program and I've stumbled upon a Access violation, the following is displayed in my output:
'2dlandzD.exe' (Win32): Loaded 'C:\WINDOWS\SysWOW64\avrt.dll'. Cannot find or open the PDB file.
First-chance exception at 0x52ADAD84 (msvcp100d.dll) in 2dlandzD.exe: 0xC0000005: Access violation writing location 0x00FFFFFF.
The program '[4120] 2dlandzD.exe' has exited with code 0 (0x0).
Sounds like either you overflowed a buffer or a destructor is giving you grief. Does BinaryUnit or BinaryHandler have non-trivial destructors?
You might want to take a look at the disassembly and see which call is failing.
class BinaryHandler
{
public:
BinaryHandler()
{
units = 0;
}
int units;
};
class BinaryUnit
{
public:
BinaryUnit()
{
unitName = "";
x = 0;
y = 0;
ownedBy = 0;
}
~BinaryUnit()
{
} < this is instead the next statement to be executed
string unitName;
float x;
float y;
int ownedBy;
};
These classes are located inside my "LevelEditorUnitHandler.h" and not the .cpp file.
Since I added destructors the error directed me to a different location which is pointed out in the above code.
EDIT: Now I got a reading violation instead of writing, this is driving me insane...
Ahh I get it now, but how would I resolve this? I believe you are not able to store strings in binary? So should i change this string into a char* since chars could easily be read?
should i change this string into a char* since chars could easily be read?
Do you want to write the characters of the string, or a pointer to the string?
You'll have to do the de/serialization yourself. Your code will end up looking somewhat like this:
1 2 3 4 5
size = read_32_bits(file);
unitName = read_string(file, size);
x = read_float(file);
y = read_float(file);
ownedBy = read_32_bits(file);
Alternatives: If you just want to save some data from your program and don't need to support an existing format, you can look at Google's Protobuf. It's a basically a compiler from a data specification language to C++ that generates a class with all the de/serialization stuff. The data specification looks somewhat like this:
1 2 3 4 5 6
message BinaryUnit{
required unitName = 1;
required float x = 2;
required float y = 3;
required int ownedBy = 4;
};