Jump to content
  • Advertisement
OmniGamer

Crash on preparing context

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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? 

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
Share on other sites
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)

 

Share this post


Link to post
Share on other sites

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()? 

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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.

 

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!