Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

AngelScript 1.10.0 FINAL (2004/11/02)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
45 replies to this topic

#21 Aggrav8d   Members   -  Reputation: 133

Like
0Likes
Like

Posted 06 November 2004 - 10:37 AM

I see a something strange. If I do this:

  uint i=0;
brickbase[i]=CreateObjectInstance(tbase);
There is no problem. However, if I do this:

  uint i;
for(i=0;i<1;++i) {
brickbase[i]=CreateObjectInstance(tbase);
}
I get the stacksize problem. In both cases they are preceeded by

ObjectType *tball, *tspinnera, *tbase, *tbrick1, *tpaddle;
ObjectInstance *[] brickbase(4);
tbase=CreateObjectType("base");
I also get a number of problems with Dereference when I try to pass the value of an element of an array of pointers to a registered method, such as

//myType *[] myArray(2);
MethodThatTakesAPointer(myArray[0]);
// this also asserts in Dereference
SomeInstance->ClassMethodThatTakesAPointer(myArray[1]);
// and this, on the first line.
myType *t=myArray[0];
MethodThatTakesAPointer(t);
I have applied the fix for the pointer dereferencing that you mentioned earlier.

[Edited by - Aggrav8d on November 6, 2004 5:37:00 PM]

Dan Royer, OwnerMarginally Clever Games

Sponsor:

#22 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 07 November 2004 - 02:45 AM

I can run the following test without any problems:


#include "utils.h"

namespace TestPointer
{

#define TESTNAME "TestPointer"

class ObjectInstance
{
public:
int val;
};

class ObjectType
{
public:
};

static void ObjectFunction(ObjectInstance *obj)
{

}

ObjectInstance obj;
static ObjectInstance *CreateObjectInstance(ObjectType *type)
{
return &obj;
}

ObjectType type;
static ObjectType *CreateObjectType(std::string &str)
{
return &type;
}

static void FunctionOnObject(ObjectInstance *obj)
{
}

static const char *script =
"void Test() \n"
"{ \n"
" ObjectInstance*[] c(5); \n"
" ObjectType *tbase = CreateObjectType(\"base\"); \n"
" uint i; \n"
" for( i = 0; i < 5; ++i ) \n"
" { \n"
" c[i] = CreateObjectInstance(tbase); \n"
" c[i]->function(); \n"
" c[i]->val = 0; \n"
" } \n"
" ObjectInstance *obj = c[0]; \n"
" FunctionOnObject(c[0]); \n"
"} \n";

bool Test()
{
bool fail = false;

asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
RegisterStdString(engine);

int r;
r = engine->RegisterObjectType("ObjectInstance", sizeof(ObjectInstance), asOBJ_CLASS); assert(r>=0);
r = engine->RegisterObjectProperty("ObjectInstance", "int val", offsetof(ObjectInstance, val)); assert(r>=0);
r = engine->RegisterObjectMethod("ObjectInstance", "void function()", asFUNCTION(ObjectFunction), asCALL_CDECL_OBJFIRST); assert(r>=0);

r = engine->RegisterObjectType("ObjectType", sizeof(ObjectType), asOBJ_CLASS); assert(r>=0);

r = engine->RegisterGlobalFunction("ObjectType *CreateObjectType(string &)", asFUNCTION(CreateObjectType), asCALL_CDECL); assert(r>=0);
r = engine->RegisterGlobalFunction("ObjectInstance *CreateObjectInstance(ObjectType *type)", asFUNCTION(CreateObjectInstance), asCALL_CDECL); assert(r>=0);

r = engine->RegisterGlobalFunction("void FunctionOnObject(ObjectInstance *)", asFUNCTION(FunctionOnObject), asCALL_CDECL); assert(r>=0);

// Register an object.
ObjectInstance obj;
r = engine->RegisterGlobalProperty("ObjectInstance obj", &obj); assert(r>=0);

// Register a pointer to object.
ObjectInstance *pnt = &obj;
r = engine->RegisterGlobalProperty("ObjectInstance *ptr", &pnt); assert(r>=0);

COutStream out;

// Function call executed fine when using an object.
r = engine->ExecuteString(0, "obj.function(); obj.val = 23;", &out);
if( r < 0 )
{
printf("%s: ExecuteString() failed %d\n", TESTNAME, r);
fail = true;
}
if( obj.val != 23 )
{
printf("%s: failed\n", TESTNAME, r);
fail = true;
}

r = engine->ExecuteString(0, "ptr->function(); ptr->val = 13;", &out);
if( r < 0 )
{
printf("%s: ExecuteString() failed %d\n", TESTNAME, r);
fail = true;
}
if( obj.val != 13 )
{
printf("%s: failed\n", TESTNAME, r);
fail = true;
}

engine->AddScriptSection(0, TESTNAME, script, strlen(script));
r = engine->Build(0, &out);
if( r < 0 )
{
printf("%s: failed\n", TESTNAME, r);
fail = true;
}

r = engine->ExecuteString(0, "Test()");
if( r < 0 )
{
printf("%s: failed\n", TESTNAME, r);
fail = true;
}

engine->Release();

return fail;
}

}




