basixs said:
You are working with a non-thread safe function outside of openGL. (Its in an action listener, so will be called by the AWT/swing thread)
you need to inject the call into the openGL rendering thread like this
........
........
........
System.out.println("file chooser project Name : " + projectName);
saveScene(filePath + ".proj");
GameTaskQueueManager.getManager().update( new Callable<Object>() {
public Object call() throws Exception {
// This is the non-thread safe call that is throwing the error
display.getRenderer().takeScreenShot("temp");
return null;
}
} );
What you said worked beautifully and I thank you, but now I see I've got another problem
. Like you see in the picture below, it saves the jFileChooser window too.
.

final JDesktopPane desktopPane = jmeDesktop.getJDesktop();
//JFileChooser newProjectFileChooser = new JFileChooser();
saveAsFileChooser.setCurrentDirectory(new File("projects"));
saveAsFileChooser.addChoosableFileFilter(new HouseFilter(Utils.project));
saveAsFileChooser.setAcceptAllFileFilterUsed(false);
saveAsFileChooser.setApproveButtonText("Save");
//Add custom icons for file types.
saveAsFileChooser.setFileView(new HouseFileView());
//Add the preview pane.
saveAsFileChooser.setAccessory(new HousePreview(saveAsFileChooser));
saveAsFileChooser.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
String projectName = null;
//String filePath = null;
if(event.getSource().toString().contains("APPROVE_OPTION")){
// System.out.println("Open");
try{
// System.out.println(newProjectFileChooser.getSelectedFile().toURL());
projectName = saveAsFileChooser.getSelectedFile().getName();
if(saveAsFileChooser.getSelectedFile().exists())
filePath = saveAsFileChooser.getSelectedFile().getPath();
else
filePath = "projects/" + projectName;
//int i = projectName.lastIndexOf('.');
//if(i > 0)
// projectName = projectName.substring(0,i);
int i = filePath.lastIndexOf('.');
if(i > 0)
filePath = filePath.substring(0,i);
System.out.println("file chooser project Name : " + projectName);
saveScene(filePath + ".proj");
GameTaskQueueManager.getManager().update( new Callable<Object>() {
public Object call() throws Exception {
// This is the non-thread safe call that is throwing the error
display.getRenderer().takeScreenShot(filePath);
return null;
}
} );
} catch(Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
System.out.println("error");
}
} else {
// System.out.println("Cancel");
}
saveAsProjectDialog.setVisible(false);
}
}) ;
saveAsProjectDialog.getContentPane().add(saveAsFileChooser);
saveAsProjectDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
saveAsProjectDialog.pack();
desktopPane.add(saveAsProjectDialog);
I call the takeScreenShot method when the user clicks on the Save button, but I need to delay it a bit, just until the window is closed.