Game Development Community

Tilemaps problems

by hugor · in Torque X 2D · 11/30/2009 (5:48 am) · 13 replies

I've been poking around in the threads trying to find a solution but i haven't gotten many responses.

When using tilemaps if you run your game and minimize the window, when you go back to it the tiles simply disapeared, seems they are not rendered anymore.

This happens with the TX platformer kit too, when you create a new Platformer Demo project...

Can someone just give it to me straight?? Are tilemaps just broken here or am I really alone in my troubles?

About the author

Recent Threads

  • PSK folder missing

  • #1
    11/30/2009 (10:50 am)
    Fix for the 'purple screen' bug in this thread: www.garagegames.com/community/forums/viewthread/104691
    #2
    11/30/2009 (11:54 am)
    The problem isn't a "purple screen", everything is fine, only the tilemap(s) disapears. Have tried this solution but seems to not work in this case.
    #3
    11/30/2009 (12:07 pm)
    Normally the screen will go purple when you minimize/restore as that is XNA's default clear colour and TX has a bug where it doesn't rebuild resources after the device context has been lost. But you say other objects still draw and it's only the tilemaps that are disappearing/not rendering?
    #4
    11/30/2009 (12:09 pm)
    Yes, only tilemaps other objects still draw.
    #5
    11/30/2009 (1:01 pm)
    Maybe the latest version of TX fixes the purple screen bug then (I haven't got the very latest version yet so maybe someone can verify).

    The only time I've seen stuff not drawing like you describe (i.e. after a minimize/restore) is when failing to rebuild resources that were nuked when the graphics device was lost. It might be worth looking in T2DTileType.Render() as a quick skim of that method shows that it's using index buffers and various other resources - it's possible that some of them might need rebuilding after the graphics device has been lost (one of the easiest ways to do that is often to just null out the relevant resource references so that they will get recreated again - that obviously assumes they are ones that get recreated if nulled :-)
    #6
    11/30/2009 (10:46 pm)
    The new version does fix the purple screen bug and the fps bug (the one fixed by check fences). The new version seems to just not re-render tilemaps, they literally just disappear after you minimize/maximize. There is no purple spots left in their wake; it's as if they were just removed. All other assets seem to re-render fine, though.

    Duncan, you were the genius behind the purple screen fix, it'd be awesome if you could compensate for garage games lack of support again by fixing this one too =) (as much as I hate to ask that of someone).
    #7
    12/01/2009 (11:50 am)
    Tiles not rendering: with regard to the old purple screen bug it's not that they would render purple, they just simply would not render - which sounds like what you describe.

    The purple screen was due to nothing getting rendered on the back buffer iirc. So effectively nothing was rendered and you would just see the xna default colour, which happens to be purple.

    It does sound like it's a similar issue with the tile rendering. I'm not sure when I'll get to look into it as I'm not using tiles or the latest TX version right now. In the meantime though you could try looking in T2DTileType.Render() for likely suspects.
    #8
    12/03/2009 (5:01 pm)
    I just tested with TX 2D 3.1 with the purple screen fix applied and all tiles rendered fine on minimize/restore. I'm downloading 3.1.4 at the moment and will try with that later.
    #9
    12/03/2009 (6:48 pm)
    It's interesting - it looks like the purple screen 'fix' in TX 2D 3.1.4 might just be an incidental fix as a side effect to other stuff that's been modified. Certainly the fact that tilelayers are still messed up on minimize/restore would suggest this is the case.

    Anyway, enough moaning about GG not properly supporting Windows XNA games... time for the fix:


    Open the T2DTileLayer.cs

    Add the following to the constructor
    T2DTileLayer()
    TorqueEventManager.ListenEvents<bool> GFXDevice.Instance.DeviceReset, OnDeviceReset);

    Add the following to Dispose()
    TorqueEventManager.SilenceEvents<bool> GFXDevice.Instance.DeviceReset, OnDeviceReset);

    Add the following method:
    public void OnDeviceReset(String eventName, bool data)
    {
        if (!_vb.IsNull)
        {
             _vb.Instance.Dispose();
             _vb.Invalidate();
        }
    }
    #10
    12/03/2009 (6:52 pm)
    Basically when the device is reset the vertex buffer needs to be rebuilt, so we nuke the buffer and then the next time Render() gets called it will rebuild it.
    #11
    12/04/2009 (9:36 am)
    How Garage Games hasn't fired their programming team and just put you on the job, I've no idea Duncan.

    It's amazing that you've, yet again, fixed the solution for someone else's broken proprietary engine in a record breaking time frame.

    #12
    12/04/2009 (10:44 am)
    Glad that worked for you Mike :-)
    #13
    12/06/2009 (5:00 am)
    Hi, Great fix, many thanks for the help Duncan.