Advertisement

Problem with arrays when upgraded to 2.28

Started by January 26, 2014 08:06 AM
2 comments, last by aliascc 10 years, 9 months ago

Hi,

I am having a problem getting AS working again. I keep getting the message "Object handle is not supported for this type", or the program crashes.

This only happens with "array<uint>" or "array<Color>". The "array<wstring>" works find and returns what it is expected. Is the color or uint that does not return ok, script fails to compile.

Thanks in advance for any help. Let me know if you guys need more info.

Here is the code:

Script Code:


array<ScriptConsoleLine> crlArr;

array<wstring> line;
array<Color> color;

wstring ukcmmd = m_LocalizationManager.GetLiteral("XE_CONSOLE_MSG_UNK_CMD") + ":";
line.insertLast(ukcmmd);
color.insertLast(GetColorByEnum(XEColorType_Red));

line.insertLast(subCommands[0]);
color.insertLast(GetColorByEnum(XEColorType_White));

ScriptConsoleLine crl;

@crl.m_SA_Strings = line;
@crl.m_SA_Colors = color;  //<----- Always fails here, states "Object handle is not supported for this type" for either array<uint> or array<Color>

crlArr.insertLast(crl);

@m_ScriptConsoleLineArray = crlArr;

Struct Code


struct ScriptConsoleLine sealed : public XEObject
{

CScriptArray*	m_SA_Strings;
CScriptArray*	m_SA_Colors;

//Contructor
ScriptConsoleLine()
 : m_SA_Strings(nullptr)
 , m_SA_Colors(nullptr)
{
}

ScriptConsoleLine(const ScriptConsoleLine& other)
{
 *this = other;
}

virtual ~ScriptConsoleLine()
{
 ReleaseAngel(m_SA_Strings);
 ReleaseAngel(m_SA_Colors);
}

ScriptConsoleLine& operator=(const ScriptConsoleLine& other)
{
 ReleaseAngel(m_SA_Strings);
 ReleaseAngel(m_SA_Colors);

 if (other.m_SA_Strings != nullptr)
 {
  m_SA_Strings = other.m_SA_Strings;
  other.m_SA_Strings->AddRef();
 }

 if (other.m_SA_Colors != nullptr)
 {
  m_SA_Colors = other.m_SA_Colors;
  other.m_SA_Colors->AddRef();
 }

 return *this;
}

static void Constructor(ScriptConsoleLine* self)
{
	new(self) ScriptConsoleLine();
}

static void Destructor(ScriptConsoleLine* self)
{
	self->~ScriptConsoleLine();
}

};

AS Code to register Struct


ret = asManager->GetASEngine()->RegisterObjectType("ScriptConsoleLine", sizeof(ScriptConsoleLine), asOBJ_VALUE | asOBJ_APP_CLASS);
...//Checks for ret

ret = asManager->GetASEngine()->RegisterObjectProperty("ScriptConsoleLine", "array<wstring>@ m_SA_Strings",  asOFFSET(ScriptConsoleLine, m_SA_Strings));
...//Checks for ret

ret = asManager->GetASEngine()->RegisterObjectProperty("ScriptConsoleLine", "array<Color>@ m_SA_Colors", asOFFSET(ScriptConsoleLine, m_SA_Colors));
...//Checks for ret

ret = asManager->GetASEngine()->RegisterObjectMethod("ScriptConsoleLine", "ScriptConsoleLine &opAssign(const ScriptConsoleLine& in)", asMETHOD(ScriptConsoleLine, operator=), asCALL_THISCALL);
...//Checks for ret

ret = asManager->GetASEngine()->RegisterObjectBehaviour("ScriptConsoleLine", asBEHAVE_CONSTRUCT, "void XEAS_ScriptConsoleLineConstructor()", asFUNCTION(ScriptConsoleLine::Constructor), asCALL_CDECL_OBJLAST);
...//Checks for ret

ret = asManager->GetASEngine()->RegisterObjectBehaviour("ScriptConsoleLine", asBEHAVE_DESTRUCT, "void XEAS_ScriptConsoleLineDestructor()", asFUNCTION(ScriptConsoleLine::Destructor), asCALL_CDECL_OBJLAST);
...//Checks for ret

ret = asManager->GetASEngine()->RegisterGlobalProperty("array<ScriptConsoleLine> @m_ScriptConsoleLineArray", &m_ScriptConsoleLineArray);
...//Checks for ret

if(asManager->LoadScript(".\\Data\\Scripts\\Console.as", m_ConsoleModuleName) != XEResult
...//Loads script and checks for ret

The "Object handle is not supported for this type" error appears to be a bug in AngelScript. I'll investigate this and let you know what I find shortly.

The crash you experience is most likely because of the copy constructor in ScriptConsoleLine. You don't clear the pointers before calling the *this = other, so the assignment operator will call release on uninitialized pointers.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

I've fixed the bug in revision 1821.

The engine was incorrectly destroying the template instance type too early, so when the compiler accessed them for the ScriptConsoleLine properties it either crashed or didn't understand that it was an array type.

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

Hi Andreas,

Thank you very much!! It is all working correctly now :D

Regards

This topic is closed to new replies.

Advertisement