Sign in to follow this  
Friggle

Script math does not work in VC6 release

Recommended Posts

I'm experiencing somthing strange using the scriptmath add-on and VC6 in release build mode: The engine does not seem to recognize any of the registered math functions, although it does correctly in the debug build. I get error messages like this when trying to compile the scripts with my release build: ERR : No matching signatures to 'pow(double, double)' Note that other add-ons like ScriptString work fine even in the release build. Any idea what the reason could be? I'm using 'scriptmath.h' and 'scriptmath.cpp' as included in the AngelScript release package 2.16.3 (2009/07/05) Many thanks for any advice!

Share this post


Link to post
Share on other sites
I'm using VC6 too at work and don't have this problem.

Is it only affecting the pow() function or all of the math functions?

Have you checked to make sure the RegisterScriptMath function is really registering the function? It may be some preprocessor macros that you have that skip that code.

Quote:
Original post by Codeka
I don't know about AngelCode, but why are you using VC6? It's eleven years old, and the latest version of Visual C++ can be downloaded for free.


Not everyone have a say in which version they use. At work we still use VC6 because we work with a lot of legacy code, which unfortunately has a lot of quirks that don't easily convert to newer versions. It would be very costly to switch to a newer compiler at this moment.

At home I use VC9 though, and I must say it is way better than VC6. So it is definitely recommended.

Share this post


Link to post
Share on other sites
Actually all math functions are affected.

I will have to check if the registering code is executed in the release build. However, there is no pre-processor conditional compilation here on my end and I call the Register function already provided in the add on cpp file.

However, registering might fail for some reason in release build and since I only use assert for checking the return values I would not be notified in the release build.

I'll keep you updated on any outcomes. Thanks so far...

Share this post


Link to post
Share on other sites
OK, here's the next update:

1.) The issue only occurs when the macro AS_USE_FLOAT is defined to be '0' (I use the double versions)

2.) The issue only occurs in the release build.

3.) The problem does not affect all math functions. I've inserted throwing an exception inside function
'void RegisterScriptMath_Native(asIScriptEngine *engine)' for test purposes:

r = engine->RegisterGlobalFunction("double ceil(double)", asFUNCTION(ceil), asCALL_CDECL); assert( r >= 0 );
if (r < 0)
{
throw(1);
}

If I put this code below the mentioned code line everything works fine (exception not thrown, function 'ceil' accessible from the script).

However, if I put the code one or more lines towards the beginning of the function, e.g. like this:

r = engine->RegisterGlobalFunction("double sqrt(double)", asFUNCTION(sqrt), asCALL_CDECL); assert( r >= 0 );
if (r < 0)
{
throw(1);
}

Then the compiler says that variable 'r' was used in the if-statement before it was initialized!

It seems like if the compiler does not see the assignment to 'r' in this case. Consequently, function 'sqrt' is not accessible in the script just like all functions that are registered beforehand are not accessible.

Any idea? Many thanks in advance!

Share this post


Link to post
Share on other sites
That is very strange. I looks like it is a bug in MSVC6' preprocessor, but I don't understand how it can just skip some parts of the code without giving any compilation errors.

Anyway, I managed to reproduce this. I also found a solution for the problem by substituting the use of the macro asFUNCTION with asFUNCTIONPR instead, i.e.


r = engine->RegisterGlobalFunction("double cos(double)", asFUNCTIONPR(cos, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double sin(double)", asFUNCTIONPR(sin, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double tan(double)", asFUNCTIONPR(tan, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double acos(double)", asFUNCTIONPR(acos, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double asin(double)", asFUNCTIONPR(asin, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double atan(double)", asFUNCTIONPR(atan, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double atan2(double,double)", asFUNCTIONPR(atan2, (double, double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double cosh(double)", asFUNCTIONPR(cosh, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double sinh(double)", asFUNCTIONPR(sinh, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double tanh(double)", asFUNCTIONPR(tanh, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double log(double)", asFUNCTIONPR(log, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double log10(double)", asFUNCTIONPR(log10, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double pow(double, double)", asFUNCTIONPR(pow, (double, double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double sqrt(double)", asFUNCTIONPR(sqrt, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double ceil(double)", asFUNCTIONPR(ceil, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double abs(double)", asFUNCTIONPR(fabs, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double floor(double)", asFUNCTIONPR(floor, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double fraction(double)", asFUNCTIONPR(fraction, (double), double), asCALL_CDECL); assert( r >= 0 );


Share this post


Link to post
Share on other sites
Yes, it's really strange, I also don't quite understand what happens here. Glad that you could reproduce it, though, I'll give your workaround a try asap.

Many thanks, great support as always!

Cheers

Share this post


Link to post
Share on other sites

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