我写了一个 JNI 库,它在 Java 中是这样定义的:
public class SDLMain
{
static {System.loadLibrary("SDLBitsX");}
public static native void init();
}
在 C 中定义为:
JNIEXPORT void JNICALL Java_gd_verfolgungsja_sdlbitsx_SDLMain_init(JNIEnv * env, jclass this)
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface *screen = SDL_SetVideoMode(512, 512, 8, 0);
SDL_FreeSurface(screen);
SDL_Quit();
}
Java代码吐出:
2013-03-29 22:34:01.796 java[10851:1303] _NSSetWindowTag, error clearing window tags (1000)
2013-03-29 22:34:01.797 java[10851:1303] _NSSetWindowTag, error setting window tags (1000)
2013-03-29 22:34:01.799 java[10851:1303] error [1000] getting window resolution
2013-03-29 22:34:01.799 java[10851:1303] Error [1000] setting resolution to 1
2013-03-29 22:34:01.800 java[10851:1303] error [1000] setting colorSpace to Color LCD colorspace
java(10851,0x107b58000) malloc: *** error for object 0x7fff8c03af01: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
如果我注释掉,该功能可以正常工作
SDL_Surface *screen = SDL_SetVideoMode(512, 512, 8, 0);
SDL_FreeSurface(screen);
我在 Mac 上。为什么这样做?