瀏覽代碼

minor fixes
fixed PostProcess crash in some cases

dmuratshin 9 年之前
父節點
當前提交
6b53e21535

+ 2 - 0
oxygine/SDL/win32/oxygine.vcxproj

@@ -162,6 +162,7 @@
     <ClCompile Include="..\..\src\Input.cpp" />
     <ClCompile Include="..\..\src\InputText.cpp" />
     <ClCompile Include="..\..\src\json\jsoncpp.cpp" />
+    <ClCompile Include="..\..\src\key.cpp" />
     <ClCompile Include="..\..\src\MaskedRenderer.cpp" />
     <ClCompile Include="..\..\src\MaskedSprite.cpp" />
     <ClCompile Include="..\..\src\Material.cpp" />
@@ -274,6 +275,7 @@
     <ClInclude Include="..\..\src\InputText.h" />
     <ClInclude Include="..\..\src\json\json-forwards.h" />
     <ClInclude Include="..\..\src\json\json.h" />
+    <ClInclude Include="..\..\src\key.h" />
     <ClInclude Include="..\..\src\KeyEvent.h" />
     <ClInclude Include="..\..\src\MaskedRenderer.h" />
     <ClInclude Include="..\..\src\MaskedSprite.h" />

+ 6 - 0
oxygine/SDL/win32/oxygine.vcxproj.filters

@@ -348,6 +348,9 @@
     <ClCompile Include="..\..\src\TweenGlow.cpp">
       <Filter>src</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\key.cpp">
+      <Filter>src</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\closure\closure.h">
@@ -743,6 +746,9 @@
     <ClInclude Include="..\..\src\TweenGlow.h">
       <Filter>src</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\key.h">
+      <Filter>src</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="ReadMe.txt" />

+ 8 - 2
oxygine/src/DebugActor.cpp

@@ -199,8 +199,14 @@ namespace oxygine
 
         if (DebugActor::instance)
         {
-            DebugActor::instance->_debugText += buff;
-            DebugActor::instance->_debugText += "\n";
+            std::string& str = DebugActor::instance->_debugText;
+            str += buff;
+            str += "\n";
+
+            if (str.size() > 500)
+            {
+                str.resize(500);
+            }
         }
     }
 

+ 2 - 0
oxygine/src/EventDispatcher.h

@@ -51,6 +51,8 @@ namespace oxygine
         virtual void dispatchEvent(Event* event);
 
         int getListenersCount() const;
+		int getLastListenerID() const { return _lastID; }
+
 
     protected:
 

+ 34 - 9
oxygine/src/PostProcess.cpp

@@ -91,7 +91,8 @@ namespace oxygine
 
     DECLARE_SMART(TweenPostProcess, spTweenPostProcess);
 
-    vector<spTweenPostProcess> postProcessItems;
+    class PPTask;
+    vector<PPTask*> postProcessItems;
 
     int alignTextureSize(int v)
     {
@@ -256,8 +257,25 @@ namespace oxygine
     }
 
 
+    void addPostProcessItem(PPTask* task)
+    {
+        if (find(postProcessItems.begin(), postProcessItems.end(), task) == postProcessItems.end())
+        {
+            task->addRefPP();
+            postProcessItems.push_back(task);
+        }
+    }
 
 
+    void removePostProcessItem(PPTask* t)
+    {
+        vector<PPTask*>::iterator i = std::find(postProcessItems.begin(), postProcessItems.end(), t);
+        if (i == postProcessItems.end())
+            return;
+        t->releaseRefPP();
+        postProcessItems.erase(i);
+    }
+
 
 
     void updatePortProcessItems()
@@ -272,9 +290,9 @@ namespace oxygine
 
             for (size_t i = 0; i < postProcessItems.size(); ++i)
             {
-                spTweenPostProcess p = postProcessItems[i];
+                PPTask* p = postProcessItems[i];
                 p->renderPP();
-                p->getActor()->releaseRef();
+                p->releaseRefPP();
             }
 
             postProcessItems.clear();
@@ -413,6 +431,8 @@ namespace oxygine
 
     TweenPostProcess::~TweenPostProcess()
     {
+
+        removePostProcessItem(this);
         if (_actor && _actor->getMaterial())
             _actor->setMaterial(_prevMaterial);
     }
@@ -427,6 +447,16 @@ namespace oxygine
         _renderPP();
     }
 
+    void TweenPostProcess::addRefPP()
+    {
+        _actor->addRef();
+    }
+
+    void TweenPostProcess::releaseRefPP()
+    {
+        _actor->releaseRef();
+    }
+
     void TweenPostProcess::init(Actor& actor)
     {
         _actor = &actor;
@@ -437,12 +467,7 @@ namespace oxygine
     void TweenPostProcess::update(Actor& actor, float p, const UpdateState& us)
     {
         _progress = p;
-
-        if (find(postProcessItems.begin(), postProcessItems.end(), this) == postProcessItems.end())
-        {
-            _actor->addRef();
-            postProcessItems.push_back(this);
-        }
+        addPostProcessItem(this);
     }
 
     void TweenPostProcess::done(Actor& actor)

+ 14 - 5
oxygine/src/PostProcess.h

@@ -61,19 +61,26 @@ namespace oxygine
         PostProcessOptions _options;
     };
 
+    class PPTask
+    {
+    public:
+        virtual ~PPTask() {}
+        virtual void addRefPP() = 0;
+        virtual void releaseRefPP() = 0;
+        virtual void renderPP() = 0;
+    };
 
     DECLARE_SMART(TweenPostProcess, spTweenPostProcess);
 
-    class TweenPostProcess : public TweenObj, public Material
+    class TweenPostProcess : public TweenObj, public Material, public PPTask
     {
     public:
         TweenPostProcess(const PostProcessOptions& opt);
         ~TweenPostProcess();
 
-        Actor* getActor() const { return _actor; }
-
-        void renderPP();
-
+        void renderPP() OVERRIDE;
+        void addRefPP() OVERRIDE;
+        void releaseRefPP() OVERRIDE;
 
         void init(Actor& actor) OVERRIDE;
         void update(Actor& actor, float p, const UpdateState& us) OVERRIDE;
@@ -115,5 +122,7 @@ namespace oxygine
     RenderTargetsManager& getRTManager();
 
     void updatePortProcessItems();
+    void addPostProcessItem(PPTask*);
+    void removePostProcessItem(PPTask*);
     void clearPostProcessItems();
 }