HELP ME, A QUESTION ABOUT ASCSCRIPT CLASS
KNIGHTS: I DEFINE A STRUCT IN C++: struct stMessage{ public: int msg; int Param1, Param2, Param3; int Param4; asCScriptString *String1, *String2 ; }; THEN I REGISTER THE STRUCT IN C++ int r; r = engine->RegisterObjectType("stMessage", sizeof(stMessage), asOBJ_CLASS); assert( r>=0 ); r = engine->RegisterObjectProperty("stMessage", "int msg", offsetof(stMessage, msg)); assert( r>=0 ); r = engine->RegisterObjectProperty("stMessage", "int Param1", offsetof(stMessage, Param1)); assert( r>=0 ); r = engine->RegisterObjectProperty("stMessage", "int Param2", offsetof(stMessage, Param2)); assert( r>=0 ); r = engine->RegisterObjectProperty("stMessage", "int Param3", offsetof(stMessage, Param3)); assert( r>=0 ); r = engine->RegisterObjectProperty("stMessage", "string@ String1", offsetof(stMessage, String1)); assert( r>=0 ); r = engine->RegisterObjectProperty("stMessage", "string@ String2", offsetof(stMessage, String2)); assert( r>=0 ); SUCESSED. THEN IN ANGELSCRIPT: void dosome() { stMessage newmsg; newmsg.msg = 0; newmsg.Param1 = 101; newmsg.Param2 = 200; newmsg.Param3 = 500; @newmsg.String1 = @string("ha"); MessageQueue.InsertMessage(newmsg); } ERROR HAPPENED, BY DEBUG ,I FIND ERROR HAPPENED IN void asCScriptString::Release() { if( --refCount == 0 )----->ERROR { // Manually call the destructor, then free the memory so that we match how the memory was allocated this->~asCScriptString(); delete[] (char*)this; } } WHY?
You have not provided a default constructor for your structure, thus the String1 and String2 members will hold random values, which the script engine will then try to free when you do assign the new string handle to the members.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
greate WitchLord:
struct stMessage{
public:
stMessage()
{
String1 = new asCScriptString("ye");
String2 = new asCScriptString("ye");
}
int msg;
int Param1, Param2, Param3;
int Param4;
asCScriptString *String1, *String2 ;
};
error happenedd yet.
struct stMessage{
public:
stMessage()
{
String1 = new asCScriptString("ye");
String2 = new asCScriptString("ye");
}
int msg;
int Param1, Param2, Param3;
int Param4;
asCScriptString *String1, *String2 ;
};
error happenedd yet.
Glad you worked it out.
Also, since the string members are handles, you don't actually have to allocate new strings in the constructor. You can just set the pointers to 0, and it will still work.
Regards,
Andreas
Also, since the string members are handles, you don't actually have to allocate new strings in the constructor. You can just set the pointers to 0, and it will still work.
Regards,
Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement