ImageBox memory leak fix

  • Konuyu başlatan Konuyu başlatan Koray'
  • Başlangıç tarihi Başlangıç tarihi
  • Cevaplar Cevaplar 19
  • Görüntüleme Görüntüleme 6K

Koray'

Pasha37
Katılım
21 Haz 2013
Konular
198
Mesajlar
1,742
Çözüm
8
Online süresi
17d 3h
Reaksiyon Skoru
2,660
Altın Konu
3
Başarım Puanı
278
MmoLira
714
DevLira
103
Ticaret - 0%
0   0   0

ROHAN2 WORLD 1-120 TR TİPİ OFFICIAL YOHARA, BALATHOR VE AMON! 80. GÜNÜNDE! +10.000 ONLİNE! HİLE VE BOT %100 ENGELLİ HEMEN TIKLA!

Oyun içerisinde ImageBox kullanan UI eklentileriniz varsa oyun penceresi açık olduğu sürece(relog atmadığınız sürece vs) pencereyi kapatsanız bile içerisindeki resimler hafızadan silinmiyor ve her açılışta yeniden yükledikçe hafıza artışına sebep oluyor, bunun çözümünü paylaşıcam.

Öncesi:

Sonrası:


* EterPythonLib\PythonWindowManagerModule.cpp

Arat:
Kod:
PyObject* wndImageLoadImage(PyObject* poSelf, PyObject* poArgs)
{
...
}

Altına ekle:
Kod:
PyObject* wndImageUnloadImage(PyObject* poSelf, PyObject* poArgs)
{
    UI::CWindow* pWindow;
    if (!PyTuple_GetWindow(poArgs, 0, &pWindow)) {
        return Py_BuildException();
    }

    if (!((UI::CImageBox*)pWindow)->UnloadImage()) {
        return Py_BuildException("Failed to unload image");
    }

    return Py_BuildNone();
}

Arat:
Kod:
        { "LoadImage",                    wndImageLoadImage,                    METH_VARARGS },

Altına ekle:
Kod:
        { "UnloadImage",                 wndImageUnloadImage,                METH_VARARGS },

---

* EterPythonLib\PythonWindow.cpp

Arat:
Kod:
    BOOL CImageBox::LoadImage(const char* c_szFileName)
    {
...
    }

Altına ekle:
Kod:
    BOOL CImageBox::UnloadImage()
    {
        if (!m_pImageInstance)
            return FALSE;

        OnDestroyInstance();
        return TRUE;
    }

---

* EterPythonLib\PythonWindow.h

Arat:
Kod:
        BOOL LoadImage(const char* c_szFileName);

Altına ekle:
Kod:
        BOOL UnloadImage();

---

* root/ui.py

Arat:
Kod:
class ImageBox(Window):

Bul:
Kod:
        self.eventFunc = {}
        self.eventArgs = {}

Altına ekle:
Kod:
        self.imageLoaded = False

---

Arat:
Kod:
wndMgr.LoadImage(self.hWnd, imageName)

Altına ekle:
Kod:
self.imageLoaded = True

---

Arat:
Kod:
def __del__(self):

Altına ekle:
Kod:
        if self.imageLoaded:
            self.UnloadImage()

---

Dosyada "UnloadImage" fonksiyonu yoksa;

Arat:
def SetAlpha(self, alpha):

Üstüne ekle:
Python:
    def UnloadImage(self):
        wndMgr.UnloadImage()
        self.imageLoaded = False

        if len(self.eventDict) != 0:
            print "UNLOAD IMAGE", self, self.eventDict
 
Son düzenleme:

En Çok Reaksiyon Alan Mesajlar

Python:
    def UnloadImage(self):
        wndMgr.UnloadImage(self.hWnd)
        self.imageLoaded = False

        if len(self.eventDict) != 0:
            print "UNLOAD IMAGE", self, self.eventDict
Öğeyi görmek için üye olmalısınız.
Paylaşımınız İçin Teşekkürler.
 
Python:
    def UnloadImage(self):
        wndMgr.UnloadImage(self.hWnd)
        self.imageLoaded = False

        if len(self.eventDict) != 0:
            print "UNLOAD IMAGE", self, self.eventDict
 
Son düzenleme:
Paylaşım için teşekkürler
 

Şu an konuyu görüntüleyenler (Toplam : 0, Üye: 0, Misafir: 0)