2
0
Эх сурвалжийг харах

- ox version up
- improving filehandle to debug leak

[email protected] 8 жил өмнө
parent
commit
4565aaec37

+ 1 - 1
oxygine/src/AsyncTask.cpp

@@ -21,7 +21,7 @@ namespace oxygine
 
         bool ok = _prerun();
         log::messageln("AsyncTask::run %d - %s", getObjectID(), typeid(*this).name());
-                
+
         sync([ = ]()
         {
             if (ok)

+ 4 - 0
oxygine/src/core/FileSystem.h

@@ -7,16 +7,20 @@ namespace oxygine
     namespace file
     {
         class buffer;
+        class FileSystem;
 
         class fileHandle: public ObjectBase
         {
         public:
+            fileHandle(FileSystem* fs): _fs(fs) {}
             virtual void release() = 0;
             virtual unsigned int read(void* dest, unsigned int size) = 0;
             virtual unsigned int write(const void* src, unsigned int size) = 0;
             virtual unsigned int getSize() const = 0;
             virtual int          seek(unsigned int offset, int whence) = 0;
             virtual unsigned int tell() const = 0;
+
+            FileSystem* _fs;
         };
 
 

+ 2 - 2
oxygine/src/core/STDFileSystem.cpp

@@ -124,7 +124,7 @@ namespace oxygine
         class fileHandleSTD: public fileHandle
         {
         public:
-            fileHandleSTD(oxHandle* fh): _handle(fh)
+            fileHandleSTD(FileSystem* fs, oxHandle* fh): fileHandle(fs), _handle(fh)
             {
             }
 
@@ -224,7 +224,7 @@ namespace oxygine
             if (!h)
                 return status_error;
 
-            fh = new fileHandleSTD(h);
+            fh = new fileHandleSTD(this, h);
             return status_ok;
         }
 

+ 35 - 4
oxygine/src/core/ZipFileSystem.cpp

@@ -159,7 +159,33 @@ namespace oxygine
             return 0;
         }
 
+        void Zips::remove(const char* name)
+        {
+            MutexAutoLock al(_lock);
 
+            for (size_t i = 0; i < _zps.size(); ++i)
+            {
+                zpitem& item = _zps[i];
+                if (!strcmp(item.name, name))
+                {
+                    for (size_t n = 0; n < _files.size();)
+                    {
+                        file_entry& entry = _files[n];
+                        if (entry.zp == item.handle)
+                        {
+                            _files.erase(_files.begin() + n);
+                        }
+                        else
+                            ++n;
+                    }
+
+                    unzClose(item.handle);
+
+                    _zps.erase(_zps.begin() + i);
+                    break;
+                }
+            }
+        }
 
         void Zips::add(const char* name)
         {
@@ -284,7 +310,7 @@ namespace oxygine
         {
         public:
 
-            fileHandleZip(const file_entry* entry): _entry(entry)
+            fileHandleZip(FileSystem* fs, const file_entry* entry): fileHandle(fs), _entry(entry)
             {
                 int r = 0;
                 r = unzGoToFilePos(entry->zp, const_cast<unz_file_pos*>(&entry->pos));
@@ -340,7 +366,7 @@ namespace oxygine
             z_off_t _size;
             long _cpos;
 
-            fileHandleZipStreaming(const file_entry* entry, const Zips& z): _cpos(0)
+            fileHandleZipStreaming(FileSystem* fs, const file_entry* entry, const Zips& z): fileHandle(fs), _cpos(0)
             {
                 int r = 0;
                 r = unzGoToFilePos(entry->zp, const_cast<unz_file_pos*>(&entry->pos));
@@ -441,6 +467,11 @@ namespace oxygine
         }
 
 
+        void ZipFileSystem::remove(const char* zip)
+        {
+            _zips.remove(zip);
+        }
+
         void ZipFileSystem::reset()
         {
             _zips.reset();
@@ -462,9 +493,9 @@ namespace oxygine
             if (entry)
             {
                 if (*mode == 's')
-                    fh = new fileHandleZipStreaming(entry, _zips);
+                    fh = new fileHandleZipStreaming(this, entry, _zips);
                 else
-                    fh = new fileHandleZip(entry);
+                    fh = new fileHandleZip(this, entry);
                 return status_ok;
             }
 

+ 2 - 0
oxygine/src/core/ZipFileSystem.h

@@ -28,6 +28,7 @@ namespace oxygine
             void add(const char* name);
             void add(const unsigned char* data, unsigned int size);
             void add(std::vector<char>& data);
+            void remove(const char* name);
 
             void update();
 
@@ -74,6 +75,7 @@ namespace oxygine
 
             /**add zip from file*/
             void add(const char* zip);
+            void remove(const char* zip);
             //add zip from memory, data should not be deleted
             void add(const unsigned char* data, unsigned int size);
             //add zip from memory, vector would be swapped (emptied)

+ 2 - 2
oxygine/src/core/oxygine.cpp

@@ -347,7 +347,7 @@ namespace oxygine
             //SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
             SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
             SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
-            
+
             SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0);
 
             if (desc.force_gles)
@@ -387,7 +387,7 @@ namespace oxygine
             //ios bug workaround
             //flags &= ~SDL_WINDOW_FULLSCREEN;
 #endif
-            
+
 #if TARGET_OS_IPHONE || defined(__ANDROID__)
             desc.w = -1;
             desc.h = -1;

+ 1 - 1
oxygine/src/oxygine-include.h

@@ -113,7 +113,7 @@ namespace oxygine { namespace log { void error(const char* format, ...); } }
 
 #define OXYGINE_RENDERER 4
 
-#define OXYGINE_VERSION 5
+#define OXYGINE_VERSION 6
 
 #ifdef __GNUC__
 #   define OXYGINE_DEPRECATED __attribute__((deprecated))