# AngelScript 1.10.0 FINAL (2004/11/02)

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

## Recommended Posts

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.

##### Share on other sites
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).

##### Share on other sites
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.

##### Share on other sites
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

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

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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. :)

##### Share on other sites
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.

##### Share on other sites
from the online documentation:

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

oops?

##### Share on other sites
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.

##### Share on other sites
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?

##### Share on other sites
I'm not sure I understand what you mean. Would you mind explaining?

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
That is certainly a nice solution for setting break points.

Another hook could be set up for when a script exception occurs, this would allow the application to examine the call stack before it is cleaned up.

Then it would also be useful to have a database of function variables, and access to the context stack. This one would require a lot more work though.

You can send me the code you have, if you'd like. I can include it in versions 1.11.0 and 2.0.0.

##### Share on other sites
I would love to see those in AS, as we speak it gets more professional, and when a coupla titles get to use it, could get that worldwide support for a great scripting language!

##### Share on other sites
I got a bug report from a mod author for my game in development. I believe this is related to changes in AS, since he was just upgrading existing script to work with latest version of game (having new AS as well).

I'm quoting here what he posted. (pay attention to the differences in last parameter of drawString call)
--

I narrowed it down a bit and while this still doesn't work:
      medFont->drawString(float(screenWidth / 2), float(screenHeight / 4) + 180, UIFONT_ALIGN_HORIZ_CENTER | UIFONT_ALIGN_VERT_CENTER, "Total: " + bstrFormat(float(handsFirst ? 1500 : 0)));

This does:
      bstr test = bstrFormat(float(handsFirst ? 1500 : 0));      medFont->drawString(float(screenWidth / 2), float(screenHeight / 4) + 180, UIFONT_ALIGN_HORIZ_CENTER | UIFONT_ALIGN_VERT_CENTER, "Total: " + test);

As does this:
      medFont->drawString(float(screenWidth / 2), float(screenHeight / 4) + 180, UIFONT_ALIGN_HORIZ_CENTER | UIFONT_ALIGN_VERT_CENTER, "Total: " + bstrFormat(handsFirst ? 1500 : 0));

##### Share on other sites
I've fixed a bug related to casting the ?: ternary operator in the WIP. Have you tried the latest WIP already?

##### Share on other sites
I identified a bug where temporary variables where prematurely released. It can be fixed by adding a test to verify that bc != 0 before calling ReleaseTemporaryVariable() in method asCCompiler::Dereference().

as_compiler.cpp line 1904:

if( bc )   ReleaseTemporaryVariable(*type, bc);

This is for the latest WIP. With this fix, the latest WIP can compile and execute all three of the situations you mentioned.

Later this week, I'm releasing version 1.10.1, which will be the first officially stable version AngelScript. Stable in that I will maintain this version with bug fixes while going forward with other versions for future features.

Thanks Jetro.