• 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
RCL

Problem (bug?) when releasing suspended context

6 posts in this topic

Hi! Is there a way to Abort() or Release() context (suspended one) without resuming its execution (what engine seemingly does)? The situation is: I have script which runs in almost-infinite :) loop and is executed via ExecuteStep(). So its context remains suspended between polls. When the program quits, context->Release() is called and AngelScript crashes when releasing BSTR instance. Calling context->Abort() prior to Release() does the same. I investigated the problem and found out that context tries to execute some cleanup code on exit. I'm not sure that it is safe - engine is already being shut down and if that code calls any external functions (like BSTR ones) they may crash. So, is there a (safe) way to release the context at once, without any bytecode execution? (However, I feel it is not correct - at least with current AngelScript). If there's no, I think I'll hack the code (for now) just to keep it from crashing :) Cheers, RCL
0

Share this post


Link to post
Share on other sites
This is probably a bug in AngelScript. The engine should be available to the contexts even after it has been released by the host application.

I'll have to investigate the situation further before I can give a definite answer. From what you describe, you're doing it correctly.

0

Share this post


Link to post
Share on other sites
I'm trying to verify this bug, but I've yet to reproduce it. I ran the following test case with version 1.9.1WIP2:


//
// Tests releasing a suspended context
//
// Test author: Andreas Jonsson
//

#include "utils.h"
#include "stdstr.h"

namespace TestSuspend
{

#define TESTNAME "TestSuspend"


static int loopCount = 0;

static const char *script1 =
"string g_str = \"test\"; \n" // variable that must be released when module is released
"void TestSuspend() \n"
"{ \n"
" string str = \"hello\"; \n" // variable that must be released before exiting the function
" while( true ) \n" // never ending loop
" { \n"
" loopCount++; \n"
" } \n"
"} \n";

bool Test()
{
bool fail = false;

asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);

RegisterStdString(engine);

engine->RegisterGlobalProperty("int loopCount", &loopCount);

COutStream out;
engine->AddScriptSection(0, TESTNAME ":1", script1, strlen(script1), 0);

engine->Build(0, &out);

asIScriptContext *ctx;
engine->CreateContext(&ctx);
ctx->Prepare(engine->GetFunctionIDByDecl(0, "void TestSuspend()"));

while( loopCount < 5 )
ctx->ExecuteStep(0);

// Release the engine first
engine->Release();

// Now release the context
ctx->Release();

// Success
return fail;
}

} // namespace





When engine->Release() is called nothing happens since the context is still holding a reference to the engine. When ctx->Release() is called it will call the CleanStack bytecode to free the local string variable. Then it will release the engine, which results in @exit() to be called for releasing the global string variable. All this happens without trouble.

Even though I couldn't reproduce the bug in the currently released version I still thank you, because I was able to detect and fix a bug in the version I'm about to release.

Let me know if you're doing something differently than I do in the test case.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by WitchLord
I'm trying to verify this bug, but I've yet to reproduce it. I ran the following test case with version 1.9.1WIP2:


That test works fine for me, too...

Quote:
Original post by WitchLord
Let me know if you're doing something differently than I do in the test case.


The difference is that my loop can exit at any time, it does not depend on any script variable like yours one. Perhaps it also means that it can exit during calls etc.

Cheers,
RCL
0

Share this post


Link to post
Share on other sites
I see that this is going to be tough to find this bug. But with your help, I'm sure I will be able to.

ExecuteNext() only allow the suspension of the execution at certain bytecodes, namely: CALL, CALLSYS, CALLBND, RET, JMP, JZ, JNZ, JS, JNS, JP, JNP, JMPP.

Is it possible for you to check the last byte code executed before releasing the context?

Better yet, is it possible for you to show me the script that crashes?

Are you calling any application registered functions from the script that call context->Suspend()?

You said in your original post that context is trying to execute the cleanup code after the engine is shut down. In my tests this cannot happen, since the context holds a reference to the engine. How did you come to this knowledge?

I'm suspecting that somehow a bstr is being destroyed more than once. But I need your help to confirm this.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by WitchLord
I see that this is going to be tough to find this bug. But with your help, I'm sure I will be able to.

[... skipped by RCL ...]



I'm terribly sorry, but right now I am on my vacations and can't check that. I'll be back in the middle of October :)

Cheers,
RCL
0

Share this post


Link to post
Share on other sites
I was just about to ask you if you had found the problem already since I didn't hear more about it. [wink]

OK, then I'll put this investigation on the shelf until you're back from your vacation. Thanks for letting me know.
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