From 7bed38562c2bc354724813774420f4b8c48e0ed9 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Fri, 17 Jul 2015 16:46:07 -0700 Subject: [PATCH] Fix use of Assets.load* with the same ID and different callbacks --- templates/haxe/DefaultAssetLibrary.hx | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/templates/haxe/DefaultAssetLibrary.hx b/templates/haxe/DefaultAssetLibrary.hx index 6dba668c7..fa9febadd 100644 --- a/templates/haxe/DefaultAssetLibrary.hx +++ b/templates/haxe/DefaultAssetLibrary.hx @@ -40,7 +40,6 @@ class DefaultAssetLibrary extends AssetLibrary { public var type (default, null) = new Map (); private var lastModified:Float; - private var loadHandlers:Map; private var threadPool:ThreadPool; private var timer:Timer; @@ -137,15 +136,15 @@ class DefaultAssetLibrary extends AssetLibrary { private function createThreadPool ():Void { threadPool = new ThreadPool (0, 2); - threadPool.doWork.add (function (id, getMethod) { + threadPool.doWork.add (function (id, data) { - threadPool.sendComplete (id, getMethod (id)); + data.result = data.getMethod (id); + threadPool.sendComplete (data.handler, data); }); threadPool.onComplete.add (function (id, data) { - var handler = loadHandlers.get (id); - handler (data); + data.handler (data.result); }); @@ -570,13 +569,11 @@ class DefaultAssetLibrary extends AssetLibrary { if (threadPool == null) { - loadHandlers = new Map (); createThreadPool (); } - loadHandlers.set (id, handler); - threadPool.queue (id, getBytes); + threadPool.queue (id, { handler: handler, getMethod: getBytes }); #end @@ -626,13 +623,11 @@ class DefaultAssetLibrary extends AssetLibrary { if (threadPool == null) { - loadHandlers = new Map (); createThreadPool (); } - loadHandlers.set (id, handler); - threadPool.queue (id, getImage); + threadPool.queue (id, { handler: handler, getMethod: getImage }); #end