StarlingGraphics / Starling-Extension-Graphics

flash.display.Graphics style extension for the Starling Flash GPU rendering framework
https://github.com/StarlingGraphics/Starling-Extension-Graphics/wiki
MIT License
285 stars 88 forks source link

Stroke error with latest Starling build #62

Closed ctinach closed 10 years ago

ctinach commented 11 years ago

Hello,

Just switched from SWC to the latest source for the Starling Graphics Extension and I keep getting this error :

The index 4294967295 is out of range 0. at starling.display.graphics::Stroke$/fixUpPolyLine()[----\src\starling\display\graphics\Stroke.as:422].

I'm using the latest Starling source.

IonSwitz commented 11 years ago

Thanks for letting me know. I will check on this. Could you give some small piece of sample code that triggers this behavior? It would help alot. Thank you.

ctinach commented 11 years ago

I get this for any Stroke object I try to use. Something basic like this:

landStroke  = new Stroke();
landStroke.material.fragmentShader =  new TextureFragmentShader();                  
landStroke.material.textures[0] = Assets.getTexture("grassTexture");

for ( j  = 0; j < ppp; j++ )
 {
     landStroke.addVertex(_tt[j].x   , _tt[j].y       , 64); 
}

parent.addChild(landStroke);

always fails with the error above.

I'm not doing anything special with Strokes. It just "dies" when it reaches fixUpPolyLine function for the first Stroke it encounters. It doesn't matter how many vertexes I add.

I understand from another user on the Starling forums(http://forum.starling-framework.org/topic/latest-starling-graphics-extension-and-starling-14-error ) that fixing this issue (https://github.com/StarlingGraphics/Starling-Extension-Graphics/issues/54) started causing the error.

IonSwitz commented 11 years ago

The problem seems to be fixUpPolyLine and the dangerous use of an "uint" here:

var idx:uint = vertices.length - 1;

when vertices.length is 0 , this will completely break, since "idx > 0" will return true.

If you want to keep on working, you can change the uint to an int and this should fix your problem.

I am unable to run any code at the moment, I\m getting this from just reading the code off the web site here, but I am pretty sure its a foul uint issue here. Please try it and let me know how it goes.

IonSwitz commented 11 years ago

Hello, @ctinach.

Since I dont know what is in your _tt-vector there, or what ppp is in your example, I have tried this, which works fine:

var landStroke:Stroke = new Stroke(); landStroke.material.fragmentShader = new TextureFragmentShader(); landStroke.material.textures[0] = Texture.fromBitmap( new GlowTiledBMP(), false );

landStroke.addVertex(100 , 100 , 64); landStroke.addVertex(200 , 100 , 64); landStroke.addVertex(200 , 300 , 64); landStroke.addVertex(500 , 500, 64);

addChild(landStroke);

However, if I remove the addVertex operations, I get your result. Have you checked that you are actually adding any vertices in your loop there? What is the values in the _tt-array, and what is the upper bound, ppp ?

IonSwitz commented 11 years ago

I have checked in a fix for the uint-crash, also adding a blocker in buildGeometry for the cases where the _line.length is 0. It caused some odd issues.

However, I do believe that the problem only occurs when there are no vertexes added, so please check over your code again, to make sure that your loop actually adds the vertices to the stroke. :)

Thanks!

ctinach commented 11 years ago

I don't get any errors now. It turns out that I was using a Stroke object without vertexes at a point in my game logic. I have a dynamically drawn Stroke that is instantiated without vertexes and update on certain events by calling stroke.clear(); and adding other vertexes. Now I don't get any errors but calling clear() on a Stroke seems to leave some vertexes in place - a small piece of the Stroke is still rendered. I fixed it by adding a visible=false; to the hole object but the clear() method might be affected by the changes - haven't had the time to test it properly.

Thanks for your help and all the effort you put into this extension.

IonSwitz commented 11 years ago

The clear method might be a bit of a misnomer, it does not clear out the already drawn graphics, only the line data that is used for the stroke. So if you call clear, and then start adding vertices again, the graphic will redraw.

Thanks for your feedback!

IonSwitz commented 10 years ago

Closing this Issue