OSX Crashes when calling saveChartAsPNG on the Mac

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
wseyler
Posts: 5
Joined: Wed May 16, 2007 3:02 pm
Contact:

OSX Crashes when calling saveChartAsPNG on the Mac

Post by wseyler » Tue Apr 29, 2008 3:53 pm

I'm using GWT to display a chart to a client. The chart is rendered and saved on the server. The URL for the saved file is then returned to the GWT client for display in an image tag. The method is listed below.

Code: Select all

  public String createChart(OlapData olapData) {
    CategoryDataset categoryDataset = OlapUtil.createCategoryDataset(olapData);
    String categoryAxisName = olapData.getRowHeaders().getCell(0, 0).getFormattedValue();
    String valueAxisName = olapData.getColumnHeaders().getCell(0, 0).getFormattedValue();
    System.out.println("Creating Chart");
    JFreeChart chart = ChartFactory.createBarChart("Olap Chart", categoryAxisName, valueAxisName, categoryDataset, PlotOrientation.VERTICAL, true, true, false);
    System.out.println("Chart Created:" + chart);
    File chartFile = null;
    try {
      chartFile = File.createTempFile("chart",".png", new File(chartDirectory));
      System.out.println("Saving Chart");
      ChartUtilities.saveChartAsPNG(chartFile, chart, 400, 400);
      System.out.println("Chart Saved!");
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    HttpServletRequest req = getThreadLocalRequest();
    StringBuffer buffer = new StringBuffer(req.getScheme()).append("://").append(req.getServerName()).append(":").append(req.getServerPort()).append("/org.pentaho.halogen.Halogen").append("/charts/").append(chartFile.getName());
    System.out.println(buffer.toString());
    return buffer.toString();
  }
When execution reaches the saveChartAsPNG it throws the following exception:

Code: Select all

[WARN] StandardContext[]Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.lang.String org.pentaho.halogen.client.services.Olap4JService.createChart(org.pentaho.halogen.client.util.OlapData)' threw an unexpected exception: java.lang.RuntimeException: Non-Java exception raised, not handled! (Original problem: *** -[CarbonWindowFrame contentFill]: unrecognized selector sent to instance 0x393d70)
	at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:361)
	at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:547)
	at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:265)
	at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:187)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	at com.google.gwt.dev.shell.GWTShellServlet.service(GWTShellServlet.java:253)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
Caused by: java.lang.RuntimeException: Non-Java exception raised, not handled! (Original problem: *** -[CarbonWindowFrame contentFill]: unrecognized selector sent to instance 0x393d70)
	at apple.awt.OSXSurfaceData.doRect(OSXSurfaceData.java:1257)
	at apple.awt.CRenderer.fillRect(CRenderer.java:157)
	at apple.awt.CRenderer.drawfillShape(CRenderer.java:420)
	at apple.awt.CRenderer.fill(CRenderer.java:566)
	at sun.java2d.pipe.ValidatePipe.fill(ValidatePipe.java:142)
	at sun.java2d.SunGraphics2D.fill(SunGraphics2D.java:2580)
	at org.jfree.chart.JFreeChart.draw(JFreeChart.java:1157)
	at org.jfree.chart.JFreeChart.createBufferedImage(JFreeChart.java:1396)
	at org.jfree.chart.JFreeChart.createBufferedImage(JFreeChart.java:1376)
	at org.jfree.chart.ChartUtilities.writeChartAsPNG(ChartUtilities.java:168)
The interesting thing about this is that if I use Eclipse to step through the code the exception doesn't occur and the chart is rendered and saved properly. For what it's worth I'm using OSX 10.5.2.

Any help or words of wisdom would be greatly appreciated.
Bill Seyler
Software Engineer
Pentaho

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Apr 29, 2008 4:13 pm

Hi Bill,

Did you verify that the JRE used by Eclipse is the same as the one that's giving the exception? It looks very much like a bug in the JRE, but it would be nice to know what exactly triggers it, because it might be possible to workaround it from the JFreeChart side.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Apr 29, 2008 4:35 pm

Another random thought - does the bug occur without anti-aliasing?
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

wseyler
Posts: 5
Joined: Wed May 16, 2007 3:02 pm
Contact:

Post by wseyler » Tue Apr 29, 2008 7:00 pm

I agree that it looks like some sort of JVM bug. It's funny that it NEVER occurs when I debug through the code. It will occur when I'm debugging unless I have a breakpoint somewhere in the createChart method before the saveChartAsPNG method and step over the saveChartAsPNG.

I verified that I'm using the same JVM in eclipse. I also turned anti-aliasing off for both the chart and fonts and got the same results.

Incidentally I've also tested this on my home Mac (it's an PowerPC mac and not an Intel mac like the one I have at work both running the save version of OS X and JVM) and it also fails there.

I'm going to download the preview version of Apple's JVM 1.6 and give it a try. I'll keep you informed.

Thanks for support,
Bill Seyler
Software Engineer
Pentaho

wseyler
Posts: 5
Joined: Wed May 16, 2007 3:02 pm
Contact:

Post by wseyler » Tue Apr 29, 2008 7:18 pm

Drat... the preview of the Java 6 only runs on 64bit intel macs... I don't have one.
Bill Seyler
Software Engineer
Pentaho

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Tue Apr 29, 2008 8:38 pm

Try to run your server in headless mode. This usually fixes all kind of native errors, as the JVM then does not use the native AWT backend. No native calls to carbon = no trouble.

... or buy a PC :)

Locked