Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Problems building scripts


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
5 replies to this topic

#1 Malmer   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 June 2004 - 03:43 AM

When compiling any script I get this type of error. Building... Parsing: "data/ai/ship.script" Error : (17, 1) Unexpected token '''' Completed. (errors: 1, warnings: 0) Row 17 is the last row of that script, so apparently there is something wrong with the ending of the script code. This is how I load the script:
// Load the file
FILE * File = fopen( CUtil::GetPath( filename ), "rb" );
if ( File == NULL )
{
	...
}

// Get file size
int size = _filelength(_fileno( File ));
	
// Get file contents
char * scriptcode = new char[ size + 1 ];
fread( scriptcode, size, 1, File );
fclose (File);
scriptcode[ size ] = NULL;

// Load into scriptengine
int result = m_ScriptEngine->AddScriptSection( filename, scriptcode, strlen( scriptcode )+1 );
	
// Free memory
delete [] scriptcode;
 
As you can see I properly make sure the string is null-terminated. Some other comments: * If I do AddScriptSection and don''t do the +1 on strlen then the entire app crashes. * I''ve tried with using acCString in exactly the same way as in the downloadable sample, no luck. And a difference there also is that while it worked with just using "len" for strlen, I had to use len+1 or else it would crash. The difference with mine and the sample is that the sample uses 1.6.1, while I use 1.7.1. It also uses an external dll, while I don''t. * I''ve tried with different encodings of my script. Both DOS and UNIX. Also tried with the sample script. No luck. * Outputting the string data to my debug window shows nothing strange in the end of the file data stream. What is wrong?

Sponsor:

#2 Malmer   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 June 2004 - 04:49 AM

The bug appears when compiling with the Visual C++ Toolkit 2003 compiler, which is the same as in new versions of VC++. Available free.

Think it has something to do with different memory handling.

[edited by - malmer on June 10, 2004 11:49:57 AM]

#3 Desdemona   Members   -  Reputation: 158

Like
Likes
Like

Posted 10 June 2004 - 05:18 AM

I''ve experienced problems like this, but the problems were usually inside the actual script file. Maybe you could post that?

#4 Malmer   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 June 2004 - 05:24 AM

It works perfectly when I compile the same application with the VS6 compiler, so it has to be something with compiler differences.

Lib author: If you want to add a check for the VC7 compiler you can do like this:

#if (_MSC_VER >= 1300) // Visual Studio .NET

#endif

#5 Malmer   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 June 2004 - 05:36 AM

To fix the bug change:


int asCBuilder::AddCode(const char *name, const char *code, int codeLength)
{
asCScriptCode *script = new asCScriptCode;
script->name = name;
script->code.SetLength(codeLength);
memcpy(script->code.AddressOf(), code, codeLength);

scripts.PushLast(script);

return 0;
}


into:


int asCBuilder::AddCode(const char *name, const char *code, int codeLength)
{
asCScriptCode *script = new asCScriptCode;
script->SetCode( name, code );
scripts.PushLast(script);

return 0;
}


The last code sample also works in the old compiler. The old code didn''t nullterminate the string put into script->code. That, by luck, worked ok in the old compilator. Did not in the new. The SetCode method that allready exists in the lib does it correctly, by adding a nullterminate to the script->code buffer.

#6 Andreas Jonsson   Moderators   -  Reputation: 3304

Like
Likes
Like

Posted 10 June 2004 - 05:58 AM

Well, it seems you found the bug already I''ll add the fix to the library as soon as possible. Thanks letting us know.

Regards,
Andreas



__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library - 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