Sign in to follow this  

string error

This topic is 4727 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

kept getting exception when i tried to join string together. ----------- C++ code ----------------------------------- void GetEntityName1 (int i, string inValue, string& realScriptName) { string tt = string("script") + inValue + string(".sc"); realScriptName = tt; } i got an error when i execute it using: string myname; GetEntityName1 (id, "ranger", myname); HEAP[ScriptText.exe]: Invalid Address specified to RtlValidateHeap( 003F0000, 01250790 ) Unhandled exception at 0x77f75a58 in ScriptText.exe: User breakpoint. the whole routine will work if i change to: (but result is not what i wanted) void GetEntityName1 (int i, string inValue, string& realScriptName) { realScriptName = inValue; }

Share this post


Link to post
Share on other sites
You need to do more to pinpoint where the error is happening. That error doesn't tell us much - we know it's happening somewhere in the runtime library, and it involves a pointer somehow. Use your debugger.

As it is, it's quit unreplicatable. Your code looks correct to me. Something somewhere else is making it fail.

Share this post


Link to post
Share on other sites
seems like the resultant string realScriptName must be long enough.

if i do this, it will work:

string myname = "0123456789012345678901234567890123456789";
GetEntityName1 (id, "ranger", myname);

Share this post


Link to post
Share on other sites
std::string should dynamically allocate enough space. My guess is that something went wrong in the interface between the script engine and the application function.

How did you register the GetEntityName1() function?

Did you use RegisterStdString() to register the std::string?

What version of AngelScript are you using?

What compiler are you using?

Share this post


Link to post
Share on other sites
>How did you register the GetEntityName1() function?

GetEntityName1 (int, string, string&)


>Did you use RegisterStdString() to register the std::string?

no, i just treat the string in angelscript as std::string.

>What version of AngelScript are you using?

v1.10.1

>What compiler are you using?

VS.NET 2003

Share this post


Link to post
Share on other sites
Quote:
Original post by iram
>Did you use RegisterStdString() to register the std::string?

no, i just treat the string in angelscript as std::string.


That is probably your problem then. If it is not registered correctly then AngelScript won't be able to handle the objects as they should.

Try registering std::string using the following code (taken from stdstring.cpp in the add_on directory)


#include <assert.h>
#include "stdstring.h"
using namespace std;

static string StringFactory(asUINT length, const char *s)
{
return string(s);
}

static void ConstructString(string *thisPointer)
{
new(thisPointer) string();
}

static void DestructString(string *thisPointer)
{
thisPointer->~string();
}

void RegisterStdString(asIScriptEngine *engine)
{
int r;

// Register the bstr type
r = engine->RegisterObjectType("string", sizeof(string), asOBJ_CLASS_CDA); assert( r >= 0 );

// Register the bstr factory
r = engine->RegisterStringFactory("string", asFUNCTION(StringFactory), asCALL_CDECL); assert( r >= 0 );

// Register the object operator overloads
r = engine->RegisterObjectBehaviour("string", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructString), asCALL_CDECL_OBJLAST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("string", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestructString), asCALL_CDECL_OBJLAST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("string", asBEHAVE_ASSIGNMENT, "string &f(const string &)", asMETHODPR(string, operator =, (const string&), string&), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("string", asBEHAVE_ADD_ASSIGN, "string &f(const string &)", asMETHODPR(string, operator+=, (const string&), string&), asCALL_THISCALL); assert( r >= 0 );

// Register the global operator overloads
r = engine->RegisterGlobalBehaviour(asBEHAVE_EQUAL, "bool f(const string &, const string &)", asFUNCTIONPR(operator==, (const string &, const string &), bool), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalBehaviour(asBEHAVE_NOTEQUAL, "bool f(const string &, const string &)", asFUNCTIONPR(operator!=, (const string &, const string &), bool), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalBehaviour(asBEHAVE_LEQUAL, "bool f(const string &, const string &)", asFUNCTIONPR(operator<=, (const string &, const string &), bool), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalBehaviour(asBEHAVE_GEQUAL, "bool f(const string &, const string &)", asFUNCTIONPR(operator>=, (const string &, const string &), bool), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalBehaviour(asBEHAVE_LESSTHAN, "bool f(const string &, const string &)", asFUNCTIONPR(operator <, (const string &, const string &), bool), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalBehaviour(asBEHAVE_GREATERTHAN, "bool f(const string &, const string &)", asFUNCTIONPR(operator >, (const string &, const string &), bool), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalBehaviour(asBEHAVE_ADD, "string f(const string &, const string &)", asFUNCTIONPR(operator +, (const string &, const string &), string), asCALL_CDECL); assert( r >= 0 );

// Register the object methods
r = engine->RegisterObjectMethod("string", "uint length()", asMETHOD(string,size), asCALL_THISCALL); assert( r >= 0 );
}


Share this post


Link to post
Share on other sites
i have assertion problem during runtime starting from this line:

r = engine->RegisterObjectBehaviour("string", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestructString), asCALL_CDECL_OBJLAST); assert( r >= 0 );


what could be wrong ?

Share this post


Link to post
Share on other sites
Very strange.

What is the value of r? The value should be able to tell you a little more of what is going wrong.

Somehow I think it is -13 (asALREADY_REGISTERED), which would mean that you have already registered a destructor for the the string object type. But please verify the value for me.



Share this post


Link to post
Share on other sites
AngelScript doesn't register the string type by default, therefore you'll have to look through your code to try and find exactly where it is being registered before. It could be that you are registering another type to be used for the strings, which would explain why your application fails to concatenate the strings.

Share this post


Link to post
Share on other sites

This topic is 4727 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this