It was being too easy

Started by
2 comments, last by jal_ 15 years, 9 months ago
Hi, I'm implementing angelscript for gametypes scripting in a C based game (warsow.net). I have to say I didn't find a single problem until now that I'm trying to run my first full gametype script which is quite amazing, but I'm now stuck with this issue that I don't know how happens. I have to add that it was so easy to implement that I'm still quite unfamiliar with how angelscript works :) Let me try to describe what happens: The gametype scripts are a series of script functions which are called by the game code on different match events. This includes a frame thinking function, match state changes, player respawning, player dieying, etc. The problem I'm getting is that, after some time, some of these calls fail to prepare the execution context with error -2 (unless I'm very wrong, the context still being active). The failing functions have already been succesfully called, but under different circumstances (different match state switches). I think the function where this happens is in this case being called from another script function via a C function (actually, it could be reaching 2 levels of this). I now have the doubt if this is supported by angelscript (they all use the same context, btw). Could you clarify me this? Is there a limit on these script->C->script nested calls? I'm sorry that my explanation isn't more precise, but it's also hard for me to guess where the problem is started. P.S: This is the script I'm running. It's not like it's going to help much, but well: http://rafb.net/p/GMGAPg96.html
Advertisement
Hmm... ok, I found out that the problem was at using the same context for all script functions so it couldn't be reused when calling a script function from another script function (via C).

Now my doubt is. Should I allow it to dynamically create contexts as needed? Would it be better to create a context for each function and forbid recursion? (won't be needed anyway). And, is there any backside on using different contexts for each function?
Hey

As you said yourself, I think your problem is that you have C code that calls a script, that calls C code, that calls a script. I.e. 2 levels of script running. In my engine I've solved this problem by having a pool of contexts, so when something wants to call a script it grabs a context from the pool (which if it's empty creates a new context), and when the script has finished the context is returned to the pool.

In std-ish pseudocode:
Context* getContext()
{
if( contextPool.size() == 0 )
return new Context();
else
return contextPool.pop();
}

void releaseContext( Context* context )
{
contextPool.push_back( context );
}


Hope that helps :)
Ye, contexts problem solved, thanks.

This topic is closed to new replies.

Advertisement