i had encountered with a little problem which are confused me... I show my code at C++ and VS 2010. I have same code at pure C and it is works. My code don`t work. Why?
Why code line Level->Rooms = new tr2_room[Level->NumRooms]; crashes.
typedef signed char bit8; // 8-bit, signed
typedef signed short int bit16; // 16-bit, signed
typedef signed long int bit32; // 32-bit, signed
typedef unsigned char bitu8; // 8-bit, unsigned
typedef unsigned short int bitu16; // 16-bit, unsigned
typedef unsigned long int bitu32; // 32-bit, unsigned
struct tr2_room {
tr2_room_info info; // where the room exists, in world coordinates
bitu32 NumDataWords; // number of data words (bitu16)
bitu8 *Data; // the raw data from which the rest of this is derived
tr2_room_data RoomData; // the room mesh
bitu16 NumPortals; // number of visibility portals that leave this room
tr2_room_portal *Portals; // list of visibility portals
bitu16 NumZsectors; // width of sector list
bitu16 NumXsectors; // height of sector list
tr2_room_sector *SectorList; // list of sectors in this room
bit16 Intensity1,
Intensity2,
LightMode;
bitu16 NumLights; // number of lights in this room
tr2_room_light *Lights; // list of lights
bitu16 NumStaticMeshes; // number of static meshes
tr2_room_staticmesh *StaticMeshes; // static meshes
bit16 AlternateRoom;
bit16 Flags; // 0x0001 - room is filled with water
// 0x0020 - Lara's ponytail gets blown by the wind
};
struct tr2_level {
char *FileName; // filename (not in .TR2 file)
bitu32 Version; // .TR2 file version
TR2_Version_type EngineVersion; // TombRaider_1, TombRaider_2, TombRaider_3
tr2_colour Palette8[256]; // 8-bit palette
bitu32 Palette16[256]; // 16-bit palette
bitu32 NumTextiles; // number of textiles
tr2_textile8 *Textile8; // 8-bit (palettised) textiles
tr2_textile16 *Textile16; // 16-bit (ARGB) textiles
bitu32 UnknownT; // 32-bit unknown (always 0 in real TR2 levels)
bitu16 NumRooms; // number of rooms in this level
tr2_room *Rooms; // list of rooms
};
tr2_level *Level;
Level = new tr2_level;
ZeroMemory(Level, sizeof(tr2_level));
//read number of rooms of game level
TR2fread(&Level->NumRooms, sizeof(Level->NumRooms), 1, fp);
//------------------------------------------
//------------------------------------------
//next line crashes with bad_alloc memory
Level->Rooms = new tr2_room[Level->NumRooms];
//------------------------------------------
//------------------------------------------
ZeroMemory(Level->Rooms, Level->NumRooms * sizeof(tr2_room));
Thanks in advance!












