Hey guys, I get a "Invalid memory access of location 0x318 rip=0x7fff85730328" error when running this code.
Seems like I can't create a new GLTexture object while the sketch is running, which is a bit weird. Code seems fine to me.
Any suggestions?
TextureTest.java
- package texturetest;
- import java.io.File;
- import java.io.FilenameFilter;
- import java.util.ArrayList;
- import processing.core.PApplet;
- import codeanticode.glgraphics.GLConstants;
- import codeanticode.glgraphics.GLGraphicsOffScreen;
- public class TextureTest extends PApplet {
- /**
- *
- */
- private static final long serialVersionUID = -8305191326600292350L;
- private GLGraphicsOffScreen glos;
- private ArrayList<Texture> textures;
- private LoaderThread loaderThread;
- private boolean keyreleased;
- public void setup() {
- size(screenWidth, screenHeight, GLConstants.GLGRAPHICS);
- textures = new ArrayList<Texture>();
- textures = loadImages("data/");
- glos = new GLGraphicsOffScreen(this, width, height, false);
- loaderThread = new LoaderThread(this, 1);
- loaderThread.start();
- keyreleased = false;
- }
- public void draw() {
- glos.beginDraw();
- glos.clear(0);
- for (int i = 0; i < textures.size(); i++) {
- Texture tex = textures.get(i);
- if (tex.hasTexture() && !keyreleased)
- glos.image(tex.getTexture(), i * 210, 0, 200, 200);
- }
- glos.endDraw();
- image(glos.getTexture(), 0, 0, glos.width, glos.height);
- }
- public void keyPressed() {
- keyreleased = true;
- }
- public void keyReleased() {
- loaderThread.initializeTextures(textures);
- keyreleased = false;
- }
- public ArrayList<Texture> loadImages(String path) {
- FilenameFilter dirFilter = new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return !name.startsWith(".");
- }
- };
- ArrayList<Texture> t = new ArrayList<Texture>();
- File filePath = new File(path);
- String[] dirList = filePath.list(dirFilter);
- if (filePath != null && filePath.list(dirFilter) != null) {
- for (int i = 0; i < dirList.length; i++) {
- File f = new File(path + dirList[i]);
- if (f.isFile())
- t.add(new Texture(this, path + dirList[i]));
- }
- }
- return t;
- }
- public static void main(String _args[]) {
- PApplet.main(new String[] { texturetest.TextureTest.class.getName() });
- }
- }
LoaderThread.java
- package texturetest;
- import java.util.ArrayList;
- import processing.core.PApplet;
- public class LoaderThread implements Runnable {
- private Thread t;
- private int sleepTime;
- private ArrayList<Texture> textures;
- private boolean updated;
- public LoaderThread(PApplet parent, int sleepTime) {
- this.sleepTime = sleepTime;
- this.updated = true;
- }
- public void initializeTextures(ArrayList<Texture> textures) {
- this.textures = textures;
- this.updated = false;
- }
- public void run() {
- Thread me = Thread.currentThread();
- while (t == me) {
- if (!updated) {
- for (int i = 0; i < textures.size(); i++) {
- textures.get(i).setTexture(textures.get(i).getFile());
- textures.get(i).setHasTexture(true);
- }
- updated = true;
- }
- try {
- Thread.sleep(sleepTime);
- } catch (InterruptedException e) {
- }
- }
- t = null;
- }
- void start() {
- if (t == null) {
- t = new Thread(this);
- t.start();
- }
- }
- void stop() {
- if (t != null) {
- t.interrupt();
- }
- t = null;
- synchronized (this) {
- notifyAll();
- }
- }
- public void dispose() {
- stop();
- }
- }
- package texturetest;
- import processing.core.PApplet;
- import codeanticode.glgraphics.GLTexture;
- public class Texture {
- private PApplet parent;
- private GLTexture texture;
- private boolean hasTexture;
- private String file;
- public Texture(PApplet parent, String file) {
- this.parent = parent;
- this.file = file;
- this.hasTexture = false;
- }
- public GLTexture getTexture() {
- return texture;
- }
- public void setTexture(String file) {
- this.texture = new GLTexture(parent, file);
- }
- public boolean hasTexture() {
- return hasTexture;
- }
- public void setHasTexture(boolean hasTexture) {
- this.hasTexture = hasTexture;
- }
- public String getFile() {
- return file;
- }
- public void setFile(String file) {
- this.file = file;
- }
- }
Thanks!
1