Jump to content
  • Advertisement
Sign in to follow this  
aliascc

Problem with arrays when upgraded to 2.28

This topic is 2087 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

 

 

 

 

 

 

 

 

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!