class A {
int x;
int y;
}
string toString(const A& a) {
return a.x + ":" + a.y;
}
string toString(const A[]& a) {
string s;
for (uint i=0; i<a.length(); i++)
s += "element " + i + ":" + toString(a);
return s;
}
A[] As;
As.resize(2);
As[0].x = 1;
As[0].y = 2;
As[1].x = 1;
As[1].y = 2;
print(toString(As));
Convert array to string
Hi all, in one of my scripts I have a class called A that contains some members. When creating an array of A and converting this array to a string I get a access violation in asCScriptEngine::CallObjectMethod Here is a small example. The string is the stl string registered without reference counting: Any ideas whats going wrong. Regards, Tim
I'll have to investigate this. It could be a problem in AngelScript itself. However, as I'm on vacation (just doing a quick stop by on the forum) don't expect any resolution until I get home in January.
Are you using CScriptString as the string implementation?
Are you using CScriptString as the string implementation?
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,
no I've registered the std::string directly with:
RegisterObjectType("string", sizeof(string), asOBJ_VALUE | asOBJ_APP_CLASS_CDA);
RegisterStringFactory("string", asFUNCTION(StringFactory), asCALL_CDECL);
Everything else connected to string is working fine (string return value, pass string by value and ref...)
Have a nice vacation,
Tim
[Edited by - xivVerge on December 22, 2008 1:21:11 AM]
no I've registered the std::string directly with:
RegisterObjectType("string", sizeof(string), asOBJ_VALUE | asOBJ_APP_CLASS_CDA);
RegisterStringFactory("string", asFUNCTION(StringFactory), asCALL_CDECL);
Everything else connected to string is working fine (string return value, pass string by value and ref...)
Have a nice vacation,
Tim
[Edited by - xivVerge on December 22, 2008 1:21:11 AM]
I did another investiagtion.
It has nothing to do with string.
The following example gives the same error.
Merry Christmas,
Tim
It has nothing to do with string.
The following example gives the same error.
class A{ int x;}int sum(const A[]& a){ int s = 0; for (uint i=0; i<a.length(); i++) s+=a.x; return s;}A[] As;As.resize(2);As[0].x = 1;As[1].x = 2;sum(As);
Merry Christmas,
Tim
Thanks for the extra information. It ought to be quite easy to find and fix the bug with this sample.
Regards,
Andreas
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
Just got a chance to look into this, and unfortunately both of the examples that you're presenting are working without any error, so I have no idea what's going on. This is on the latest version from the SVN (2.15.1 WIP).
What version of AngelScript are you using?
What version of AngelScript 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
I wrote the following test case, and tried it with AS_NO_USER_ALLOC, but it still doesn't show any problem. The fact that you use Posix threads shouldn't make a difference either. But I'll give the test a try on my Mac as well when I get the time, just to make sure.
Could you verify if the above test reproduces the problem on your setup?
Regards,
Andreas
bool Test2(){ bool fail = false; const char *script = "class A \n" "{ \n" " int x; \n" "} \n" "int sum(const A[]& a) \n" "{ \n" " int s = 0; \n" " for (uint i=0; i<a.length(); i++) \n" " s+=a.x; \n" " return s; \n" "} \n"; const char *exec = "A[] As; \n" "As.resize(2); \n" "As[0].x = 1; \n" "As[1].x = 2; \n" "sum(As); \n"; asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); asIScriptModule *module = engine->GetModule("module", asGM_ALWAYS_CREATE); module->AddScriptSection("script", script); int r = module->Build(); if( r < 0 ) { fail = true; } r = engine->ExecuteString("module", exec); if( r != asEXECUTION_FINISHED ) { fail = true; } engine->Release(); return fail;}
Could you verify if the above test reproduces the problem on your setup?
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement