AGAIN: A problem of gcj with SVGAlib

Search this archive.

From: Bruce You (bruceyou@sina.com)
Date: Wed 15 May 2002 - 10:36:35 IDT


Hi,

I am trying using gcj(GNU's Java) and SVGAlib to do something
(thru JNI), but I am facing a trouble, it'll get SIGPWR somehow,
I don't know where the problem is.

Followings are my running environment:

TurboLinux 7.0
Linux kernel version 2.4.5-3
SVGAlib version 1.4.3
GCC 3.0.4

Followings are my source code, it contains:
hyi/svga/SVGAToolkit.java
hyi/svga/SVGAToolkitImpl.c
and a building script

Could anbody kindly get me any clue?

hyi/svga/SVGAToolkit.java
------------------------------------------------

 1: package hyi.svga;
 2: 
 3: public class SVGAToolkit {
 4:     static {
 5:         System.loadLibrary("myvga");
 6:     }
 7:     public native static int init();
 8:     public native static void drawSomething(String chars, int x, int
y);
 9:
10:     static public void main(String[] args) throws Exception {
11:         init();
12:         while (true) {
13:             Thread.sleep(10);
14:             drawSomething("a", 0, 0);
15:         }
16:     }
17: }
------------------------------------------------------------------------
---

hyi/svga/SVGAToolkitImpl.c
------------------------------------------------

 1: #include <stdio.h>
 2: #include <vga.h>
 3: 
 4: #include "hyi_svga_SVGAToolkit.h"
 5: 
 6: jint Java_hyi_svga_SVGAToolkit_init(JNIEnv *env, jclass cl)
 7: {
 8:     if (vga_setmode(G640x480x16) < 0) {
 9:         fprintf(stderr, "Couldn't set to graphic mode.\n");
10:         exit(1);
11:     }
12:    return 0;
13: }
14: 
15: void Java_hyi_svga_SVGAToolkit_drawSomething
16:     (JNIEnv *env, jclass cl, jstring b, jint x, jint y)
17: {
18:     int i;
19:     int width = (int)random() % 620;
20:     int height = (int)random() % 440;
21:     unsigned char g_colorPool[640];
22:     unsigned char *str = (unsigned char*)(*env)->GetStringChars(env,
b, 0);
23: 
24:     memset(g_colorPool, (int)random() % 16, width);
25:     for (i = y; i < y + height; i++)
26:         vga_drawscansegment(g_colorPool, x, i, width);
27: 
28:     (*env)->ReleaseStringChars(env, b, (const jchar*)str);
29: }
------------------------------------------------------------------------
---

Building script
-----------------------------------------------------------

# make JNI header file: hyi_svga_SVGAToolkit.h
cd hyi/svga
/usr/java/jdk1.3.1/bin/javac SVGAToolkit.java
cd ../..
gcjh -jni hyi.svga.SVGAToolkit
mv -f hyi_svga_SVGAToolkit.h hyi/svga

# build shared library: libmyvga.so
gcc -g -o libmyvga.so -shared hyi/svga/SVGAToolkitImpl.c -lvga

# build executable: dtr
gcj -fjni -g -c hyi/svga/SVGAToolkit.java -o hyi/svga/SVGAToolkit.o
gcj -g -lvga -o dtr hyi/svga/SVGAToolkit.o libmyvga.so \
    --main=hyi.svga.SVGAToolkit
------------------------------------------------------------------------
---

After running 3 minutes, it'll crash,

  [root@JDL vga]# gdb dtr
  GNU gdb 5.0
  Copyright 2000 Free Software Foundation, Inc.
  GDB is free software, covered by the GNU General Public License, and
you are
  welcome to change it and/or distribute copies of it under certain
conditions.
  Type "show copying" to see the conditions.
  There is absolutely no warranty for GDB.  Type "show warranty" for
details.
  This GDB was configured as "i686-pc-linux-gnu"...
  (gdb) run
  Starting program: /root/vga/dtr
  [New Thread 1024 (LWP 644)]
  [New Thread 2049 (LWP 645)]
  [New Thread 1026 (LWP 646)]
  [svgalib: allocated virtual console #8]
  
  Program received signal SIGPWR, Power fail/restart.
  [Switching to Thread 1024 (LWP 644)]
  0x404d2a72 in __sigsuspend (set=0xbffffb68) at
../sysdeps/unix/sysv/linux/sigsuspend.c:54
  54      ../sysdeps/unix/sysv/linux/sigsuspend.c: No such file or
directory.
  (gdb)


BUT, if I comment out line 22 and 28 in SVGAToolkitImpl.c
(GetStringChars() and
ReleaseStringChars() part), it'll not crash. Why?

Thank you in advance.

--Bruce You (bruceyou@sina.com)



------------------------------------------------------------------
Unsubscribe:  To:   listbot@svgalib.org
              Body: unsubscribe linux-svgalib


This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:25 IST