Scaleform BitmapData: Invalid Bitmapdata - actionscript-3

I'm trying to add a "on fire effect" to our UI.
I am achieving this using BitmapData and PerlinNoise and some others.
The issue comes when anything I do with the BitmapData causes this error:
ArgumentError: Error #2015: Argument error: Invalid BitmapData.
at effects::FireFX/updateBitmaps()...
Something as simple as this will cause the error to show up.
displayBmp = new BitmapData(200, 200, true, 0);
scratchBmp = displayBmp.clone();
In my case, functions like clone() or perlinNoise() or colorTransform.... etc... are causing the crash.
Debugging / Running it under Animate CC works just fine.
PD: Publishing to Flash 10.3, using Scaleform: 4.1.19
Thanks

Scaleform does support the BitmapData API, as of version 4.1 (reference). However, 4.1.19 was the first release of 4.1, and thus the initial release with BitmapData support. You may want to upgrade to a newer version, as there have certainly been fixes to the BitmapData support since its initial release.
The most common reason to get this error, is to not pass a ThreadCommandQueue instance into MovieDef::CreateInstance as the last parameter, and BitmapData operations are used on the first frame. Without an instance of the ThreadCommandQueue, the renderer cannot create the backing for the BitmapData objects within Scaleform. A more descriptive warning was added to Scaleform in later versions.
For ThreadCommandQueue, you generally need to implement this yourself, to integrate properly with your application's rendering code. The simplest multi-threaded implementation would simply store ThreadCommand objects in a (thread-safe) list, when called from PushThreadCommand, and call Execute on the objects at some point during the application render loop.
In later versions of the SDK, there is a class provided called SingleThreadedCommandQueue, which provides an basic implementation that will execute all commands immediately. This only works if you are using Movie::Advance and HAL::Display on the same thread. You can see a more complex version of a ThreadCommandQueue implementation, used in the Scaleform samples from the RenderHALThread class, which defers most of the important implementation to RTCommandQueue.

Related

Is It Possible To Write WebGL in the Chrome Javascript REPL?

Usually when using WebGL one writes most of the graphics code in a function bound to window.onload. For the sake of REPL-style graphics development, is it possible to write that OpenGL code interactively in the javascript console?
Of course it is but WebGL is a very verbose API. You have to upload, compile and link shaders, look up attributes and uniforms, create buffers and textures and upload data into each, then bind all textures, buffers, set attributes, and set uniforms and finally call a one of the draw functions
Doing that all from a REPL would be pretty tedious and error prone.
That said when I'm debugging I often paste something like this into the devtools REPL
gl = document.querySelector("canvas").getContext("webgl");
Which will give me the WebGLRenderingContext for the first canvas in the page (which is usually what I want). I can then for example check if there's an error
gl.getError();
Another common thing I do is check the available extensions
document.createElements("canvas").getContext("webgl").getSupportedExtensions().join("\n");
Otherwise if you're looking for editing WebGL in real time that's usually limited to things like glslsandbox.com or vertexshaderart.com where you're just editing a single shader that's used in a single way and not using the entire WebGL API in a REPL. There's also shdr which gives you a single model and a both a vertex and fragment shaders to work with.
If you really want a REPL you probably need some engine above it in which case it would be a name-of-engine REPL and not a WebGL REPL.

Have Adobe changed Flash's ExternalInterface marshalling?

I have an application written in ActionScript 3 which has to run on all versions of the Flash runtime, including the latest - Flash 18.
One section of my code passes a rather complex object (actually a tree of objects) from AS3 to JS via ExternalInterface.call(). The object has internal cyclic references, and it always used to work, up to and including Flash version 17.
In Flash 18 this object no longer gets passed, there is a very long pause, and a stack overflow is thrown. Upon further inspection (with the debugger and FlashBuilder) I find that the pause is in a toJSON method getting called recursively (obviously not correctly handling the cycles in my object).
The documentation for ExternalInterface states that marshalling is done using XML and in the past I've had problems when I've tried to marshal data that can't be represented easily in XML but would work in JSON, I now appear to be having the opposite issue, and this is quite a backward step if cyclic references in existing compiled applications will now break.
Has anyone else seen this issue?
Do we know if this is intentional, permanent, and/or documented? It doesn't appear in the release notes for Flash 18, so far as I can see.

AS3 Starling custom shader crash "Error #3600: No valid program set" when computer is locked or put to sleep

