I wanted to post here as well for two reason. I don't believe I'm the only one who has seen this and maybe someone could tell me if I'm doing something wrong and after searching the forum, it doesn't look like there are other posts related to this and it might be useful to someone else.
When running MaxToJme main() with the appropriate arguments, execution will fail with the following output:
Oct 25, 2008 11:07:05 AM com.jmex.model.converters.FormatConverter attemptFileConvert
INFO: Converting file C:ProjectsworkspaceBaketf.3DS to C:ProjectsworkspaceBaketf.3DS.jbin
Oct 25, 2008 11:07:07 AM com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
Exception in thread "main" java.lang.NullPointerException
at com.jmex.model.converters.maxutils.MaterialBlock.initializeVariables(MaterialBlock.java:80)
at com.jmex.model.converters.maxutils.MaterialBlock.<init>(MaterialBlock.java:75)
at com.jmex.model.converters.maxutils.EditableObjectChunk.processChildChunk(EditableObjectChunk.java:94)
at com.jmex.model.converters.maxutils.ChunkerClass.chunk(ChunkerClass.java:94)
at com.jmex.model.converters.maxutils.EditableObjectChunk.<init>(EditableObjectChunk.java:80)
at com.jmex.model.converters.maxutils.TDSFile.processChildChunk(TDSFile.java:102)
at com.jmex.model.converters.maxutils.ChunkerClass.chunk(ChunkerClass.java:94)
at com.jmex.model.converters.maxutils.TDSFile.<init>(TDSFile.java:92)
at com.jmex.model.converters.MaxToJme.convert(MaxToJme.java:75)
at com.jmex.model.converters.FormatConverter.attemptFileConvert(FormatConverter.java:87)
at com.jmex.model.converters.MaxToJme.main(MaxToJme.java:64)
As far as I can tell, the DisplaySystem.system is null and is created the first time is is requested in MaterialBlock.java ln 80.
Ok, I figured it out. The problem is with the way the DummyDisplaySystem is created. It needs to be created as the DisplaySystem.system which means you need to do this:
DisplaySystem.getDisplaySystem("dummy");
Instead of
new DummyDisplaySystem();
I've made the change to my version of the model conversion code and it works. Maybe getDisplaySystem(String) should be renamed to indicate exactly what it is doing. It took me way to long to figure this out and it was in front of me the entire time.
Yes sir. it was a simple change. The one in Standard game wasn't cause trouble in any of the tests, but it will if anyone decides to make a model converter using it.
As to the underlying cause, I did not investigate it. I would assume it has something to do with the nature of how the System Providers work with the DisplaySystems and the static accessor in DisplaySystem that returns the current system which is only set up if someone calls the getDisplaySystem() method that takes a String parameter. I'm not sure how jme 1 handled this. It may be that it didn't use the DisplaySystem's static accessor during the model conversion or that somehow the current system was setup in the constructors of the individual DisplaySystems. Which would be very weird because the system providers would not have been created at that point.
I'm afraid I cannot make this very clear. Its kind of a confusing. I'm on IRC if you want to talk more. Just hope on and ping lefty2shoes.
Well, at a glance, I can tell you one reason it might have been removed. The constructor for DummyDisplaySystem is making a DummySystemProvider which can make a DummyDisplaySystem.
public class DummySystemProvider implements SystemProvider {
...
public DisplaySystem getDisplaySystem() {
if (displaySystem == null) {
displaySystem = new DummyDisplaySystem();
}
return displaySystem;
}
Sounds fine if the only way you make the object is by calling new DummyDisplaySystem, but as soon as you rely on the DummySystemProvider to create it which makes perfect sense to me, then you end up with some weird behavior.
well if we have FactoryMethods we should use them, so replacing 'new DummyDisplaySystem' with getDisplaySystem('dummy') is the smarter idea i guess.
The other question is, should the constructors of LWJGLDisplaySystem and DummyDisplaySystem be changed from public to protected, to avoid such mistakes?
import com.jme.animation.SpatialTransformer;
import com.jme.scene.Node;
-import com.jme.system.dummy.DummyDisplaySystem;
+import com.jme.system.DisplaySystem;
+import com.jme.system.dummy.DummySystemProvider;
import com.jme.util.LittleEndien;
import com.jme.util.export.binary.BinaryExporter;
import com.jmex.model.converters.maxutils.TDSFile;
@@ -60,7 +61,7 @@
* @param args The array of parameters. args="file1.3ds file2.jme" will convert file1.3ds to jme and save it to file2.jme.
*/
public static void main(String[] args){
- new DummyDisplaySystem();
+ DisplaySystem.getDisplaySystem(DummySystemProvider.DUMMY_SYSTEM_IDENTIFIER);
new MaxToJme().attemptFileConvert(args);
}
public static void main(String[] args) {
- new DummyDisplaySystem();
+ DisplaySystem.getDisplaySystem(DummySystemProvider.DUMMY_SYSTEM_IDENTIFIER);
new Md3ToJme().attemptFileConvert(args);
}