🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
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.
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement