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

Graphics stop working after Context loss #110

Closed ddoerr closed 8 years ago

ddoerr commented 10 years ago

I have a simple drawing screen in my app for iOS.

bildschirmfoto 2014-05-09 um 09 48 48

Works fine until i take a photo on another screen of my app, which leads to a lost context, then when i come back to the drawing it doesnt work at all. Touch event fires, but no lines are drawn. Any ideas? (iPad, AIR 13, iOS7, Starling 1.4.1, Feathers 1.2)

ddoerr commented 10 years ago

Nobody? Still not working...

IonSwitz commented 10 years ago

I can probably look into this tonight.

Have you done any debugging on your own, stepping into the Graphics code? If so, please share any insights.

I am using the Graphics API to draw lines and they restore properly on a lost context scenario, not sure what is different here.

ddoerr commented 10 years ago

Ok thank you. I didnt step into the Graphics code. I am not sure whats happening. As i said the code above draws lines into my canvas, after a lost context it stops working and wont draw anything at all.

zenrobin commented 10 years ago

We use the Graphics extension quite a bit in our app, though not precisely with your test case.

And at one point we had a similar issue mostly on older android systems and Kindle Fire. But that was mostly solved by running in "single top" mode, and updating to the latest Graphics extension which added onGraphicLostContext which forces FastSTroke to redraw vertices.

It seems like you're losing context. So I'd put a breakpoint in your onActivate and onGraphicLostContext to be sure that the appropriate events are being fired to allow the extension to recover.

As a distantly related side note, if you use render textures and lose context on iOS, you'll need to manually handle that by saving the render textures to memory: Starling doesn't account for renderTextures during a lost context scenario. (Our drawing tool uses bitmap data, not vector).

ddoerr commented 10 years ago

@zenrobin I am still searching for a solution. Where do i find those onActivate and onGraphicLostContext methods you mentioned? I doublechecked if i have the newest verison of the extension.

@IonSwitz I'm using Feathers and the drawing happens in a FeathersControl inside a Feathers Screen, could that be the difference? Can u maybe give me some example code of yours and i'll try to compare?

I really need a solution for this, its a show stopper for my app and customers. I am willing to give a reward to someone who helps me find a solution :)

zenrobin commented 10 years ago

onActiviate is in Starling

NativeApplication.nativeApplication.addEventListener(flash.events.Event.ACTIVATE, onActivate, false, 0, true);
NativeApplication.nativeApplication.addEventListener(flash.events.Event.DEACTIVATE, onDeactivate, false, 0, true);

onGraphicLostContext can be found in Graphic.as and FastStroke.as in display.graphics

I recommend you simplify your test case. Make a shape, draw a rectangle with it, make it big and red, add it to the starling stage (not in feathers, not anywhere else).

Then leave the app and return to cause a context loss. If the red shape is still visible, then you probably have successfully recovered from the context loss.

If that works for you, gradually make the test case more like your drawing code and eventually you'll find the difference maker.

ddoerr commented 10 years ago

@zenrobin Ok, onGraphicLostContext and onContextCreated never fires, but i assume thats because there are no graphics in my app wenn the context loss happens, it happens on a different screen. Then when i go back to my screen where the drawing happens my red shape (drawRect) wont draw.

ddoerr commented 10 years ago

Yes! Thanks a lot for your help. That is the problem. When i draw a little shape in my main Screen on top over my whole app, the event fires when the context is lost on my other screen, then when i come back to my drawing screen it works! Very happy to see it working. Cannot believe nobody had that problem before. There must be another workaround than keeping a little transparent shape (in my case a rectangle) on the screen at all times.

IonSwitz commented 10 years ago

When you are using multiple screens with the Graphics API, you need to set the current context properly when the Graphics code is initialized. I will refer to another issue with a similar problem:

https://github.com/StarlingGraphics/Starling-Extension-Graphics/issues/64

Read that thread, especially the comment that starts like this:

I am sorry, I forgot this part: In your SecondWindow class, you need to make the Starling instance of that window current before creating the Shape in timerCompleteHandler. Like this:

The correct starling context needs to be current when the Shape you wish to use on that context is created. This could be related to the issues you are having. I hope this helps.

Working without simple reproductions is very hard, so sorry for being vague

vrabete commented 9 years ago

Does anyone have a clue why Shape does not show anymore after I lose context because I lock out? No new Shape is showing anymore at all and I don't find onGraphicLostContext in Graphics extension (not even in the latest update)

IonSwitz commented 8 years ago

I have submitted a fix for this, or at least a problem related to Lost Context