Advertisement

string error

Started by December 31, 2004 03:55 AM
10 comments, last by WitchLord 19 years, 10 months ago
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; }
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.
Advertisement
seems like the resultant string realScriptName must be long enough.

if i do this, it will work:

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

That's decidingly odd. I take it string is not really std::string?
it is std::string.
i find it wierd too, i thot std::string can dynamically allocate itself.

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?

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
>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

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 );}

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

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 ?
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.



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