Please give the latest 1.10.1 WIP 1 a try and see if the problems remain.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#23 Aggrav8d   Members   -  Reputation: 133

Like
0Likes
Like

Posted 07 November 2004 - 05:05 AM

I did the following with your test and it failed.


#include "utils.h"

namespace TestPointer
{

#define TESTNAME "TestPointer"

class ObjectInstance
{
public:
int val;
int val2;
int val3;

void Method() {
val=val2=val3=0;
}
};

class ObjectType
{
public:
};

static void ObjectFunction(ObjectInstance *obj)
{

}

ObjectInstance obj;
static ObjectInstance *CreateObjectInstance(ObjectType *type)
{
return &obj;
}

ObjectType type;
static ObjectType *CreateObjectType(std::string &str)
{
return &type;
}

static void FunctionOnObject(ObjectInstance *obj)
{
}

static const char *script =
"void Test() \n"
"{ \n"
" ObjectInstance*[] c(5); \n"
" ObjectType *tbase = CreateObjectType(\"base\"); \n"
" uint i; \n"
" for( i = 0; i < 5; ++i ) \n"
" { \n"
" c[i] = CreateObjectInstance(tbase); \n"
" c[i]->function(); \n"
" c[i]->val = 0; \n"
" } \n"
" ObjectInstance *obj = c[0]; \n"
" FunctionOnObject(c[0]); \n"
"} \n";

bool Test()
{
bool fail = false;

asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
RegisterStdString(engine);

int r;
r = engine->RegisterObjectType("ObjectInstance", sizeof(ObjectInstance), asOBJ_CLASS); assert(r>=0);
r = engine->RegisterObjectProperty("ObjectInstance", "int val", offsetof(ObjectInstance, val)); assert(r>=0);
r = engine->RegisterObjectProperty("ObjectInstance", "int val2", offsetof(ObjectInstance, val)); assert(r>=0);
r = engine->RegisterObjectProperty("ObjectInstance", "int val3", offsetof(ObjectInstance, val)); assert(r>=0);
r = engine->RegisterObjectMethod("ObjectInstance", "void function()", asFUNCTION(ObjectFunction), asCALL_CDECL_OBJFIRST); assert(r>=0);
r = engine->RegisterObjectMethod("ObjectInstance", "void Method()", asMETHOD(ObjectInstance,Method), asCALL_THISCALL); assert(r>=0);

r = engine->RegisterObjectType("ObjectType", sizeof(ObjectType), asOBJ_CLASS); assert(r>=0);

r = engine->RegisterGlobalFunction("ObjectType *CreateObjectType(string &)", asFUNCTION(CreateObjectType), asCALL_CDECL); assert(r>=0);
r = engine->RegisterGlobalFunction("ObjectInstance *CreateObjectInstance(ObjectType *type)", asFUNCTION(CreateObjectInstance), asCALL_CDECL); assert(r>=0);

r = engine->RegisterGlobalFunction("void FunctionOnObject(ObjectInstance *)", asFUNCTION(FunctionOnObject), asCALL_CDECL); assert(r>=0);

// Register an object.
ObjectInstance obj;
r = engine->RegisterGlobalProperty("ObjectInstance obj", &obj); assert(r>=0);

// Register a pointer to object.
ObjectInstance *pnt = &obj;
r = engine->RegisterGlobalProperty("ObjectInstance *ptr", &pnt); assert(r>=0);

COutStream out;

// Function call executed fine when using an object.
r = engine->ExecuteString(0, "obj.function(); obj.val = 23;", &out);
if( r < 0 )
{
printf("%s: ExecuteString() failed %d\n", TESTNAME, r);
fail = true;
}
if( obj.val != 23 )
{
printf("%s: failed\n", TESTNAME, r);
fail = true;
}

r = engine->ExecuteString(0, "ptr->function(); ptr->val = 13;", &out);
if( r < 0 )
{
printf("%s: ExecuteString() failed %d\n", TESTNAME, r);
fail = true;
}
if( obj.val != 13 )
{
printf("%s: failed\n", TESTNAME, r);
fail = true;
}

engine->AddScriptSection(0, TESTNAME, script, strlen(script));
r = engine->Build(0, &out);
if( r < 0 )
{
printf("%s: failed\n", TESTNAME, r);
fail = true;
}

r = engine->ExecuteString(0, "Test()");
if( r < 0 )
{
printf("%s: failed\n", TESTNAME, r);
fail = true;
}

engine->Release();

return fail;
}

}





