Hey, I'm experiencing a crash in free() on exit. I'm lost, so maybe you can tell me if I did something wrong in the bindings?
struct Tile
{
b2Fixture* edgeN, *edgeS, *edgeW, *edgeE;
u16 blobid1, blobid2;
u16 backblobid1, backblobid2;
TileType type;
u16 flags;
u8 support;
u8 dirt;
u8 light;
u8 noise;
u8 damage;
Tile();
Tile( const TileType t );
Tile( Tile& t );
Tile& operator=(const Tile& t)
{
type = t.type;
support = t.support;
dirt = t.dirt;
light = t.light;
flags = t.flags;
noise = t.noise;
damage = t.damage;
return *this;
}
bool operator==(const Tile& rhs)
{
return (type == rhs.type); // legacy
}
bool operator==(const Tile& rhs) const
{
return (type == rhs.type); // legacy
}
enum TileFlags {
SPARE_0 = 0x01,
BACKGROUND = 0x02,
SOLID = 0x04,
LADDER = 0x08,
LIGHT_PASSES = 0x10,
WATER_PASSES = 0x20,
FLAMMABLE = 0x40,
PLATFORM = 0x80,
LIGHT_SOURCE = 0x100,
MIRROR = 0x200,
FLIP = 0x400,
ROTATE = 0x800,
SPARE_1 = 0x1000,
SPARE_2 = 0x2000,
SPARE_3 = 0x4000,
SPARE_4 = 0x8000
};
};
The binding:
r = engine->RegisterObjectType("Tile", sizeof(Tile), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CA); assert(r >= 0);
// Set Vec2f behaviour.
// Initialisation and deinitialisation
r = engine->RegisterObjectBehaviour("Tile", asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONPR(constructorTile,
(void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
r = engine->RegisterObjectBehaviour("Tile", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(deconstructorTile),
asCALL_CDECL_OBJLAST); assert(r >= 0);
r = engine->RegisterObjectProperty("Tile", "TileType type", asOFFSET(Tile, type)); assert(r >= 0);
r = engine->RegisterObjectProperty("Tile", "u8 support", asOFFSET(Tile, support)); assert(r >= 0);
r = engine->RegisterObjectProperty("Tile", "u8 dirt", asOFFSET(Tile, dirt)); assert(r >= 0);
r = engine->RegisterObjectProperty("Tile", "u8 light", asOFFSET(Tile, light)); assert(r >= 0);
r = engine->RegisterObjectProperty("Tile", "u16 flags", asOFFSET(Tile, flags)); assert(r >= 0);
r = engine->RegisterObjectProperty("Tile", "u8 damage", asOFFSET(Tile, damage)); assert(r >= 0);
r = engine->RegisterObjectProperty("Tile", "u8 noise", asOFFSET(Tile, noise)); assert(r >= 0);
r = engine->RegisterObjectProperty("Tile", "u16 blobid1", asOFFSET(Tile, blobid1)); assert(r >= 0);
r = engine->RegisterObjectProperty("Tile", "u16 blobid2", asOFFSET(Tile, blobid2)); assert(r >= 0);
r = engine->RegisterObjectProperty("Tile", "u16 backblobid1", asOFFSET(Tile, backblobid1)); assert(r >= 0);
r = engine->RegisterObjectProperty("Tile", "u16 backblobid2", asOFFSET(Tile, backblobid2)); assert(r >= 0);
r = engine->RegisterObjectMethod("Tile", "Tile& opAssign(const Tile &in)",
asMETHODPR(Tile, operator=, (const Tile&), Tile&),
asCALL_THISCALL); assert(r >= 0);
r = engine->SetDefaultNamespace("Tile"); assert( r >= 0 );
r = engine->RegisterEnum("TileFlags"); assert( r >= 0 );
r = engine->RegisterEnumValue("TileFlags", "SPARE_0", Tile::SPARE_0); assert( r >= 0 );
r = engine->RegisterEnumValue("TileFlags", "SOLID", Tile::SOLID); assert( r >= 0 );
r = engine->RegisterEnumValue("TileFlags", "BACKGROUND", Tile::BACKGROUND); assert( r >= 0 );
r = engine->RegisterEnumValue("TileFlags", "LADDER", Tile::LADDER); assert( r >= 0 );
r = engine->RegisterEnumValue("TileFlags", "LIGHT_PASSES", Tile::LIGHT_PASSES); assert( r >= 0 );
r = engine->RegisterEnumValue("TileFlags", "WATER_PASSES", Tile::WATER_PASSES); assert( r >= 0 );
r = engine->RegisterEnumValue("TileFlags", "FLAMMABLE", Tile::FLAMMABLE); assert( r >= 0 );
r = engine->RegisterEnumValue("TileFlags", "PLATFORM", Tile::PLATFORM); assert( r >= 0 );
r = engine->RegisterEnumValue("TileFlags", "LIGHT_SOURCE", Tile::LIGHT_SOURCE); assert( r >= 0 );
r = engine->RegisterEnumValue("TileFlags", "MIRROR", Tile::MIRROR); assert( r >= 0 );
r = engine->RegisterEnumValue("TileFlags", "FLIP", Tile::FLIP); assert( r >= 0 );
r = engine->RegisterEnumValue("TileFlags", "ROTATE", Tile::ROTATE); assert( r >= 0 );
r = engine->RegisterEnumValue("TileFlags", "SPARE_1", Tile::SPARE_1); assert( r >= 0 );
r = engine->RegisterEnumValue("TileFlags", "SPARE_2", Tile::SPARE_2); assert( r >= 0 );
r = engine->RegisterEnumValue("TileFlags", "SPARE_3", Tile::SPARE_3); assert( r >= 0 );
r = engine->RegisterEnumValue("TileFlags", "SPARE_4", Tile::SPARE_4); assert( r >= 0 );
r = engine->SetDefaultNamespace(""); assert( r >= 0 );
And some functions that use it:
r = engine->RegisterObjectMethod("CMap", "void server_SetTile(Vec2f pos, const Tile &in tile)",
asMETHODPR( CMap, server_SetTile, (Vec2f, const Tile&), void),
asCALL_THISCALL); assert(r >= 0);
r = engine->RegisterObjectMethod("CMap", "Tile getTile( Vec2f pos ) const",
asMETHODPR( CMap, getTile, (Vec2f) const, Tile),
asCALL_THISCALL); assert(r >= 0);
r = engine->RegisterObjectMethod("CMap", "Tile getTileFromTileSpace( Vec2f pos ) const",
asMETHODPR( CMap, getTile_Vec2f, (Vec2f) const, Tile),
asCALL_THISCALL); assert(r >= 0);
r = engine->RegisterObjectMethod("CMap", "Tile getTile( u32 offset ) const",
asMETHODPR( CMap, getTile, (u32) const, Tile),
asCALL_THISCALL); assert(r >= 0);