What is the indexBuffer, and what might cause me to run out of them? - actionscript-3

I am making a flash game using Flare3D and when i load a new scene it give me this error:
Error: Error #3691: Resource limit for this resource type exceeded.
at flash.display3D::Context3D/createIndexBuffer()
at flare.core::Surface3D/upload()[Z:\projects\flare3d 2\src\flare\core\Surface3D.as:237]
at flare.core::Mesh3D/upload()[Z:\projects\flare3d 2\src\flare\core\Mesh3D.as:130]
at flare.core::Mesh3D/draw()[Z:\projects\flare3d 2\src\flare\core\Mesh3D.as:335]
at flare.basic::Scene3D/render()[Z:\projects\flare3d 2\src\flare\basic\Scene3D.as:593]
at flare.basic::Scene3D/enterFrameEvent()[Z:\projects\flare3d 2\src\flare\basic\Scene3D.as:461]
I am guessing from the error that it is running of something, but I don't know what the Context3D.createIndexBuffer() does. Since flare3D is not open source I can't dig in for any clues there.
So i want to know: what is teh Context3D IndexBuffer, and what might make me run out of that resource type?
And please don't just link to the ASDocs for those classes, I have looked and they do not answer this question.

I could be wrong, but I'm guessing they are talking about the same Index Buffers that are used in OpenGL and DirectX. They are arrays of integers that are indices into a vertex array so that when drawing multiple polygons that share vertices, you don't have to specify the entire vertex every time.
This is a relatively good explanation:
http://openglbook.com/the-book/chapter-3-index-buffer-objects-and-primitive-types/#toc-enter-index-buffers
I don't know anything about Flare3D, but is it possible that your scene has too many complex meshes and is running out of memory for index buffers?

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.

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

StackOverflow Errors caused by flood fill: How to stop the error?

For my level editor in my game, I have a floodfill function. The map has a size of 3600 tiles (60 by 60), and I get a stack overflow error from my floodfill function (as it calls itself).
If I only floodfill a smaller radius, it works fine. How do I stop the error from occuring?
Alternatively, is there a way to tell the flash runtime to clear the stack as there is no need to return back to the function?
You need to make a flood fill function that doesn't rely on recursion because Flash's stack is quite limited. You can find some non-recursive ways on Wikipedia: http://en.wikipedia.org/wiki/Flood_fill#Alternative_implementations
I'm guessing you might be using a simple recursive implementation of flood-fill; that algorithm can create deep stacks. It's possible you could implement one of the more efficient queue based algorithms and save the stack, however I would suggest using the already built-in flood-fill capabilities of the BitmapData object.
BitmapData is provided by the Flash Player and has a pretty fast and stack friendly flood-fill implementation.
I was playing with flood-fill algorithms a while back and ended up using the built-in APIs mainly because of the speed advantage -- as well it's compiled C code vs ActionScript.
Here are the docs:
flash.display.BitmapData floodFill()

AS3 Error #1502

AS3
Error: Error #1502: A script has executed for longer than the default timeout period of 15 seconds.
Is there a way to temporarily suppress this on a specific block of code?
I am creating a HUGE dynamic 3d array of objects, 1000x1000x1000 and need the build to actually finish the initializing.
Your best bet would be to try and refactor your code. Perhaps you can make use of this tutorial which deals with the exact problem you are having.
http://www.senocular.com/flash/tutorials/asyncoperations/
Increasing the timeout is one option, however I would also suggest considering an approach that would build your arrays over multiple frames, that is splitting the work up into separate jobs. As long as you give control back to the Flash Player every once in a while, you will not get this exception.
I'm not certain of the specifics of your problem, however you will need to find a way to parallelize or just simply segment your calculations. If your algorithm centers around one major loop, then consider creating a function that takes all of the arguments necessary to record the context of a single iteration. Then, create a simple control loop that will call this function and determine when to wait until the next frame and when not to. Leveraging AS3 closures can also help with this.
Look for the script execution time limit in the "Publish Settings" (Flash). If you're using Flex, maybe this one can be useful: http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_14.html (check default-script-limits, max-recursion-depth, max-execution-time). Oh! It seems there's apparently no way to make it behave in a different way on a specific piece of code (it is a global setting).
I do not approve the increse timeout option. Because for all this time your appllication is just hangs the whole Flash player. And normaly user thinks it is down, and forses it to quit.
check this one out: How to show the current progressBar value of process within a loop in flex-as3?
And then you can even show the progress which would be really more confident for you and for user.

AS3: Faster to use EventListeners or ArrayLoops?

I am writing a game in AS3 and have, as an example, around 40 objects on screen. Let's say they are clouds. I'm wondering which of the two paths would be less a strain on system resources:
a) Put an eventListener on each object and have it update itself, or
b) Loop through the array and manually update each object
Or is the performance difference negligable? Does either solution scale better than the others?
I would expect the performance to be fairly negligable either way. Once you get a lot of objects you might see a difference (with the loop being the winner). From my experience Adobe put a lot of work into optimizing the actionscript event listener path.
This is a tricky one, purists would say to to go with the array looping method, as with this method it would be possible to cut out the 'view' out of the MVC and still have the system working (which is a good test of any system). However, if you are working with the events you can cut some corners with event bubbling and strict typing.
For example if we assume you make a custom event called CloudEvent that has a property called cloud that contains a reference to the dispatching CloudSprite, then as long as the event bubbles by default, you don't need to add an event listener to each one, just to the DisplayObjectContainer which holds them (which I am imaginatively calling CloudContainer). This way the event bubbles up and you only have to add one listener, and don't have to worry about managing listeners on child items.
public function CloudContainer()
{
super();
addEventListener(CloudEvent.CHANGE, cloudChangeHandler);
}
private function cloudChangeHandler(evt:CloudEvent):void
{
var cloud:CloudSprite = evt.cloud;
cloud.update();
}
Hope this helps
I am under the impression that event listeners require more resources so it is better to use an array when performance is required. It would also scale better for that reason. If you are using Flash 10 then use a Vector, I believe it offers better performance than an array (and type saftey).
Use EventListeners! Just make sure you manage them properly ie. remove them when you done, use weak references.
You wont really find much performance from doing things like this. Usually better performance comes from the bigger ticked items, like not using filters, lowering the frame-rate etc. So punishing your code clarity and OO for the sake of a half a millisecond is not worth it in my book.
There are a few really great guides out there that will teach you all about optimizing in AS3. The best one I have found is Grant Skinner's; AS3 Resource Management. And I just found a quicker seven step version. I would definitely recommend everyone doing AS3 should read the Grant Skinner slides though.
Of course don't just take my word (or anyone else answering your question), you can do you own tests and actually see whats up using a profiler. See Lee Brimlow's latest video tutorial for how to do this. It is worth the watch! Check it out here: GotoAndLearn - ActionScript 3 Performance Testing.