Note that this is not with the latest WIP. When I try to compile the library there, the WIN32 Debug with ASM VM build fails with the message

c:\angelcode\sdk\angelscript\source\as_context_x86.cpp(131) : error C2248: 'length' : cannot access protected member declared in class 'asCArray<int>'
c:\angelcode\sdk\angelscript\source\as_array.h(61) : see declaration of 'length'
I comment out that one line, compile the necessary projects, and run with the version of TestPointer listed here and it dies with the error message

Assertion failed: false, file c:\angelcode\sdk\angelscript\source\as_compiler.cpp, line 1921
... is there any way to get "check here to include your profile signature" to stay selected all the time? That bugs the hell out of me!

Dan Royer, OwnerMarginally Clever Games

#24 jetro   Members   -  Reputation: 144

Like
0Likes
Like

Posted 07 November 2004 - 06:22 AM

In addition to the already solved pointer problems, I'm having problems with casting things to double with AS 1.10.0:

I managed to reduce the case down to simple test like this, after which I print out value of ft or t2 (using bstrFormat).

float ft = float(0.03);
double t = double(ft);
float t2 = float(t);


At this point, printing out ft gives out 0.03 and printing
out t2 gives out -3.68935e+019, although they should be equal.
--Jetro Lauha - tonic - http://jet.ro

#25 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 07 November 2004 - 07:09 AM

Aggrav8d:

Quote:

Note that this is not with the latest WIP. When I try to compile the library there, the WIN32 Debug with ASM VM build fails with the message


c:\angelcode\sdk\angelscript\source\as_context_x86.cpp(131) : error C2248: 'length' : cannot access protected member declared in class 'asCArray<int>'
c:\angelcode\sdk\angelscript\source\as_array.h(61) : see declaration of 'length'


Sorry about that, I thought I had commented out that line already, but I remember now that that was at work after I sent the code home for development during the weekend. I've fixed the download already.

With the changes you made to the test case I too get the assert failure. It should now be quite easy to find the problem.

jetro:

I will look into this problem as well. It might be a problem with the VM. There are unfortunately too many of the bytecodes that haven't been thouroughly tested yet.





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

#26 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 07 November 2004 - 07:29 AM

To fix the assert failure in Dereference() you need to replace the code for asCDataType::GetSubType() (in as_datatype.cpp) with the following:


asCDataType asCDataType::GetSubType(asCScriptEngine *engine)
{
asCDataType dt(*this);
if( dt.arrayDimensions )
dt.arrayDimensions--;
else if( dt.pointerLevel )
dt.pointerLevel--;

if( dt.arrayDimensions > 0 )
dt.objectType = engine->GetArrayType(dt);
else if( dt.pointerLevel > 0 )
dt.objectType = 0;
else
dt.objectType = dt.extendedType;

return dt;
}



