Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RenderDoc support #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main/java/net/neoforged/devlaunch/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

public class Main {
public static void main(String[] args) throws Throwable {
RenderDocIntegration.init();

if (args.length == 0) {
throw new IllegalArgumentException("DevLaunch requires at least one argument: an @-file to expand, or the main class.");
}
Expand All @@ -46,13 +48,13 @@ public static void main(String[] args) throws Throwable {

Method mainMethod;
try {
mainMethod = Class.forName(newArgs.get(0)).getMethod("main", String[].class);
mainMethod = Class.forName(newArgs.remove(0)).getMethod("main", String[].class);
} catch (ReflectiveOperationException e) {
throw new IllegalArgumentException("Could not find main class or main method. Given main class: " + newArgs.get(0), e);
}

try {
mainMethod.invoke(null, (Object) newArgs.subList(1, newArgs.size()).toArray(String[]::new));
mainMethod.invoke(null, (Object) newArgs.toArray(String[]::new));
} catch (InvocationTargetException e) {
throw e.getTargetException();
} catch (ReflectiveOperationException e) {
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/net/neoforged/devlaunch/RenderDocIntegration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.neoforged.devlaunch;

import java.io.File;

/**
* Loads the RenderDoc DLL, allowing attaching from the RenderDoc UI.
* On Linux, this should have the same effect as LD_PRELOAD since at no point
* have any OpenGL DLLs be loaded yet.
*/
final class RenderDocIntegration {
private static final String SYSTEM_PROPERTY = "devLaunch.renderDocLibrary";

private RenderDocIntegration() {
}

public static void init() {
String renderDocLibrary = System.getProperty(SYSTEM_PROPERTY);
if (renderDocLibrary == null) {
return;
}

var libraryFile = new File(renderDocLibrary);
if (!libraryFile.isFile()) {
System.err.println("The RenderDoc library specified by the system property " + SYSTEM_PROPERTY
+ " does not exist: " + libraryFile);
System.exit(2);
}

System.out.println("Loading renderdoc from " + libraryFile.getAbsolutePath());
System.load(libraryFile.getAbsolutePath());
}
}
Loading