changeset 2728:bf89c7fc48fd

6741392: libmawt.so crash at Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeFinishPainting+0x4f Reviewed-by: peterz
author malenkov
date Thu, 16 Sep 2010 09:07:03 +0400
parents 49650448c3c7
children 21562f873588 e2050786c3ce
files src/solaris/native/sun/awt/gtk2_interface.c src/solaris/native/sun/awt/gtk2_interface.h src/solaris/native/sun/awt/swing_GTKEngine.c
diffstat 3 files changed, 34 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/native/sun/awt/gtk2_interface.c	Tue Sep 14 22:05:03 2010 +0400
+++ b/src/solaris/native/sun/awt/gtk2_interface.c	Thu Sep 16 09:07:03 2010 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -371,6 +371,16 @@
     return convertionBuffer;
 }
 
+static void throw_exception(JNIEnv *env, const char* name, const char* message)
+{
+    jclass class = (*env)->FindClass(env, name);
+
+    if (class != NULL)
+        (*env)->ThrowNew(env, class, message);
+
+    (*env)->DeleteLocalRef(env, class);
+}
+
 /* This is a workaround for the bug:
  * http://sourceware.org/bugzilla/show_bug.cgi?id=1814
  * (dlsym/dlopen clears dlerror state)
@@ -859,14 +869,26 @@
  * comparing results. This can be optimized by using subclassed pixmap and
  * doing the second drawing only if necessary.
 */
-void gtk2_init_painting(gint width, gint height)
+void gtk2_init_painting(JNIEnv *env, gint width, gint height)
 {
     GdkGC *gc;
+    GdkPixbuf *white, *black;
 
     init_containers();
 
     if (gtk2_pixbuf_width < width || gtk2_pixbuf_height < height)
     {
+        white = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
+        black = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
+
+        if (white == NULL || black == NULL)
+        {
+            snprintf(convertionBuffer, CONV_BUFFER_SIZE, "Couldn't create pixbuf of size %dx%d", width, height);
+            throw_exception(env, "java/lang/RuntimeException", convertionBuffer);
+            fp_gdk_threads_leave();
+            return;
+        }
+
         if (gtk2_white_pixmap != NULL) {
             /* free old stuff */
             (*fp_g_object_unref)(gtk2_white_pixmap);
@@ -875,14 +897,12 @@
             (*fp_g_object_unref)(gtk2_black_pixbuf);
         }
 
-        gtk2_white_pixmap = (*fp_gdk_pixmap_new)
-                                (gtk2_window->window, width, height, -1);
-        gtk2_black_pixmap = (*fp_gdk_pixmap_new)
-                                (gtk2_window->window, width, height, -1);
-        gtk2_white_pixbuf = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8,
-                                                 width, height);
-        gtk2_black_pixbuf = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8,
-                                                 width, height);
+        gtk2_white_pixmap = (*fp_gdk_pixmap_new)(gtk2_window->window, width, height, -1);
+        gtk2_black_pixmap = (*fp_gdk_pixmap_new)(gtk2_window->window, width, height, -1);
+
+        gtk2_white_pixbuf = white;
+        gtk2_black_pixbuf = black;
+
         gtk2_pixbuf_width = width;
         gtk2_pixbuf_height = height;
     }
--- a/src/solaris/native/sun/awt/gtk2_interface.h	Tue Sep 14 22:05:03 2010 +0400
+++ b/src/solaris/native/sun/awt/gtk2_interface.h	Thu Sep 16 09:07:03 2010 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -717,7 +717,7 @@
 void gtk_paint_background(WidgetType widget_type, GtkStateType state_type,
         gint x, gint y, gint width, gint height);
 
-void gtk2_init_painting(gint w, gint h);
+void gtk2_init_painting(JNIEnv *env, gint w, gint h);
 gint gtk2_copy_image(gint *dest, gint width, gint height);
 
 gint gtk2_get_xthickness(JNIEnv *env, WidgetType widget_type);
--- a/src/solaris/native/sun/awt/swing_GTKEngine.c	Tue Sep 14 22:05:03 2010 +0400
+++ b/src/solaris/native/sun/awt/swing_GTKEngine.c	Thu Sep 16 09:07:03 2010 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -293,7 +293,7 @@
         JNIEnv *env, jobject this, jint w, jint h)
 {
     fp_gdk_threads_enter();
-    gtk2_init_painting(w, h);
+    gtk2_init_painting(env, w, h);
     fp_gdk_threads_leave();
 }