---

I'm still looking in to the conversion to double problem.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#27 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 07 November 2004 - 07:52 AM

The fix for the floating conversion problem is to change the VM code for the following two bytecodes:

as_context.cpp line 1282:

case BC_fTOd:
*(double*)--l_sp = double(*(float*)(l_sp));
l_bc += BCS_fTOd;
break;


as_context.cpp line 1267:

case BC_dTOf:
*(float*)++l_sp = float(*(double*)(l_sp));
l_bc += BCS_dTOf;
break;


Note, this problem most likely exist for other conversions to and from double as well. I will write tests for all conversions right now (something that I should have done a long time ago).


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

#28 jetro   Members   -  Reputation: 144

Like
0Likes
Like

Posted 07 November 2004 - 09:19 AM

Just an additional note: I think I had the double conversion thing working just ok with previous version(s) - not sure if I tested it last time with 1.8.x or 1.9.x. I was using it with wrapping std sin, cos, etc. and just noticed with the latest update that my test code for them wasn't working anymore.

#29 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 07 November 2004 - 12:25 PM

I know, the conversion bug was introduced with the optimization of the C++ VM. I failed to fully understand when the ++ and --operators are evaluated:

I was doing:

*sp = *sp++; // Doesn't update sp until after the assignment

instead of:

*++sp = *sp; // Updates sp after the right hand expression has been evaluated, but before the assignment




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

#30 jetro   Members   -  Reputation: 144

Like
0Likes
Like

Posted 09 November 2004 - 08:03 AM

I verified that your fixes for as_context.cpp fix the float<=>double conversions.

However, when I first noticed the problem, I was actually using code which casts a time value of type uint to double, and that one still didn't work. Which is not a surprise since the VM code related to that was still untouched :). That is, I have "uint mTime;" and "double(mTime)" didn't work, but adding additional typecast to float helped: "double(float(mTime))".

Looking at your fix, I made the equivalent changes to BC_dTOi, BC_dTOui, BC_iTOd and BC_uiTOd:

case BC_dTOi:
*++l_sp = int(*(double*)(l_sp));
l_bc += BCS_dTOui;
break;

case BC_dTOui:
*++l_sp = asDWORD(*(double*)(l_sp));
l_bc += BCS_dTOui;
break;

// ...

case BC_iTOd:
*(double*)--l_sp = double(int(*l_sp));
l_bc += BCS_iTOd;
break;

case BC_uiTOd:
*(double*)--l_sp = double(*l_sp);
l_bc += BCS_uiTOd;
break;


This seems to have fixed the problem and now the original script code seems to work again.
--Jetro Lauha - tonic - http://jet.ro

#31 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 09 November 2004 - 08:18 AM

Thanks, I had already fixed those cases, but I forgot to show the fixes here.

I've added test cases for all conversions so this should never happen again.


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

#32 jetro   Members   -  Reputation: 144

Like
0Likes
Like

Posted 09 November 2004 - 09:45 AM

Um.. hopefully your fixes are better, since I found out that the ones I presented above aren't probably correct after all - at least my usage case doesn't work with Release builds currently. :)

#33 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 10 November 2004 - 01:15 AM

Good point. I hadn't tested the fix with release build.

Here's a fix that works:


case BC_dTOi:
{
int i = int(*(double*)(l_sp++));
*l_sp = i;
}
l_bc += BCS_dTOui;
break;

case BC_dTOui:
{
asUINT u = asDWORD(*(double*)(l_sp++));
*l_sp = u;
}
l_bc += BCS_dTOui;
break;

case BC_dTOf:
{
float f = float(*(double*)(l_sp++));
*(float*)l_sp = f;
}
l_bc += BCS_dTOf;
break;

case BC_iTOd:
{
double d = double(int(*l_sp--));
*(double*)l_sp = d;
}
l_bc += BCS_iTOd;
break;