I'm working on a Flash game using Starling, and I have started coming across an issue where my render crashes immediately after I put my PC to sleep/lock it and then turn it back on. The error I'm getting is:
Error #3600: No valid program set
I was not able to find any advice online on how to prevent this/re-initialize everything appropriately. I'm assuming this is part of a wider issue with how Flash/Starling handles the computer being put to sleep/locked.
Things I have tried so far:
Catching the error and re-uploading the shader programs.
Setting Starling.handleLostContext to true
Has anyone come across this issue before? Any help/pointers would be greatly appreciated.
It sounds like your game is losing the GPU context.
On context loss, all GPU data is lost. You have to restore textures, vertex buffers, etc. Starling handles some of it for you when you set handleLostContext to true, but you still have to handle the textures.
If you use the AssetManager, it will handle re-uploading textures for you, which is clearly the easiest way to go. It automatically creates a texture.root.onRestore callback function which Starling calls after it re-creates the context, and it will attempt to re-load your textures from wherever you first loaded them from, whether from disk, an embedded asset, or a URL.
You can also manually define the function yourself, though that is more complicated and as the article mentions, some gotchas are involved.
More information: http://wiki.starling-framework.org/manual/context_loss

Word-VBA Functions "Method Saveas2 of object failed"

I have an access-vba application that also makes use of word-vba. While running the application on my local machine, it functions well. Once it is moved to others (same versions of access and word) it will crash when it comes to the vba portion of word. Commands such as document.open or .saveas2 fail: Method 'SaveAs2' of object failed for example.
I've also noticed that libraries that I've referenced in the application are required by any other end user. I'm used to just compiling with the libraries and from that point they are always included in the .jar/.exe/etc, but, it seems when you move the application to other's computers it's always trying to recompile?
I'm not well versed in VBA so I'm speculating that my failing word-vba functions are because of a referencing error, any other ideas?
The "libraries" that VBA can reference are actually COM objects, usually packaged as DLL files. They are objects which are dynamically instantiated at runtime (if they aren't already) when requested. They are loaded by Windows into memory and your program uses the COM standard to interact with them, calling methods and getting or setting properties (interprocess communication). There are generally two ways of interacting with them: early binding and late binding.
With early binding, you add a reference to the library while you are still writing code, which allows the VBA IDE to provide autocompletion and some compile-time error checking. You instantiate objects with the "new" keyword and by directly typing the object name. However, early binding requires that you select a specific dll and possibly a specific version of the interface. This can lead to issues if you reference a specific interface version which one of your users doesn't have.
With late binding, you instantiate objects using CreateObject or GetObject, requesting them by name from Windows. Windows will look the name up and return a reference to the object. The variables in your code are simply objects and calling methods is a bit dangerous because the compiler allows you to type in whatever method name you want and provides no compile-time warnings. This has the advantage that as long as you are calling well established methods and nothing new or deprecated, the code will work regardless of the user's version.
As for the error you are getting, you may want to check the version of Office on the user machines - SaveAs2 was added in Office 2010.

Is it possible to write an AS3 library with Haxe that uses type parameters?

First a little background: I'm looking for a way to create a "collection" library that abstracts the Flash Player version based implementation (Vector on FP10, Array on FP9) away from the calling code. I've already written a small AS3 lib doing that but...
...the performance is bad (especially because of two levels of indirection and the runtime type checks on the Array implementation)
...the code is ugly (since Vector types need to be defined at compiletime I needed a factory returning concrete Vector instances based on an Enum that contains only the supported types)
I'm currently looking into Haxe as a possible solution since it supports type parameters and is able to compile to various Flash Player versions (and apparently compiles into mmore optimized bytecode).
Now, my question is: Is there a way to write a library in Haxe that can be used like this in AS3 code
var foo:IMyInterface = new MyImplementation(int);
var bar:IMyInterface = new MyImplementation(getDefinitionByName("my.package.MyClass"));
with IMyInterface exposing the required methods (push, pop, ...)?
The basic idea is that I want to provide the type information at runtime and get a typesafe Flash Player version independent "collection" for use in the calling code without having to bother with conditional compilation fragments all over the place.
Can Haxe do something like that and if yes, how can I make it work?
There's an opportunity in Haxe to override native classes (e.g. int) in Haxe. take a look at the Metadata manual. Metadata has been added in version 2.06.
As for analogue of getDefinitionByName() method. Take a look at resolveClass() method of the Type class.