🎉 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!

Crash on preparing context

Started by
8 comments, last by WitchLord 5 years, 7 months ago

asIScriptModule *mod = engine->GetModule("ScriptModule");
	asIScriptFunction *func =  mod->GetFunctionByDecl("void main()");
	if( func == 0 )
	{
	  // The function couldn't be found. Instruct the script writer
	  // to include the expected function in the script.
	  printf("The script must have the function 'void main()'. Please add it and try again.\n");
	  return;
	}
	// Create our context, prepare it, and then execute
	asIScriptContext *ctx = engine->CreateContext();
	ctx->Prepare(func);
	int r = ctx->Execute();
	if( r != asEXECUTION_FINISHED )
	{
	  // The execution didn't complete as expected. Determine what happened.
	  if( r == asEXECUTION_EXCEPTION )
	  {
		// An exception occurred, let the script writer know what happened so it can be corrected.
		printf("An exception '%s' occurred. Please correct the code and try again.\n", ctx->GetExceptionString());
	  }
	}

When my program reaches ctx->Prepare(); the program crashes. Does anybody know how to fix it?

If you need, I can give you the whole code.

Advertisement

There are no apparent errors in the code snippet you posted. With just this information it is not possible to identify the cause of the crash.

Can you show the trace back on the stack when the crash happens? Have you tried debugging the code to see if you can identify the cause of the error?

Have you made any customizations to the library? What engine configurations are you using? 

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

1 hour ago, WitchLord said:

There are no apparent errors in the code snippet you posted. With just this information it is not possible to identify the cause of the crash.

Can you show the trace back on the stack when the crash happens? Have you tried debugging the code to see if you can identify the cause of the error?

Have you made any customizations to the library? What engine configurations are you using? 

I use 2.32.0 version. I made no customizations to the library.

screenshot.png

Oh, never mind. Everything is okay, I just registered the function the wrong way.

Can you expand on the solution a little bit? I'd have for someone to find this page through Google and there not being any real answer :)

3 hours ago, Miss said:

Can you expand on the solution a little bit? I'd have for someone to find this page through Google and there not being any real answer :)

My mistake was in the section of code where I registered the functions.

I did it like this:


r = engine->RegisterGlobalFunction("void PrintDebugString(string &in)", asFUNCTION(PrintDebugString), asCALL_CDECL); assert( r >= 0 );

And to fix this crash, I replaced


void PrintDebugString(string &in)

With


void PrintDebugString(const string &in)

 

The way you registered the function shouldn't cause a crash in ctx->Prepare(), since Prepare doesn't actually call any of the registered functions. Are you sure the crash didn't happen within ctx->Execute()? 

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

45 minutes ago, WitchLord said:

The way you registered the function shouldn't cause a crash in ctx->Prepare(), since Prepare doesn't actually call any of the registered functions. Are you sure the crash didn't happen within ctx->Execute()? 

ctx->Execute doesn't run without context being prepared

Just noticed you had posted the trace back I asked for (somehow I completely ignored the image). That clearly shows the crash is within Execute, and not in Prepare.

 

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

This topic is closed to new replies.

Advertisement