stealth977
26-02-2010 09:27:24
Since I implemented Grass Painting in Ogitor, i realized that there was a huge memory leak causing my app to use over 1GB memory and increased forever till it crashes due to insufficient memory problems.
So i took a look at what was wrong with GrassLoader. At first it seemed alright since loadPage() was creating meshes and entites and unloadPage() was destroying them. So what was wrong???
Finally i found out why: GRASS PAGES ARE NEVER UNLOADED!!!
The reason is in a small detail:
PagedGeometry.h
virtual void unloadPage(const PageInfo &page) {}
GrassLoader.h
/** INTERNAL FUNCTION - DO NOT USE */
void unloadPage(PageInfo &page);
do you see the problem??? The virtual function defines the variable as const, but the function which tries to OVERRIDE it is non-const, so the compiler thinks they are different functions and all the virtual calls are directed to the first empty definition. GrassLoader::unloadPage() is never called.
Solution is Simple, just edit PagedGeometry.h and replace:
virtual void unloadPage(const PageInfo &page) {}
with
virtual void unloadPage(PageInfo &page) {}
because grassloader needs the parameter non-const. This solves the problem and now compiler correctly overrides the base function. Voila, now pages really unload and no memory leaks...
So i took a look at what was wrong with GrassLoader. At first it seemed alright since loadPage() was creating meshes and entites and unloadPage() was destroying them. So what was wrong???
Finally i found out why: GRASS PAGES ARE NEVER UNLOADED!!!
The reason is in a small detail:
PagedGeometry.h
virtual void unloadPage(const PageInfo &page) {}
GrassLoader.h
/** INTERNAL FUNCTION - DO NOT USE */
void unloadPage(PageInfo &page);
do you see the problem??? The virtual function defines the variable as const, but the function which tries to OVERRIDE it is non-const, so the compiler thinks they are different functions and all the virtual calls are directed to the first empty definition. GrassLoader::unloadPage() is never called.
Solution is Simple, just edit PagedGeometry.h and replace:
virtual void unloadPage(const PageInfo &page) {}
with
virtual void unloadPage(PageInfo &page) {}
because grassloader needs the parameter non-const. This solves the problem and now compiler correctly overrides the base function. Voila, now pages really unload and no memory leaks...