Sign in to follow this  
PhilCK

Unhandled exception On VS2013

Recommended Posts

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?

Edited by PhilCK

Share this post


Link to post
Share on other sites

Your registration is asOBJ_APP_CLASS_CDAK, but it looks like you didn't register an assignment. Any mismatch in these flags tends to cause strange behavior, but I'm not sure if any assignments would be used for this code. The asOBJ_POD flag may also be conflicting here.

Edited by ThyReaper

Share this post


Link to post
Share on other sites

Changing to 

asOBJ_VALUE | asOBJ_APP_CLASS_CDK

 gives me the error...

"There is no copy operator for the type 'FormatDesc' available"

Share this post


Link to post
Share on other sites

I'm pretty sure this type needs to be registered with asOBJ_APP_CLASS_CDAK (since the string member has all of these). If you wish to avoid guess work, use the GetTypeTraits<FormatDesc>() from the helper add-on.

 

The type must definitely not be registered as a POD type since it would be causing error if the members are accessed without proper initialization first, and the type cannot be copied through a bitwise copy.

 

The message "There is no copy operator for the type 'FormatDesc' available" is telling you that you need to register the copy operator for the FormatDesc type. The copy operator is the opAssign method (you're not using the latest version of AngelScript, or the message would have read "No appropriate opAssign method found in 'FormatDesc'").

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this