Skip to content

Commit

Permalink
AppChooser: change macOS exec from glfw_async to -XstartOnFirstThread
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jun 11, 2023
1 parent d46dd5d commit ea6ac39
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions WesExamples/src/main/java/jme3utilities/test/wes/AppChooser.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.jme3.system.Platform;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Logger;
import jme3utilities.Heart;
import jme3utilities.MyString;
Expand All @@ -44,7 +46,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import jme3utilities.ui.Overlay;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.lwjgl.system.Configuration;

/**
* Choose an application from a list, then execute it.
Expand Down Expand Up @@ -101,6 +102,10 @@ final class AppChooser extends AcorusDemo {
* index of the selected app in the {@code mainClasses} array
*/
private static int selectedAppIndex = 0;
/**
* environment variables passed to the executor
*/
private static Map<String, String> env = new TreeMap<>();
/**
* menu overlay, displayed in the upper-left corner of the GUI node
*/
Expand All @@ -123,11 +128,6 @@ private AppChooser() {
* @param arguments array of command-line arguments (not null)
*/
public static void main(String[] arguments) {
Platform platform = JmeSystem.getPlatform();
if (platform.getOs() == Platform.Os.MacOS) {
Configuration.GLFW_LIBRARY_NAME.set("glfw_async");
}

String title = applicationName + " " + MyString.join(arguments);
AppChooser application = new AppChooser();
Heart.parseAppArgs(application, arguments);
Expand Down Expand Up @@ -155,6 +155,14 @@ public static void main(String[] arguments) {
@Override
public void acorusInit() {
script = findScriptToExecute();

// environment variables that will be passed to the executor
env.putAll(System.getenv());
Platform platform = JmeSystem.getPlatform();
if (platform.getOs() == Platform.Os.MacOS) {
env.put("JAVA_OPTS", "-XstartOnFirstThread");
}

getHelpBuilder().setBackgroundColor(new ColorRGBA(0f, 0.05f, 0f, 1f));
addMenuOverlay();
super.acorusInit();
Expand Down Expand Up @@ -274,7 +282,7 @@ private static void executeSelectedApp() {

DefaultExecutor executor = new DefaultExecutor();
try {
executor.execute(commandLine);
executor.execute(commandLine, env);
// ignore the return code
} catch (IOException exception) {
throw new RuntimeException(exception);
Expand Down

0 comments on commit ea6ac39

Please sign in to comment.