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

Shape is not restored if handleLostContext is set #100

Closed konsnos closed 10 years ago

konsnos commented 10 years ago

I've created a simple app whith one shape.

Then Ctrl+Alt+Delete, and the shape is gone. I've set Starling.handleLostContext to true before I start Starling. Is there a way for the Shapes to handle this by themselves?

jonathanrpace commented 10 years ago

Yes - this should be working without you having to do anything (at least it used to). Probably related to https://github.com/StarlingGraphics/Starling-Extension-Graphics/issues/99

You might get some milage with the 'fix' in there, though though the fix will cause a performance problem if you're clearing/drawing every Graphics API object each frame.

Not sure when I'll get round to taking a look.

IonSwitz commented 10 years ago

yes, changing the releaseProgram3D method back to

    public static function releaseProgram3D( program3D:Program3D ):void
    {
        if ( !numReferencesByProgramTable[program3D] )
        {
            throw( new Error( "Program3D is not in cache" ) );
            return;
        }

        numReferencesByProgramTable[program3D]--;
        flush();
    }

fixes the issue here.

However, that kills the benefit of the Lazy Cache. I can look into something for this briefly, but I need a second pair of eyes before I dare committing anything.

IonSwitz commented 10 years ago

Well, the simplest solution seems to be to re-write releaseProgram3D like this:

    public static function releaseProgram3D( program3D:Program3D, forceFlush:Boolean = false ):void
    {
        if ( !numReferencesByProgramTable[program3D] )
        {
            throw( new Error( "Program3D is not in cache" ) );
            return;
        }

        numReferencesByProgramTable[program3D]--;
        if ( forceFlush )
            flush();
    }

and set the forceFlush variable to "true" only in restoreOnLostContext() in StandardMaterial, in the call:

Program3DCache.releaseProgram3D(program, true);

that seems to keep the program from being flushed on dispose() and other similar methods, while still being able to recreate it properly after a lost Context.

Let me know what you think, @jonathanrpace. I can check in the fix if you think it seems reasonable.

jonathanrpace commented 10 years ago

Nice - makes sense to me. Check it in!

IonSwitz commented 10 years ago

Ok, I have checked in the fix, it seems to work in the few test cases I have run it through.

konsnos commented 10 years ago

Indeed it works. Thank you!