In XCode this code works fine, but on VS2013 Express I get an.
Unhandled exception at 0x5EA9DF62 (msvcp120d.dll) in Application.exe: 0xC0000005: Access violation writing location 0x00000003.
The C++ struct
struct FormatDesc {
std::string attrName;
AttrFormat type;
unsigned int size;
};
AS Registration
r = engine->RegisterObjectType("FormatDesc", sizeof(CaffApp::FormatDesc), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CDAK); assert(r >= 0);
r = engine->RegisterObjectBehaviour("FormatDesc", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(CaffGlue::Renderer::FormatDescCtor), asCALL_CDECL_OBJLAST); assert(r >= 0);
r = engine->RegisterObjectBehaviour("FormatDesc", asBEHAVE_LIST_CONSTRUCT, "void f(const int &in) {string, AttrFormat, uint}", asFUNCTION(CaffGlue::Renderer::FormatDescListCtor), asCALL_CDECL_OBJLAST); assert(r >= 0);
r = engine->RegisterObjectBehaviour("FormatDesc", asBEHAVE_CONSTRUCT, "void f(const FormatDesc &in)", asFUNCTION(CaffGlue::Renderer::FormatDescCCtor), asCALL_CDECL_OBJLAST); assert(r >= 0);
r = engine->RegisterObjectBehaviour("FormatDesc", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(CaffGlue::Renderer::FormatDescDotr), asCALL_CDECL_OBJLAST); assert(r >= 0);
r = engine->RegisterObjectProperty("FormatDesc", "string attrName", asOFFSET(CaffApp::FormatDesc, attrName)); assert(r >= 0);
r = engine->RegisterObjectProperty("FormatDesc", "AttrFormat type", asOFFSET(CaffApp::FormatDesc, type)); assert(r >= 0);
r = engine->RegisterObjectProperty("FormatDesc", "uint size", asOFFSET(CaffApp::FormatDesc, size)); assert(r >= 0);
The constructors and dtors
void FormatDescCtor(void *mem)
{
std::cout << "ctor" << std::endl;
new(mem) CaffApp::FormatDesc;
}
void FormatDescCCtor(const CaffApp::FormatDesc &other, void *mem)
{
std::cout << "cctor" << other.attrName << std::endl;
new((void*)mem) CaffApp::FormatDesc(other);
}
void FormatDescListCtor(const CaffApp::FormatDesc *self, void *mem)
{
std::cout << "list ctor" << self->attrName << std::endl;
new((void*)mem) CaffApp::FormatDesc{self->attrName, self->type, self->size};
}
void FormatDescDotr(void *mem)
{
std::cout << "dtor " << static_cast<CaffApp::FormatDesc*>(mem)->attrName << std::endl;
static_cast<CaffApp::FormatDesc*>(mem)->~FormatDesc();
}
The AS Code looks like this.
{
array<FormatDesc> vertFmt = {
{"inPosition", AttrFormat::FLOAT, 3},
{"inTexC", AttrFormat::FLOAT, 2},
{"inNormal", AttrFormat::FLOAT, 3}
};
} // scope
When running the application I get the output
ctor
list ctor inPosition
dtor inPosition
ctor
list ctor inTexC
dtor inTexC
ctor
list ctor inNormal
dtor inNormal
ctor
ctor
ctor
dtor inPosition // When array goes out of scope.
dtor inTexC
dtor inNormal
dtor inPosition // This seems odd, doens't always output though.
Any ideas?