jMonkeyEngine / jMonkeyEngine/jmonkeyengine
ClassCastException trying to load a MTL material
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 14
Description
Another ClassCastException. Code:
this.box = assetManager.loadModel("assets/models/tiles/box-1.obj");
Material mat1 = assetManager.loadMaterial("assets/materials/tiles/loam/loam-1-1.mtl")
return box
It finds all objects and loads the texture. DesktopAssetManager#loadLocatedAsset returns a MaterialList. The obj = proc.postProcess(key, obj); returns the same MaterialList. See
public class CloneableAssetProcessor implements AssetProcessor {
public Object postProcess(AssetKey key, Object obj) {
return obj;
}
Then cache.addToCache(key, (T) obj) is called with cache being WeakRefCloneAssetCache and obj being MaterialList. And then here we get the CCEx CloneableSmartAsset asset = (CloneableSmartAsset) obj because a MaterialList is not a CloneableSmartAsset.
public <T> void addToCache(AssetKey<T> originalKey, T obj) {
// Make room for new asset
removeCollectedAssets();
CloneableSmartAsset asset = (CloneableSmartAsset) obj;
Error:
java.lang.ClassCastException: class com.jme3.material.MaterialList cannot be cast to class com.jme3.asset.CloneableSmartAsset (com.jme3.material.MaterialList and com.jme3.asset.CloneableSmartAsset are in unnamed module of loader 'app')
at com.jme3.asset.cache.WeakRefCloneAssetCache.addToCache(WeakRefCloneAssetCache.java:126)
at com.jme3.asset.DesktopAssetManager.loadLocatedAsset(DesktopAssetManager.java:281)
at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:373)
at com.jme3.asset.DesktopAssetManager.loadMaterial(DesktopAssetManager.java:394)
Version: 3.2.4-stable
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with WeakRefCloneAssetCache.addToCache at line 126 and follow the call from DesktopAssetManager.loadLocatedAsset through loadMaterial. Reproduce the MTL load using the issue's asset paths and verify that loading a MaterialList no longer raises ClassCastException and returns the expected material.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- desktop-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100