case BC_uiTOd:
{
double d = double(*l_sp--);
*(double*)l_sp = d;
}
l_bc += BCS_uiTOd;
break;

case BC_fTOd:
{
double d = double(*(float*)(l_sp--));
*(double*)l_sp = d;
}
l_bc += BCS_fTOd;
break;



This teaches us that we can't rely on when the ++ and -- operators will be evaluated. If we need them to be exactly as we want them then the expressions must to be broken up.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#34 Aggrav8d   Members   -  Reputation: 133

Like
0Likes
Like

Posted 11 November 2004 - 09:50 AM

from the online documentation:

GetReturnValue
int GetStackData(asDWORD *data,int count);


oops?

Dan Royer, OwnerMarginally Clever Games

#35 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 11 November 2004 - 12:06 PM

Oops!

At first I didn't see what you meant. I thought you were wondering about the parameters, but then I saw the difference in function names. [wink]

I'll have that fixed for the next release.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#36 EddHead   Members   -  Reputation: 140

Like
0Likes
Like

Posted 11 November 2004 - 07:39 PM

Is there any way we could get the VC++ style Debug Trace associated with the MS IDE for AngelScript...I think VC++ would support this anyhow with a 3rd party plugin. any Ideas?
Jayanth.KRaptor Entertainment Pvt. Ltd.http://www.raptorentertainment.com---------------------------------------------------------Why Mr. Anderson? Why? ...Why keep fighting? Do you think you're fighting for something - for more than your survival? Can you tell me what it is? Do you even know? Is it freedom, or truth, perhaps peace, could it be for love? Illusions Mr. Anderson, vagaries of perception. Temporary constructs of a feeble human intellect trying desperately to justify an existence without meaning or purpose.

#37 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 12 November 2004 - 02:04 AM

I'm not sure I understand what you mean. Would you mind explaining?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#38 EddHead   Members   -  Reputation: 140

Like
0Likes
Like

Posted 12 November 2004 - 05:56 AM

Is there any way in which we could emulate a Debug Build in VC with the AS code, like breakpoints and call stack viewing, possibly integrated into VC itself, pushing it closer to C++ code compatibility! Just your thoughts and suggestions on this subject.
Jayanth.KRaptor Entertainment Pvt. Ltd.http://www.raptorentertainment.com---------------------------------------------------------Why Mr. Anderson? Why? ...Why keep fighting? Do you think you're fighting for something - for more than your survival? Can you tell me what it is? Do you even know? Is it freedom, or truth, perhaps peace, could it be for love? Illusions Mr. Anderson, vagaries of perception. Temporary constructs of a feeble human intellect trying desperately to justify an existence without meaning or purpose.

#39 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 12 November 2004 - 06:42 AM

With a few changes it would be possible to query the call stack. Setting break points would also be possible. But this would be with function calls to the context, i.e. the application would have to do this.

Integration into the MSVC++ debugger would be a completely different matter though. I don't know how to do this, or even if it's possible.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#40 Lioirc   Members   -  Reputation: 142

Like
0Likes
Like

Posted 12 November 2004 - 09:07 AM

No function calls to the context are necesary for the debug, but the oposite, function calls from the context to the client application.

That is what i have implemented here, and i asked you if you want this to be integrated in the current AS or in the new AS2, the debug hook

in bc_Line step, there is a:

if(debug_hook)
status = debug_hook(linenumber, state, whatever, ....)
if(status == _Suspend)
jmp bc_Suspsend

so if the client application implements a function with the correct declaration ( scriptEngine->SetDebugHook(debug_hookFunc); ) it will recive callbacks every line of execution with the line number and all the parameters that it will need

in the client application:

uint debug_hookFunc(int linenumber, uint state, whatever, ....) {
........
application specific code

if(breakpointsMap.find(linenumber)) {
execution line is on some breakpoint, do what you need
........
application specific code

return state_Suspsend;

}
........
application specific code

return state_continue;
}

this way the debugger can be created very easy, externally and will not affect the as engine, because in release it will compiled without the bc_line opcode

Lioric




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS