运行程序时处理停止
Posted
技术标签:
【中文标题】运行程序时处理停止【英文标题】:Processing stalls when running a program 【发布时间】:2021-11-12 19:24:03 【问题描述】:我试图编写一个程序来模拟地月系统,它运行了一段时间,但出乎意料的是,Processing 开始停止。每次我点击“运行”时,都会出现大约 10 秒的异常延迟,然后我的 Windows 11 任务栏通知我草图窗口已打开,但我无法访问它,并且没有任何显示。其他程序运行良好,包括使用 P3D 的程序。
这是我的代码:
PShape earth,moon;
void setup()
size(6000,6000,P3D);
PImage img = loadImage("earth.jpg");
PImage img2= loadImage("moon.jpg");
noStroke();
earth=createShape(SPHERE,212.6); //radius of earth is 6378, sized down to by a factor of 30
earth.setTexture(img);
moon=createShape(SPHERE,57.9); //radius of moon is 1737, sized down by a factor of 30
moon.setTexture(img2);
float z = -300; //transversal along z-axis
float angle; // angle of rotation wrt center
float rotAngMoon=6.68; //angle of moon's rotation
float rotAngEarth=23.5; //angle of earth's rotation
float inclination=5.14; //angle between moon's orbital plane and earth's orbital plane
float orbitDistEarth=155.6666; //distance from earth's center to barycenter (4670, sized down by a factor of 30)
float orbitDistMoon=1298.9; //distance from moon's center to barycenter (389670, sized down by a factor of 300)
void draw()
background(0);
translate(width/2,height/2,2*z);
pushMatrix(); // Earth
rotateY(27.321661*angle); //Earth spins faster
translate(orbitDistEarth,0,0); //go to the point where earth would be
rotateZ(rotAngEarth*PI/180); //rotate the earth
shape(earth);
popMatrix();
pushMatrix(); //moon
rotateY(angle);
translate(-orbitDistMoon,(tan(inclination*PI/180))*orbitDistMoon*sin(angle*PI/180),0); //go to the point where the moon would be, additionally, the moon lies on a plane of inclination
//the line above might be incorrect with respect to the simulation, but I was debugging it when the stalls started occurring. There doesn't seem to be any error with it as far as I can see, so it should run fine
rotateZ(rotAngMoon*PI/180); //rotate the moon
shape(moon);
popMatrix();
angle+=0.01;
对可能出现的问题有任何想法吗?
【问题讨论】:
【参考方案1】:由于 6000 宽和 6000 高的巨大窗口大小,您的系统已停止运行。这远远超过你在今天的屏幕上看到的(2021 年)。缩小窗口大小:
size(6000, 6000, P3D);
size(1920, 1280, P3D);
【讨论】:
成功了!不过,它之前并没有出现任何问题(尽管我必须手动调整窗口大小以适应我的屏幕)。不知道为什么突然觉得 6000*6000 太大了? @NaN 可能是显卡驱动的问题,在 Windows 更新后。以上是关于运行程序时处理停止的主要内容,如果未能解决你的问题,请参考以下文章