SDL_SetVideoMode尝试释放未被malloc'd(?)的指针

时间:2013-03-30 02:45:11

标签: java c java-native-interface sdl

我编写了一个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上。为什么这样做?

1 个答案:

答案 0 :(得分:0)

我从来没有在Mac上使用过SDL,但是你对SDL_FreeSurface(screen)的调用无效.. (IIRC你通常不会自己释放默认的工作表面)默认绘图表面由SDL_Quit()自动释放,因此在您的情况下SQL_Quit()正在尝试释放不存在的内容。