• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Desdemona

ExecuteString

9 posts in this topic

I've been experiencing a problem with ExecuteString crashing my game in randomly wierd ways. The only thing I can see at the moment is that each time ExecuteString is called, it is being done while another context is executing. Is this a problem? Joe
0

Share this post


Link to post
Share on other sites
On second thought, it shouldnt matter at all, considering that you can ExecuteStep the ExecuteString context. It might be a really simple error on my part, but the code is pretty simple; it just calls ExecuteString... uhg.
0

Share this post


Link to post
Share on other sites
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.

0

Share this post


Link to post
Share on other sites
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.)
0

Share this post


Link to post
Share on other sites
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.

0

Share this post


Link to post
Share on other sites
Yes, cmd_execute() is a script function. I guess I worded the problem poorly. My concern was that ExecuteString might be messing up AngelScript's state, such that when it is finishes, the original context (e.g. cmd_execute) is unstable.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
I ran the following test:


#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.
0

Share this post


Link to post
Share on other sites
Figured out my problem. I was passing a string from the engine to a script by value and the string object's destructor was getting called twice.
0

Share this post


Link to post
Share on other sites
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.
0

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  
Followers 0