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

Bugfix for handleGraphicsDataType() #98

Closed mimamuh closed 9 years ago

mimamuh commented 10 years ago

Bugfix a type coercion error in handleGraphicsDataType() when calling drawGraphicsData() with a Vector. :: The crash only happens when packaging the code for iOS in Ad Hoc mode. It throws an Error #1034: Type Coercion failed: cannot convert Vector. to ..

IonSwitz commented 10 years ago

Thank you for this!

However, what happens in drawPath when the conversion fails with the new code, and the method drawPath receives null values as arguments? Won't this just delay the problem, or lead to graphics that silently fails to draw?

mimamuh commented 10 years ago

Hm. Maybe you are right, ... :) I don't know right now. But the conversion shouldn't fail due to the if( gfxData is flash.display.GraphicsPath ), or?

IonSwitz commented 10 years ago

It is unfortunate that it only happens in such a special case, I will be unable to reproduce it.

What is the full error message? You wrote

"Error #1034: Type Coercion failed: cannot convert Vector. to..."

but what type comes after the "..." ? :)

Probably it would be better with an if-statement, but I wonder very much what other type that can be received here.

mimamuh commented 10 years ago

Okay, the Problem is, I think, when handleGraphicsDataType() is called, gfxData is a type of flash.display.IGraphicsData but flash.display.GraphicsPath() needs at the first parameter a Vector.int and it seems, that cause the error? But I'm sorry, the Error message didn't give me more than a dot after the to. It says only:

Error #1034: Type Coercion failed: cannot convert Vector.int to .

IonSwitz commented 10 years ago

Oh, ok. What an odd error message :)

But, ok, I will look at this sometime soon, but I really can't say what can be done if I can't reproduce the bug.

It would be easier if you could experiment a bit and try to find a way around the problem, maybe creating a local variable that receives the type cast, and if that fails, and the variable becomes null, we can at least get rid of the crash?

mimamuh commented 10 years ago

Okay, I've made a test: The type casting itself works fine: var temp:flash.display.GraphicsPath = flash.display.GraphicsPath(gfxData);

And the code even works fine if I'm using this afterwards: drawPath( temp.commands, temp.data, temp.winding);

I think it's a bug of the compiler or so when he tries something like that: flash.display.GraphicsPath(gfxData).commands

as when I'm trying the following: var temp2:Vector. = flash.display.GraphicsPath(gfxData).commands;

it fails again, as said, only in ad-hoc mode and ios.

It doesn't makes any sense, but it is so. :) And maybe it is an old problem: http://forums.adobe.com/thread/1089172

Okay, thank you IonSwitz for your help!!! ;)

IonSwitz commented 10 years ago

Ok, those problems seem related. Wow, what a mess. I then believe that it isn't a Starling Graphics Extension problem. So thank you for finding the adobe-thread.

IonSwitz commented 10 years ago

I have checked in an attempt to avoid this crash. However, if you reach this part of the code, and the type casts fail, the graphics will obviously not be drawn. But I hope this at least fixes the crash.

mimamuh commented 10 years ago

Hi IonSwitz, thx!!! I've tested it in ad-hoc mode and it works great. :)

The last days I used the following fix which even works for my purposes: if( gfxData is flash.display.GraphicsPath ) { var gfxPath:flash.display.GraphicsPath = flash.display.GraphicsPath(gfxData); drawPath( gfxPath.commands, gfxPath.data, gfxPath.winding); }