🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Problem with deleting the engine and context.

Started by
2 comments, last by Rain Dog 19 years, 8 months ago
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();

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.

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

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

This topic is closed to new replies.

Advertisement