🔒 Locked
ExecuteString
Advertisement
Original Post
Well, I use ExecuteString() all the time in the test framework, so I know that the method itself is not the cause of the crashes.
You are saying that ExecuteString is run while another context is executing. Do you mean that you are using multithreading, or do you suspend the other context and run ExecuteString()?
If you are executing script contexts in multiple threads then you are most likely going to have trouble, even if the contexts belong to different engines. AngelScript is not yet supporting multithreading.
I'll do some tests with concurrent script execution to see if that is the problem. But without more info, I think it will be very difficult to find the exact problem you're having.
You are saying that ExecuteString is run while another context is executing. Do you mean that you are using multithreading, or do you suspend the other context and run ExecuteString()?
If you are executing script contexts in multiple threads then you are most likely going to have trouble, even if the contexts belong to different engines. AngelScript is not yet supporting multithreading.
I'll do some tests with concurrent script execution to see if that is the problem. But without more info, I think it will be very difficult to find the exact problem you're having.
I'm still stepping through the code to figure out what is going on, but the engine is single threaded. The game works by invoking scripts based on the user's input, e.g. "void cmd_execute(string buffer)." If the user typed "exec this->SetWhatever(1)," then the engine would magically call the cmd_execute method with buffer set to "this->SetWhatever(1)." cmd_execute would then invoke a engine function that would in turn call ExecuteString.
The original call to cmd_execute does not actually finish until after it invokes ExecuteString.
(The "this" pointer is a pointer to the game object invoking the script.)
The original call to cmd_execute does not actually finish until after it invokes ExecuteString.
(The "this" pointer is a pointer to the game object invoking the script.)
Is cmd_execute() a script function?
That would make it a situation where a context causes another context to be executed. Theoretically this should work, though I don't have a test case for it (I do believe Lennart Denninger's BeatHarness have some situations like this though.) I'll write some test cases to verify this functionality.
That would make it a situation where a context causes another context to be executed. Theoretically this should work, though I don't have a test case for it (I do believe Lennart Denninger's BeatHarness have some situations like this though.) I'll write some test cases to verify this functionality.
It could be that this is what is happening, and if that is so it is because of a bug in AngelScript.
I hope I'll get the time to test this further tomorrow.
Hmm, come to think of it. ExecuteString() can't call a function that in turn calls ExecuteString() as the context is shared for all calls to ExecuteString(). Maybe I can fix this by pushing the context on a stack. I don't know if this is your scenario, but it is something that I have to fix, or at least prevent.
I hope I'll get the time to test this further tomorrow.
Hmm, come to think of it. ExecuteString() can't call a function that in turn calls ExecuteString() as the context is shared for all calls to ExecuteString(). Maybe I can fix this by pushing the context on a stack. I don't know if this is your scenario, but it is something that I have to fix, or at least prevent.
I ran the following test:
As I thought the first call with a proper context works as expected, where as the second call through ExecuteString() fails silently, with the result that i == 2.
I'll fix this so that ExecuteString() can be nested by pushing the current context on the stack. That is if it is possible to do that, otherwise I'll just make ExecuteString() fail if it is already active. In that case CallExecuteString() ought to raise an exception for the script.
NOTE. The code above is using the latest WIP with default values for some of the parameters.
#include "utils.h"#include "stdstr.h"using namespace std;#define TESTNAME "TestNested"static const char *script1 ="void TestNested() \n""{ \n"" CallExecuteString(\"i = 2\"); \n"" i = i + 2; \n""} \n";static void CallExecuteString(string &str){ asIScriptContext *ctx = asGetActiveContext(); asIScriptEngine *engine = ctx->GetEngine(); engine->ExecuteString(0, str.c_str());}static int i = 0;bool TestNested(){ bool fail = false; asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); RegisterStdString(engine); engine->RegisterGlobalProperty("int i", &i); engine->RegisterGlobalFunction("void CallExecuteString(string &)", asFUNCTION(CallExecuteString), asCALL_CDECL); COutStream out; engine->AddScriptSection(0, TESTNAME, script1, strlen(script1), 0); engine->Build(0, &out); // Make the call with a separate context (should work) asIScriptContext *ctx; engine->CreateContext(&ctx); ctx->Prepare(engine->GetFunctionIDByIndex(0, 0)); ctx->Execute(); if( i != 4 ) { printf("%s: Failed to call nested ExecuteString() from other context\n", TESTNAME); fail = true; } ctx->Release(); // Make the call with ExecuteString (doesn't work) i = 0; engine->ExecuteString(0, "TestNested()"); if( i != 4 ) { printf("%s: Failed to call nested ExecuteString() from ExecuteString()\n", TESTNAME); fail = true; } engine->Release(); // Success return fail;}As I thought the first call with a proper context works as expected, where as the second call through ExecuteString() fails silently, with the result that i == 2.
I'll fix this so that ExecuteString() can be nested by pushing the current context on the stack. That is if it is possible to do that, otherwise I'll just make ExecuteString() fail if it is already active. In that case CallExecuteString() ought to raise an exception for the script.
NOTE. The code above is using the latest WIP with default values for some of the parameters.
That's good to hear.
But in either case your problem inspired me to improve the ExecuteString() implementation. With the next WIP ExecuteString() can be called recursively, and can also be called from multiple threads at the same time.
I'll release the next WIP in a couple of days.
But in either case your problem inspired me to improve the ExecuteString() implementation. With the next WIP ExecuteString() can be called recursively, and can also be called from multiple threads at the same time.
I'll release the next WIP in a couple of days.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement