Lag issues when i load images in netbeans?

Hi, Im working on a webdesigner program and in processing the program doesnt have much involved other than a Y tracking ruler mark, a x/y coord box. but for some reason when i add a image the y tracker starts to get some seriously bad lag. Im running on a amd 6-core with 8gb ram and a pretty good amd graphics card... so i dont think my system is the issue. maybe memory management or something? it didnt seem to be eatting up alot of ram or anything.

Answers

  • some code would help to find the error maybe

  • in edu.mass.necc.processing look at inkWDStartwindow2. if i add a workspace.image() with all the other code required for an image in lines 52-69, everything works but slows down and lags a ton.

  • edited March 2015
    • You should strive to load as much resources as possible within setup().
    • In most situations it makes no sense re-loading the very same resources over & over after setup()!
    • Plus you seem to have a static background w/ many rectangles.
    • It'd be nice if you created a PGraphics for it so it's drawn once only.
  • okay ill mess with that. should i take everything that stays the same and put it inside the setup()? or should i just incorporate all the elements of the editor itself in a Pgraphics? I know how to

  • edited March 2015 Answer ✓
    • Most important is loading all resources like loadImage() within setup() b/c they're the slowest!
    • Rendering the non-dynamic parts within a PGraphics is just for a slightly performance gain.
    • Create a function which renders those parts only and returns either a PGraphics or a PImage.
    • Then we can use that as our background() image!
    • Some online examples which does just that technique: O:-)

    1. http://studio.processingtogether.com/sp/pad/export/ro.9ozYNbweyOpjT/latest
    2. http://studio.processingtogether.com/sp/pad/export/ro.9WrTp2GiTlnLW/latest
    3. http://studio.processingtogether.com/sp/pad/export/ro.9ck0KLYubLcZG/latest
  • is it possible that using import processing.core.*; (importing all of processing) could also be causing lag? or that its running within an ide rather than something like a .jar file?

  • go to loop i know this question is totally different than the topic but taking my current files and making a jar wouldnt cause any issues in processing would it? i tried to create a jar with netbeans, it worked without errors but now when i try to run it nothing happens at all. I know how to run .jars just fine (im using ubuntu).

  • I just ran the .jar via terminal and i get this

    Exception in thread "main" java.lang.UnsupportedClassVersionError: edu/mass/necc/processing/Main : Unsupported major.minor version 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
    
    
    • Processing's IDE (PDE) relies on the Java compiler just like any other IDE.
    • Only that the PDE comes bundled and configured for everything it needs.
    • Other IDEs aren't setup to deal w/ Processing's exported jar files.
    • Since I only use the PDE for Processing, I've got no idea what's needed elsewhere. Sorry!
    • Other causes can be the default's OS Java is too old for target exported Java version.
    • Kinda you compiled for Java 8 but the OS is setup to run for Java 6 or 7 for example.
  • since the PDE uses java i may just move all my code to it. altho i did try compiling in the PDE with a test program and i had issues running on my system

  • edited March 2015

    I do wish there were more good processing video tutorials... maybe when I get some experience ill have to make some :). theres just alot to be understood in processing and I can get a little confusing trying to figure stuff out in the examples. I hate asking so many questions. thanks so much GoToLoop and and anyone else who helped me out. everyone has been more than helpful!

  • edited March 2015
    • I simple hit CTRL+E in order to export a sketch from the PDE. They run w/o any problems!
    • RU sure you've got JDK (be it Open or Oracle's) properly installed in your OS?
    • In this very recent thread, the OP had a lotta problems which was nothing more than not having Java's runtime installed:

    http://forum.processing.org/two/discussion/9419/daniel-s-processing-in-eclipse-tutorial-no-longer-works#latest

  • Okay you convinced me to switch over to PDE for sure. i got it to work. one thing tho... ive done what you advised. still having major lag issues. i think processing is trying to use each pixel specifically when i use a image (if that makes sence). is there any way to flatten or rasterize the image. or make it so processing uses less data in the pic? like it seems like its cant handle when i include a large/multicolored png. I have no idea how to fix this. its a major issue for me because this program will often be using and resizing images. (its a html/css editor)

  • W/o checking on your most current code it's just blind guesses!
    Your Dropbox link still points to your old NetBeans code!

  • W/o checking on your most current code it's just blind guesses!
    Your Dropbox link still points to your old NetBeans code!

  • okay ill change it for ya in a bit

  •  
    package edu.mass.necc.processing;
    
    import processing.core.*;
    import static processing.core.PConstants.CORNERS;
    
    public class revision1 extends PApplet {
       
        PGraphics mFrame, workspace;
        PImage logo,test;
        
        public void setup() {
            
            size(1500,900);
            frame.setTitle("Ink revision 1");
            
            rectMode(CORNERS);
            
            mFrame = createGraphics(1500,900);
            workspace = createGraphics(1204,842);
            
            logo = loadImage("inktitle.png");
            
            
            mFrame.beginDraw();
            for(int i=0;i<1;i++) {
        
                //rightside button pane
                mFrame.rectMode(CORNERS);
                mFrame.fill(8);
                mFrame.rect(1451,0,1500,900);                                
                
                //grey rectangle behind build area
                mFrame.fill(35);
                mFrame.noStroke();
                mFrame.rect(0,32,1233,900);
                
                //frame to build area
                mFrame.noFill();
                mFrame.stroke(100);
                mFrame.rect(6,52,1209,894,3);
                
                //Y-mouse tracker bar
                mFrame.fill(40,100);
                mFrame.stroke(100);
                mFrame.rect(6,32,1209,47,2);
                
                //white controll pane
                mFrame.fill(239, 253, 255);
                mFrame.noStroke();
                mFrame.rect(1234,0,1450,900,2);
                
                //X scroll frame/bar
                mFrame.fill(40,100);
                mFrame.stroke(100);
                mFrame.rect(1214,52,1229,894,2);
                
                //Coord box
                mFrame.fill(35);
                mFrame.stroke(100);
                mFrame.rect(1340,857,1445 ,877,3);
                mFrame.fill(35);
                mFrame.stroke(100);
                mFrame.rect(1340,877,1445 ,897,3);
                mFrame.textSize(16);
                mFrame.fill(35);
                mFrame.text(" x position",1235, 874);
                mFrame.textSize(16);
                mFrame.fill(35);
                mFrame.text(" y position",1235, 894);
                mFrame.stroke(100);
                mFrame.line(1241,878,1334,878);
                
                //grey backdrop behind(logo and tabs)
                mFrame.fill(38);
                mFrame.noStroke();
                mFrame.rect(0,0,1233,32);
                
                //Logo
                mFrame.image(logo,1005,0,220,32);
                            
            }
            mFrame.endDraw();
            
            
        }
        
        
        public void draw() {
            test = loadImage("image.png");
            
            image(mFrame.get(),0,0,1500,900);
            workspace.beginDraw();
            workspace.image(test,200,100,100,2000);
            workspace.endDraw();
            image(workspace.get(),6,52,1200,842);
            
            
            if(mouseX < 1209 && mouseX > 6) {
                stroke(201, 255, 146);
                line(mouseX,33,mouseX,46);
            } else {
                
            }
            //scroll bar (bar)
            /* scroll bar button length is to scroll frame as view
            window is to full page length
            */
        }
    }
    
    
  • I feel like processing is doing way to much with the pixels of the image... i just need the image to be displayed and resizable, thats it.

  • edited March 2015

    By the looks of it, seems like you didn't quit NetBeans! ;)
    But you're still loading resources after setup() has finished: #-o

    public void draw() {
      test = loadImage("image.png");
    
  • I havent completely changed the code over to where it needs to be for pde. busy last few days because im building a 3d printer. I will have to load images into the workspace often as this is a tool sorta like photoshop in some ways... is there any way that this can be helped? is there another way to get images into processing i havent found yet?

  • Things like buttons (that have onPress animations/ mash buttons) wouldn't be put in setup right?

    • setup() : fixed/static things that won't change later on.
    • draw() : animation/dynamic things which doesn't stay the same after setup().
  • okay so in that case this is fine. the image that you noticed was an example of loading a image into the workspace. the workspace is completely dynamic until save() and exit(). Im looking through everything involved in processing to find a fix with little luck. maybe i should look into some java thread or memory management?

  • edited March 2015

    The workspace is completely dynamic until save() and exit().

    • Do you mean "image.png"'s content changes somewhere else during the course of the sketch???
    • If that is so, you should issue loadImage() in another Thread so not to impact draw()'s performance!
  • thats a good idea... im not sure what you mean. but the workspace is a specific box-like area inside the program where shapes, images, buttons, text etc and created, edited and then saved to a file. i will have to experiment with the thread management your talking about

  • requestImage() is to load in another thread right?

  • edited March 2015

    ... where shapes, images, buttons, text etc are created, edited and then saved to a file.

    • Generally we should save at the end of the program, after a fixed time or upon user's request.
    • For performance reasons, we should manipulate contents in memory only.
    • What's the purpose to save to disk in 1 code block and another code forced to load that from disk?
    • Can't all parts of your sketch access the content in RAM w/o needing to load it from a slower disk?
  • can you explain? im a little confused... what this program is doing is as follows: the user can create/manipulate objects within the workspace, as each object is created or changed its attributes are written to a text file and saved periodically. then when upon user request (export button) the text file will be read and based on the contents will be essentially giving commands to the program on what HTML/CSS code to write to .html. does that make sense?

  • edited March 2015

    ... will be essentially giving commands to the program on what HTML/CSS code to write to .html.

    • It makes sense! Problem is your code examples don't match your descriptions!
    • What this line test = loadImage("image.png"); has anything to do w/ your "text" workspace?
    • Seems like you're dynamically modifying some ".html" & ".css" files w/ Processing.
    • I just dunno what images have anything to do w/ text files! :-/
    • It's still a mystery to me why you would need to keep re-loading "image.png" after setup().
    • Does "image.png" disappear from your sketch's memory and you have to recover it from disk?
    • Or is that "image.png" being dynamically modified from another program apart from your sketch?
    • Either way, you can't keep 60 FPS while save/load operations happen in the "Animation" Thread.
    • They should be handled in another Thread just for that!
  • yes , image.png is being dynamically modified... im gonna mess with threading a bit. 30 fps is all i would need... actually now that i think of it is there a way to limit the max FPS? that would probably help a bit because the system would only have to render at the needed speed

  • edited March 2015

    ... is there a way to limit the max FPS?

    Certainly! Just use frameRate(): https://processing.org/reference/frameRate_.html

    Yes, "image.png" is being dynamically modified...

    But by "whom"? The sketch itself or from another program as I had already asked you from my previous post?

    Reiterating, if it's the sketch itself which is saving the PImage to disk, I can't envision why you couldn't access that very same PImage from a variable and instead would prefer to load it from disk again inside draw(), making the whole sketch lose performance awaiting for that constant loading @ 60x per second (60 FPS)?

    Now if that happens to come from somewhere else, you're gonna need a separate Thread to deal w/ pre-loading it at a fixed time.
    Gonna need 2 variables. 1 to store the current PImage being displayed and another to keep the pre-loaded 1 until it's finally assigned to current 1!
    Some boilerplate code for the draw() and the pre-load Thread to deal w/ all that!

    I hope you now have a better idea what's need to be done in each case. Good luck! O:-)

  • the sketch its self... or i should say it will be. at this moment its just displayed. but it needs to be dynamic so that a user could move its position or resize it.

  • I do, and thanks for all the help. its very appriciated! :).

Sign In or Register to comment.