Zappster Posted February 6, 2016 Share Posted February 6, 2016 This has been killing me for too long now My paint is : private BufferedImage img = null; private void setBuffImage(){ try { img = ImageIO.read(new URL("http://i.imgur.com/hxNYgK6.jpg")); } catch (IOException e) { } } private static final Font font1 = new Font("Gentium Basic", 0, 16); private static final Color color1 = Color.WHITE; @Override public void onPaint(Graphics2D g) { timeRan = System.currentTimeMillis() - this.timeBegan; g.drawImage(img, 0, 335, null); g.setFont(font1); g.setColor(color1); g.drawString("Rewards collected: "+picked,70, 425); g.drawString("Farming XP(per hour): "+experienceTracker.getGainedXP(Skill.FARMING)+"("+experienceTracker.getGainedXPPerHour(Skill.FARMING)+")",280, 425); g.drawString("Status: "+statusWrite(),130, 455); g.drawString("Run time: " + ft(timeRan), 360, 385); } the img gets set on script start. But everytime I minimise my client and open it again, my paint has disappeared and will only come back after I move my cursor on screen. I have reason to believe setBuffImage() is the culprit as I didn't have this problem before adding it. Quote Link to comment Share on other sites More sharing options...
Vilius Posted February 6, 2016 Share Posted February 6, 2016 make a graphics var Graphics2D paint = (Graphics2D) g.create(); and do: paint.drawString(); etc. I think its because you are using an entity debugger which overrides your paint. Quote Link to comment Share on other sites More sharing options...
Explv Posted February 6, 2016 Share Posted February 6, 2016 Not relevant to your problem but in your onPaint you should also do a null check for your image. if(img != null) g.drawImage(img, null, 0, 335); 1 Quote Link to comment Share on other sites More sharing options...
Botre Posted February 6, 2016 Share Posted February 6, 2016 Not relevant to your problem but in your onPaint you should also do a null check for your image. if(img != null) g.drawImage(img, null, 0, 335); Why? If it was initialized correctly there's no need to check if it's null 30 times per second. @OP empty try-catch blocks are a big no-no. Quote Link to comment Share on other sites More sharing options...
Explv Posted February 6, 2016 Share Posted February 6, 2016 (edited) Why? If it was initialized correctly there's no need to check if it's null 30 times per second. @OP empty try-catch blocks are a big no-no. Well it has no impact on performance. If imgur fucks up your script will still work. onPaint runs on a separate thread so I think there could also be a point at the start where img is null Edited February 6, 2016 by Explv Quote Link to comment Share on other sites More sharing options...
Zappster Posted February 6, 2016 Author Share Posted February 6, 2016 Well it has no impact on performance. If imgur fucks up your script will still work. onPaint runs on a separate thread so I think there could also be a point at the start where img is null Yeah, I should really move it to a local file :X make a graphics var Graphics2D paint = (Graphics2D) g.create(); and do: paint.drawString(); etc. I think its because you are using an entity debugger which overrides your paint. I'll look into this now thanks for the fast reply Quote Link to comment Share on other sites More sharing options...
Botre Posted February 6, 2016 Share Posted February 6, 2016 Well it has no impact on performance. If imgur fucks up your script will still work. onPaint runs on a separate thread so I think there could also be a point at the start where img is null You might be right since onPaint gets called before onStart. @OP try this public class Script { public static BufferedImage PAINT_BACKGROUND; static { try { PAINT_BACKGROUND = ImageIO.read(new URL("http://i.imgur.com/hxNYgK6.jpg")); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } // onstart ... // onloop ... } Quote Link to comment Share on other sites More sharing options...
Zappster Posted February 6, 2016 Author Share Posted February 6, 2016 You might be right since onPaint gets called before onStart. @OP try this public class Script { public static BufferedImage PAINT_BACKGROUND; static { try { PAINT_BACKGROUND = ImageIO.read(new URL("http://i.imgur.com/hxNYgK6.jpg")); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } // onstart ... // onloop ... } Sorry, the only thing that gets called in the onStart, relative to the onPaint, is the setBuffImage() call Quote Link to comment Share on other sites More sharing options...
Botre Posted February 6, 2016 Share Posted February 6, 2016 Sorry, the only thing that gets called in the onStart, relative to the onPaint, is the setBuffImage() call onStart usually gets called AFTER the first onPaint called. So if you use onStart to initialize variables used inside onPaint you could run into trouble. You could use a static block to make sure the image gets initialize on time or you could null check the image variable in your onPaint. Or maybe it's something entirely different that's causing the issue :p Getting any errors? Try providing a gif if you can. 1 Quote Link to comment Share on other sites More sharing options...