我在IntelliJ IDEA中运行Processing应用程序时遇到了这个特殊问题.我想保存一个大图像并执行此操作我遇到以下异常:
线程"动画线程"中的异常java.lang.OutOfMemoryError:java.awt.image.Raster.createPackedRaster(Raster.java:467)中java.awt.image.DataBufferInt.(DataBufferInt.java:75)的Java堆空间java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032)在java.awt.image.BufferedImage.(BufferedImage.java:331)处理处理时的processing.core.PImage.saveImageIO(PImage.java:3117). core.PImage.save(PImage.java:3297)在OffScreenRender.stopRender(OffScreenRender.java:38)的MainVecField.draw(MainVecField.java:93)处理.处理.Cack.Papplet.handleDraw(PApplet.java:2305)at at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)atprocess.core.PApplet.run(PApplet.java:2176)at java.lang.Thread.run(Thread.java:724)
很明显这里有一些内存分配问题.问题是,当我更改IntelliJ中的.vmoptions文件时,我得到相同的结果,它们没有任何效果.IDE右下角的"内存"编号相应增加,但似乎不让我的应用程序分配更多内存.
当我在处理IDE中运行处理应用程序时,我可以设法通过设置较大的堆大小来保存更大的文件.
在IntelliJ中,超过256mb似乎没有什么区别.所以我的问题是如何在IntelliJ中设置更大的堆大小,允许我的应用程序分配更多的内存?
谢谢您的帮助!
我附上了我的项目的代码,以防有人想测试它:
import processing.core.*; public class TestClassMain extends PApplet { public static void main(String args[]) { PApplet.main(new String[] { "--present", "TestClassMain" }); } //Global variables OffScreenRender screenRender; int c = 0; //Variables for offScreenRender int resFactor = 10; boolean offScreenRenderSwitch = false; public void setup() { size(1000,700); background(0); stroke(255); //Initialize the render object screenRender = new OffScreenRender(this, 11000, 7950, resFactor); } public void draw() { frameRate(30); stroke(255); //Check if the render should be saved if(offScreenRenderSwitch == true){screenRender.startRender();} background(0,0,0); rect(20+c,height/2,60,60); if(offScreenRenderSwitch == true) { screenRender.stopRender(); offScreenRenderSwitch = false; } c += 2; } public void keyPressed() { //Render the graphics to an offScreen buffer offScreenRenderSwitch = true; } } import processing.core.*; /** * Renders the processingsketch to a .tif file at specified resolution. */ public class OffScreenRender { PApplet parent; // The parent PApplet PGraphics render; int width; int height; int resFactor; OffScreenRender(PApplet p, int width_, int height_, int resFactor_) { //Initialize variables parent = p; width = width_; height = height_; resFactor = resFactor_; render = parent.createGraphics(width, height); } //Render the image void startRender() { parent.beginRecord(render); render.scale(resFactor); PApplet.println("first step"); } //Render the image void stopRender() { parent.endRecord(); PApplet.println("second step"); render.save("hej"); PApplet.println("final step"); } }
Vic.. 37
更改vmoptions文件可调整IntelliJ使用的内存,但您在此处所拥有的是由IntelliJ启动以执行您的应用程序的JRE内存不足.您需要在运行/调试配置的VM选项部分中调整内存设置,例如:
更改vmoptions文件可调整IntelliJ使用的内存,但您在此处所拥有的是由IntelliJ启动以执行您的应用程序的JRE内存不足.您需要在运行/调试配置的VM选项部分中调整内存设置,例如: