Browse Source

fixed thread unsafe http progress dispatch

[email protected] 8 years ago
parent
commit
84f4a862a2
2 changed files with 7 additions and 4 deletions
  1. 5 3
      oxygine/src/AsyncTask.h
  2. 2 1
      oxygine/src/HttpRequestTask.cpp

+ 5 - 3
oxygine/src/AsyncTask.h

@@ -66,15 +66,17 @@ namespace oxygine
 
 
         template <class F>
-        void sync(const F& f)
+        void sync(const F& f, bool addref = true)
         {
             if (_mainThreadSync)
             {
-                addRef();
+                if (addref)
+                    addRef();
                 core::getMainThreadDispatcher().postCallback([ = ]()
                 {
                     f();
-                    releaseRef();
+                    if (addref)
+                        releaseRef();
                 });
                 return;
             }

+ 2 - 1
oxygine/src/HttpRequestTask.cpp

@@ -176,7 +176,7 @@ namespace oxygine
             _progressDispatched = false;
             dispatchProgress(delta + _progressDeltaDelayed, loaded, total);
             _progressDeltaDelayed = 0;
-        });
+        }, false);
     }
 
     void HttpRequestTask::_onError()
@@ -230,6 +230,7 @@ namespace oxygine
             unsigned int written = file::write(_fhandle, data, size);
             if (written != size)
             {
+                log::messageln("WRITE FILE ERROR %d %d", written, size);
                 _writeFileError = true;
                 return;
             }