IndexOutOfRangeException on CCRenderTexture.Begin() in v1.5.0.0.

I get an IndexOutOfRangeException the 100th time I run the Begin method of a CCRenderTexture. Here is an example that produces the error:

for (int i = 0; i < 100; i++) { CCRenderTexture rtm = new CCRenderTexture(new CCSize(50, 50), new CCSize(50, 50), CCSurfaceFormat.Color, CCDepthFormat.Depth24Stencil8); rtm.Begin(); rtm.End(); }

This only happens in the new version (v1.5.0.0) of CocosSharp. How can I fix this?

Posts

  • RamiTabbaraRamiTabbara AUMember, Xamarin Team Xamurai

    Hi Peter,

    As described here, v1.5.0.0 introduces the new renderer pipeline, which pushes all drawing commands for a given scene onto a render queue. Every draw call all these commands are potentially reordered, and then processed sequentially. In order to achieve this setup, the renderer maintains a stack of state parameters that correspond to certain types of draw commands --- in particular, setting up a CCRenderTexture requires state parameters related to the size of the render texture (among other things). Currently, the size of these parameter stacks is 100, which is why you're encountering your issue.

    We certainly can, and probably should, nicely handle dynamically increasing the stack size, however can you please describe the use case for needing such a large number of render textures? For performance reasons, render textures should be used sparingly, so perhaps there might be another approach to what you're trying to achieve.

  • PeterKrusagerPeterKrusager DKMember ✭✭

    Hey Rami

    I have a lot of sprites that need to change based on some user interactions. My thought was that I could save some space by rendering them on the fly since it doesn't seem to require that much performance and it wont happen so often. I am also rendering some of my menu controls this way which also makes it add up to the 100th. limit. I can save some of the sprites as resources, but the limit still seems weird.

  • RamiTabbaraRamiTabbara AUMember, Xamarin Team Xamurai

    Hi Peter,

    Can't you group the rendering of all the sprites into the one render texture? In other words, make the dimensions of the render texture larger and render the first sprite in the top corner, then the next adjacent to it etc.

    Then when you come to construct your sprite, along with providing the texture created, you specify the texRectInPixels that points to the subregion of the texture that corresponds to the given sprite. Basically, you're creating a sprite sheet on the fly.

    This would definitely help with performance on a number of fronts. Firstly, you're creating fewer render textures (1 vs. 100) and secondly, with the new renderer pipeline, there's the potential for automated batching of these sprites (especially if they're siblings of one another) because they're using the same underlying texture — just a different region of that texture.

  • PeterKrusagerPeterKrusager DKMember ✭✭

    Hey Rami

    Sounds interesting, I will give it try. Thanks.

Sign In or Register to comment.