Ticket #1355: free-cursors.patch

File free-cursors.patch, 2.6 KB (added by Deiz, 12 years ago)
  • source/lib/res/h_mgr.h

     
    384384extern Status h_free(Handle& h, H_Type type);
    385385
    386386
     387// Forcibly frees all handles of a specified type.
     388void h_mgr_free_type(const H_Type type);
     389
     390
    387391// find and return a handle by key (typically filename hash)
    388392// currently O(log n).
    389393//
  • source/lib/res/h_mgr.cpp

     
    787787    pool_destroy(&hpool);
    788788}
    789789
     790void h_mgr_free_type(const H_Type type)
     791{
     792    ignoreDoubleFree = true;
    790793
     794    H_ScopedLock s;
     795
     796    // forcibly close all open handles of the specified type
     797    for(HDATA* hd = (HDATA*)hpool.da.base; hd < (HDATA*)(hpool.da.base + hpool.da.pos); hd = (HDATA*)(uintptr_t(hd)+hpool.el_size))
     798    {
     799        // free if not previously freed and only free the proper type
     800        if (hd->key == 0 || hd->type != type)
     801            continue;
     802
     803        // disable caching; we need to release the resource now.
     804        hd->keep_open = 0;
     805        hd->refs = 0;
     806
     807        h_free_hd(hd);
     808    }
     809}
     810
    791811void h_mgr_init()
    792812{
    793813    ModuleInit(&initState, Init);
  • source/lib/res/graphics/cursor.cpp

     
    295295    return h_alloc(H_Cursor, vfs, name, 0, (int)forceGL);
    296296}
    297297
     298void cursor_shutdown()
     299{
     300    h_mgr_free_type(H_Cursor);
     301}
     302
    298303static Status cursor_free(Handle& h)
    299304{
    300305    return h_free(h, H_Cursor);
  • source/lib/res/graphics/cursor.h

     
    4646 **/
    4747extern Status cursor_draw(const PIVFS& vfs, const wchar_t* name, int x, int y, bool forceGL);
    4848
     49/**
     50 * Forcibly frees all cursor handles.
     51 *
     52 * Currently used just prior to SDL shutdown.
     53 */
     54void cursor_shutdown();
     55
    4956#endif  // #ifndef INCLUDED_GRAPHICS_CURSOR
  • source/ps/GameSetup/GameSetup.cpp

     
    636636
    637637static void ShutdownSDL()
    638638{
     639    // Free cursors before shutting down SDL, as they may depend on SDL.
     640    cursor_shutdown();
     641
    639642    SDL_Quit();
    640643    sys_cursor_reset();
    641644}