Created
September 11, 2016 12:29
-
-
Save oggy83/08851bce158191450c42535cdb0e9746 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//============================================================================= | |
// Oggy_1_3_1_MemoryLeakPatch.js | |
//============================================================================= | |
var _Oggy_TextureRpgUid_SnapTexture = 1; | |
// NOTE: This code deeply depends on PIXI 1.4.0 implementation. | |
// See TextureGarbageCollector.prototype.run() | |
Oggy_destroyTexture = function(uid) { | |
if (!Graphics.isWebGL()) { | |
// The target bug had caused about WebGL mode, so we don't touch Canvas mode. | |
return; | |
} | |
var gc = Graphics._renderer.textureGC; | |
var tm = gc.renderer.textureManager; | |
var managedTextures = tm._managedTextures; | |
var wasRemoved = false; | |
var i,j; | |
for (i = 0; i < managedTextures.length; i++) | |
{ | |
var texture = managedTextures[i]; | |
if (texture.hasOwnProperty("rpgUid") && texture.rpgUid === uid) { | |
tm.destroyTexture(texture, true); | |
managedTextures[i] = null; | |
wasRemoved = true; | |
} | |
} | |
if (wasRemoved) | |
{ | |
j = 0; | |
for (i = 0; i < managedTextures.length; i++) | |
{ | |
if (managedTextures[i] !== null) | |
{ | |
managedTextures[j++] = managedTextures[i]; | |
} | |
} | |
managedTextures.length = j; | |
} | |
}; | |
(function() { | |
var _Oggy_SceneManager_snapForBackground = SceneManager.snapForBackground; | |
SceneManager.snapForBackground = function() { | |
if (this._backgroundBitmap) { | |
Oggy_destroyTexture(_Oggy_TextureRpgUid_SnapTexture); | |
} | |
_Oggy_SceneManager_snapForBackground.call(this); | |
} | |
// NOTE: This code hides the original code (rpg_core.js) | |
Bitmap.snap = function(stage) { | |
var width = Graphics.width; | |
var height = Graphics.height; | |
var bitmap = new Bitmap(width, height); | |
var context = bitmap._context; | |
var renderTexture = PIXI.RenderTexture.create(width, height); | |
renderTexture.baseTexture.rpgUid = _Oggy_TextureRpgUid_SnapTexture;// add by oggy | |
if (stage) { | |
Graphics._renderer.render(stage, renderTexture); | |
stage.worldTransform.identity(); | |
var canvas = null; | |
if (Graphics.isWebGL()) { | |
canvas = Graphics._renderer.extract.canvas(renderTexture); | |
} else { | |
canvas = renderTexture.baseTexture._canvasRenderTarget.canvas; | |
} | |
context.drawImage(canvas, 0, 0); | |
} else { | |
//TODO: Ivan: what if stage is not present? | |
} | |
bitmap._setDirty(); | |
return bitmap; | |
}; | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment