Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


- - - - -

Problem (bug?) when releasing suspended context


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 RCL   Members   -  Reputation: 122

Like
0Likes
Like

Posted 19 September 2004 - 07:48 AM

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

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3438

Like
0Likes
Like

Posted 19 September 2004 - 09:26 AM

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.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#3 Andreas Jonsson   Moderators   -  Reputation: 3438

Like
0Likes
Like

Posted 20 September 2004 - 07:11 AM

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.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#4 RCL   Members   -  Reputation: 122

Like
0Likes
Like

Posted 20 September 2004 - 10:21 PM

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

#5 Andreas Jonsson   Moderators   -  Reputation: 3438

Like
0Likes
Like

Posted 21 September 2004 - 03:25 AM

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.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#6 RCL   Members   -  Reputation: 122

Like
0Likes
Like

Posted 28 September 2004 - 02:37 AM

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


#7 Andreas Jonsson   Moderators   -  Reputation: 3438

Like
0Likes
Like

Posted 28 September 2004 - 02:43 AM

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.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS