problem with ScriptLimit

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

problem with ScriptLimit

Franco Ponticelli
Hi List,
I need an advice. I have a script that only receives a few call through external interface and operates like a super cookie.
The computation is really minimal but even so after 15 seconds I have a nice dialog stating " a script in this movie is causing adobe flash player 10 to run slowly ..." (this apparently happens only with the debug player).
Lurking on google I've found that the ScriptLimit/scriptTimeoutSeconds may be the cause. I've tried to change the timeout value with the attached script but after that operation the swf simply ceases to work without any kind of error.
I've found the script in the mailing list in an old post (I think the author is Jan J.Flanders)
Do you have any suggestion?
I really don't understand why a script with no loops, and no events can create such error, any idea?

Thank you,

Franco 

import format.swf.Reader;
import format.swf.Writer;
import neko.FileSystem;
import neko.io.File;
import neko.Lib;
import neko.Sys;
import haxe.io.BytesInput;
import haxe.io.BytesOutput;
import format.swf.Data;
import format.swf.Constants;
class ScriptLimit 
{
public static inline var MAX_VALUE = 256;
public static function main()
{
var args = Sys.args();
if (args.length < 1 || args.length > 2)
{
trace("invalid number of arguments");
return;
}
var src = args[0],
dst = args.length == 2 ? args[1] : src,
swfBytesInput = new BytesInput(File.getBytes(src)),
swfReader = new Reader(swfBytesInput),
header = swfReader.readHeader(),
tags = swfReader.readTagList();
swfBytesInput.close();

var data = new BytesOutput();
data.bigEndian = false;
data.writeUInt16(MAX_VALUE);//maxRecursionDepth
data.writeUInt16(MAX_VALUE);//scriptTimeoutSeconds
var found = false;
for (i in 0...tags.length)
{
switch(tags[i])
{
case TUnknown(id, _):
if (id != TagId.ScriptLimits) continue;
tags[i] = TUnknown(TagId.ScriptLimits, data.getBytes());
found = true;
break;
default: // do nothing
}
}
if(!found)
tags.unshift(TUnknown(TagId.ScriptLimits, data.getBytes()));

var swfBytesOutput = new BytesOutput();
new format.swf.Writer(swfBytesOutput).write({header:header, tags:tags});

var fout = File.write(dst, true);//output swf
fout.write(swfBytesOutput.getBytes());
fout.close();
}
}

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: problem with ScriptLimit

Dion Whitehead Amago
I don't know if this is a cause, but when an ExternalInterface call is
made, the Flash player waits until the external function returns.

To work around this, I made a remoting bidirectional async connection,
where, when Flash makes the ExternalInterface call, the javascript
part calls the function later on the next update using setTimeout, and
thus can immediately return (void) the ExternalInterface call,
allowing the Flash player to continue (and not hang).

The code is in the hydrax haxelib project if you need it.

Dion

On Wed, Aug 3, 2011 at 10:52 PM, Franco Ponticelli
<[hidden email]> wrote:

> Hi List,
> I need an advice. I have a script that only receives a few call through
> external interface and operates like a super cookie.
> The computation is really minimal but even so after 15 seconds I have a nice
> dialog stating " a script in this movie is causing adobe flash player 10 to
> run slowly ..." (this apparently happens only with the debug player).
> Lurking on google I've found that the ScriptLimit/scriptTimeoutSeconds may
> be the cause. I've tried to change the timeout value with the attached
> script but after that operation the swf simply ceases to work without any
> kind of error.
> I've found the script in the mailing list in an old post (I think the author
> is Jan J.Flanders)
> Do you have any suggestion?
> I really don't understand why a script with no loops, and no events can
> create such error, any idea?
> Thank you,
> Franco
> import format.swf.Reader;
> import format.swf.Writer;
> import neko.FileSystem;
> import neko.io.File;
> import neko.Lib;
> import neko.Sys;
> import haxe.io.BytesInput;
> import haxe.io.BytesOutput;
> import format.swf.Data;
> import format.swf.Constants;
> class ScriptLimit
> {
> public static inline var MAX_VALUE = 256;
> public static function main()
> {
> var args = Sys.args();
> if (args.length < 1 || args.length > 2)
> {
> trace("invalid number of arguments");
> return;
> }
> var src = args[0],
> dst = args.length == 2 ? args[1] : src,
> swfBytesInput = new BytesInput(File.getBytes(src)),
> swfReader = new Reader(swfBytesInput),
> header = swfReader.readHeader(),
> tags = swfReader.readTagList();
> swfBytesInput.close();
> var data = new BytesOutput();
> data.bigEndian = false;
> data.writeUInt16(MAX_VALUE);//maxRecursionDepth
> data.writeUInt16(MAX_VALUE);//scriptTimeoutSeconds
> var found = false;
> for (i in 0...tags.length)
> {
> switch(tags[i])
> {
> case TUnknown(id, _):
> if (id != TagId.ScriptLimits) continue;
> tags[i] = TUnknown(TagId.ScriptLimits, data.getBytes());
> found = true;
> break;
> default: // do nothing
> }
> }
> if(!found)
> tags.unshift(TUnknown(TagId.ScriptLimits, data.getBytes()));
> var swfBytesOutput = new BytesOutput();
> new format.swf.Writer(swfBytesOutput).write({header:header, tags:tags});
> var fout = File.write(dst, true);//output swf
> fout.write(swfBytesOutput.getBytes());
> fout.close();
> }
> }
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: problem with ScriptLimit

Franco Ponticelli
After further inspection the problem seems to be in the SharedObject I am using. After writing and flushing a few times it generates an error and the consequence is the pop-up message even if the error is intercepted.
I've tried to close and reopen the SharedObject but doesn't seem to help, any suggestion?

Anyway, thank you for your advice, my functions do not return anything and JS just move on happily.

Franco

On Wed, Aug 3, 2011 at 10:53 PM, Dion Whitehead Amago <[hidden email]> wrote:
I don't know if this is a cause, but when an ExternalInterface call is
made, the Flash player waits until the external function returns.

To work around this, I made a remoting bidirectional async connection,
where, when Flash makes the ExternalInterface call, the javascript
part calls the function later on the next update using setTimeout, and
thus can immediately return (void) the ExternalInterface call,
allowing the Flash player to continue (and not hang).

The code is in the hydrax haxelib project if you need it.

Dion

On Wed, Aug 3, 2011 at 10:52 PM, Franco Ponticelli
<[hidden email]> wrote:
> Hi List,
> I need an advice. I have a script that only receives a few call through
> external interface and operates like a super cookie.
> The computation is really minimal but even so after 15 seconds I have a nice
> dialog stating " a script in this movie is causing adobe flash player 10 to
> run slowly ..." (this apparently happens only with the debug player).
> Lurking on google I've found that the ScriptLimit/scriptTimeoutSeconds may
> be the cause. I've tried to change the timeout value with the attached
> script but after that operation the swf simply ceases to work without any
> kind of error.
> I've found the script in the mailing list in an old post (I think the author
> is Jan J.Flanders)
> Do you have any suggestion?
> I really don't understand why a script with no loops, and no events can
> create such error, any idea?
> Thank you,
> Franco
> import format.swf.Reader;
> import format.swf.Writer;
> import neko.FileSystem;
> import neko.io.File;
> import neko.Lib;
> import neko.Sys;
> import haxe.io.BytesInput;
> import haxe.io.BytesOutput;
> import format.swf.Data;
> import format.swf.Constants;
> class ScriptLimit
> {
> public static inline var MAX_VALUE = 256;
> public static function main()
> {
> var args = Sys.args();
> if (args.length < 1 || args.length > 2)
> {
> trace("invalid number of arguments");
> return;
> }
> var src = args[0],
> dst = args.length == 2 ? args[1] : src,
> swfBytesInput = new BytesInput(File.getBytes(src)),
> swfReader = new Reader(swfBytesInput),
> header = swfReader.readHeader(),
> tags = swfReader.readTagList();
> swfBytesInput.close();
> var data = new BytesOutput();
> data.bigEndian = false;
> data.writeUInt16(MAX_VALUE);//maxRecursionDepth
> data.writeUInt16(MAX_VALUE);//scriptTimeoutSeconds
> var found = false;
> for (i in 0...tags.length)
> {
> switch(tags[i])
> {
> case TUnknown(id, _):
> if (id != TagId.ScriptLimits) continue;
> tags[i] = TUnknown(TagId.ScriptLimits, data.getBytes());
> found = true;
> break;
> default: // do nothing
> }
> }
> if(!found)
> tags.unshift(TUnknown(TagId.ScriptLimits, data.getBytes()));
> var swfBytesOutput = new BytesOutput();
> new format.swf.Writer(swfBytesOutput).write({header:header, tags:tags});
> var fout = File.write(dst, true);//output swf
> fout.write(swfBytesOutput.getBytes());
> fout.close();
> }
> }
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: problem with ScriptLimit

Jan_Flanders
In reply to this post by Franco Ponticelli


On Thu, Aug 4, 2011 at 5:52 AM, Franco Ponticelli <[hidden email]> wrote:
. I've tried to change the timeout value with the attached script but after that operation the swf simply ceases to work without any kind of error.
I've found the script in the mailing list in an old post (I think the author is Jan J.Flanders)
Do you have any suggestion?


Hey Franco,

In a swf that contains AS3 bytecode the FileAttributes tag must be the very first tag (right after the swf header).
If it's not present or not the first tag, the FlashPlayer will use the AVM1 and will ignore any AS3 code in the swf.
Since the script you posted uses 'unshift' it will place the ScriptLimits tag before that FileAttributes tag and break the swf.

if you change:
if(!found)
    tags.unshift(TUnknown(TagId.ScriptLimits, data.getBytes()));

into:
if(!found)
    tags.insert(1, TUnknown(TagId.ScriptLimits, data.getBytes()));

it should work fine.

Cheers,

Jan

PS: I posted several of these scripts and one was to change the FileAttributes tag.
It looks like the 'unshift idea' comes from that script.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: problem with ScriptLimit

Franco Ponticelli
Hey Jan, thank you very much. I finally found that the problem where in having all the code executing in the same place. I added a timer that every 2 seconds recreates the SharedObject instance and that fixed the issue; note that recreating it when the external call was perfomed was not enough.

Thank you,

Franco

On Thu, Aug 4, 2011 at 5:47 AM, Jan Flanders <[hidden email]> wrote:


On Thu, Aug 4, 2011 at 5:52 AM, Franco Ponticelli <[hidden email]> wrote:
. I've tried to change the timeout value with the attached script but after that operation the swf simply ceases to work without any kind of error.
I've found the script in the mailing list in an old post (I think the author is Jan J.Flanders)
Do you have any suggestion?


Hey Franco,

In a swf that contains AS3 bytecode the FileAttributes tag must be the very first tag (right after the swf header).
If it's not present or not the first tag, the FlashPlayer will use the AVM1 and will ignore any AS3 code in the swf.
Since the script you posted uses 'unshift' it will place the ScriptLimits tag before that FileAttributes tag and break the swf.

if you change:

if(!found)
    tags.unshift(TUnknown(TagId.ScriptLimits, data.getBytes()));

into:
if(!found)
    tags.insert(1, TUnknown(TagId.ScriptLimits, data.getBytes()));

it should work fine.

Cheers,

Jan

PS: I posted several of these scripts and one was to change the FileAttributes tag.
It looks like the 'unshift idea' comes from that script.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org