* AssetEventListener now has an additional callback that can be used to detect when a dependent asset has failed to load.

Since dependent assets that were not located have no exception thrown, detection of this event could be needed by some tools e.g. jMonkeyPlatform to indicate to the user that the asset may have not been loaded correctly. 

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8597 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
sha..rd 13 years ago
parent 66127db26d
commit 511c417fe7
  1. 13
      engine/src/core/com/jme3/asset/AssetEventListener.java
  2. 10
      engine/src/desktop/com/jme3/asset/DesktopAssetManager.java
  3. 29
      engine/src/desktop/com/jme3/asset/ImplHandler.java

@ -60,5 +60,18 @@ public interface AssetEventListener {
* @param key
*/
public void assetRequested(AssetKey key);
/**
* Called when an asset dependency cannot be found for an asset.
* When an asset is loaded, each of its dependent assets that
* have failed to load due to a {@link AssetNotFoundException}, will cause
* an invocation of this callback.
*
* @param parentKey The key of the parent asset that is being loaded
* from within the user application.
* @param dependentAssetKey The asset key of the dependent asset that has
* failed to load.
*/
public void assetDependencyNotFound(AssetKey parentKey, AssetKey dependentAssetKey);
}

@ -236,13 +236,23 @@ public class DesktopAssetManager implements AssetManager {
AssetInfo info = handler.tryLocate(key);
if (info == null){
if (handler.getParentKey() != null && eventListener != null){
// Inform event listener that an asset has failed to load.
// If the parent AssetLoader chooses not to propagate
// the exception, this is the only means of finding
// that something went wrong.
eventListener.assetDependencyNotFound(handler.getParentKey(), key);
}
throw new AssetNotFoundException(key.toString());
}
try {
handler.establishParentKey(key);
o = loader.load(info);
} catch (IOException ex) {
throw new AssetLoadException("An exception has occured while loading asset: " + key, ex);
} finally {
handler.releaseParentKey(key);
}
if (o == null){
throw new AssetLoadException("Error occured while loading asset \"" + key + "\" using" + loader.getClass().getSimpleName());

@ -51,6 +51,9 @@ public class ImplHandler {
private final AssetManager owner;
private final ThreadLocal<AssetKey> parentAssetKey
= new ThreadLocal<AssetKey>();
private final ArrayList<ImplThreadLocal> genericLocators =
new ArrayList<ImplThreadLocal>();
@ -103,6 +106,30 @@ public class ImplHandler {
}
}
/**
* Establishes the asset key that is used for tracking dependent assets
* that have failed to load. When set, the {@link DesktopAssetManager}
* gets a hint that it should suppress {@link AssetNotFoundException}s
* and instead call the listener callback (if set).
*
* @param key The parent key
*/
public void establishParentKey(AssetKey parentKey){
if (parentAssetKey.get() == null){
parentAssetKey.set(parentKey);
}
}
public void releaseParentKey(AssetKey parentKey){
if (parentAssetKey.get() == parentKey){
parentAssetKey.set(null);
}
}
public AssetKey getParentKey(){
return parentAssetKey.get();
}
/**
* Attempts to locate the given resource name.
* @param name The full name of the resource.
@ -111,7 +138,7 @@ public class ImplHandler {
*/
public AssetInfo tryLocate(AssetKey key){
synchronized (genericLocators){
if (genericLocators.size() == 0)
if (genericLocators.isEmpty())
return null;
for (ImplThreadLocal local : genericLocators){

Loading…
Cancel
Save