• Advertisement
Sign in to follow this  

Problem with deleting the engine and context.

This topic is 4836 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My program keeps crashing after i instantiate an engine or context object when i go to close my program. i get an unhandled exception. If i omit all of my AS code, the program terminates fine. this is my code:
	int result;
	asIScriptEngine* ASEngine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
	asIScriptContext* ASCtx;
	//RegisterEngineObjects(ASEngine);
	ASEngine->AddScriptSection(0, "section", Script, (int)strlen(Script), 0);
		
	COutStream out;
	
	ASEngine->Build(0, &out);
	if(Errors.GetLength() > 0)
	{
		MessageBox(0, (LPCTSTR)Errors, 0,0 );
		Errors = "";
		return;
	}
	result = ASEngine->CreateContext(&ASCtx);
	result = ASCtx->Prepare(ASEngine->GetFunctionIDByDecl(0, "void main()"));
	result = ASCtx->Execute();


	result = ASCtx->Release();
	result = ASEngine->Release();

Share this post


Link to post
Share on other sites
Advertisement
What is Errors.GetLength()? I assume it holds the compiler messages from the Build() call. You really ought to verify the return message from the Build() call instead.

I can't see any obvious errors with your code. You'll need to verify the return codes for each of the calls. AngelScript returns a negative value on error (the exact meaning of the value can be seen in angelscript.h).

Also make sure the ctx is not null when calling Release() on it.

Share this post


Link to post
Share on other sites
The script builds fine, no errors are generated during the building of the script or during the registration of the script.

Nor are any errors reported when releasing the context or the engine.

After any script runs, even a

void main()
{
return;
}

will generate the error.

The error does not surface at anytime during the execution of the script, nor does it occur in the code block where i instantiate and execute my script.

It surfaces when i exit my program and the program attempts MFC standard cleanup code. im going to try WIP4 to see if it is a WIP5 specific problem.

Share this post


Link to post
Share on other sites
Fixed it. Was with a global CString object that i used to report my errors. Instead i encapsulated it within a COutStream class. Works really well now.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement