> x.exe!memcpy(unsigned char * dst=0xcdcdcdcd, unsigned char * src=0x04ca9f14, unsigned long count=13) Line 232 Asm x.exe!std::char_traits<char>::copy(char * _First1=0xcdcdcdcd, const char * _First2=0x04ca9f14, unsigned int _Count=13) Line 497 + 0x11 bytes C++ x.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _Right="Camera_static", unsigned int _Roff=0, unsigned int _Count=4294967295) Line 904 + 0x1e bytes C++ x.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _Right="Camera_static") Line 889 C++ x.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::operator=(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _Right="Camera_static") Line 765 C++ x.exe!X::bspEntity::operator=(const X::bspEntity & __that={...}) + 0x2f bytes C++ x.exe!X::XBSP::XS_getEntityName(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & name="CameraPosition0", X::bspEntity & ret={...}) Line 2337 C++
Which in this case is a problem with std::string that is to be returned into the angelscript. There is no problem when i remove std::string from the structure definition, but i need those strings in the structure for later in-script usage.
The std::strings are marked as <bad-ptr's> in debugger,
[23026546] [] Error, Type tEntityis missing behaviours (Line 0/0) [23026546] [] A non-pod value type must have the default constructor and destructor behaviours (Line 0/0) [23026546] [] Error, Invalid configuration (Line 0/0)
Ps. i changed the name from bspEntity to tEntity meantime to fit to the engine requirements.
the application crashes only when a std::string to AS is returned, all other types (int,floats,... , CVector3 and other defined within my engine) are returned OK.
As the tEntity struct contains std::strings, you must not register it with asOBJ_POD. You must also register the asBEHAVE_CONSTRUCT and asBEHAVE_DESTRUCT behaviours for the type to properly initialize the members and release the memory of the strings when the object is destroyed.
#include <new> // placement new void tEntity_Construct(tEntity *o) { // Call the constructor to initialize the already allocated memory new(o) tEntity; }
void tEntity_Destruct(tEntity *o) { // Call the destructor to release the memory that the members hold o->~tEntity(); }