Hi all,
I’m trying to write an XMMS visu plugins which use SDL OpenGl functions.
I have already wrote a bit of code creating a visu plugin with SDL functions
and another bit of code drawing with SDL/OpenGL.
But when I try to “paste” one code with other, a segfault error appear as
soon as I start the plugin.
Does anyone have any experience XMMS plugins and can everybody help me ?
Karl—
Here is the piecce of code compiling on RedHat 7.2, SDL-1.2.2-3, NVIDIA
drivers last release, XFree86-4.1.0-3, GCC 2.96.
(gdb) run
[New Thread 1024 (LWP 1279)]
[New Thread 2049 (LWP 1453)]
[New Thread 1026 (LWP 1454)]
[New Thread 2051 (LWP 3416)]
[New Thread 3076 (LWP 3417)]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 3076 (LWP 3417)]
0x4124186a in glViewport () from /usr/lib/libGL.so.1
(gdb) bt
#0 0x4124186a in glViewport () from /usr/lib/libGL.so.1
#1 0x411ffddb in display_function (unused=0x0) at ./main.c:59
#2 0x411688c5 in SDL_RunThread (data=0x81c0db8) at SDL_thread.c:213
#3 0x41168aac in RunThread (data=0x81c0db8) at SDL_systhread.c:82
#4 0x4003ab9c in pthread_start_thread (arg=0x49d63be0) at manager.c:274
#5 0x4003ac7f in pthread_start_thread_event (arg=0x49d63be0) at manager.c:298
(gdb)
The plugin crash at the function glViewport(0, 0, width, height);
Here is the stack (obtained with ddd/gdb)
(Sorry but a bit long) :
#include <xmms/plugin.h>
#include <SDL/SDL.h>
#include <SDL/SDL_thread.h>
#include <SDL/SDL_opengl.h>
#include <SDL/SDL_video.h>
#include <stdio.h>
#define false 0
#define true 1
/*** XMMS callback functions /
static void jess_init_xmms(void); / Static init func /
static void jess_cleanup(void); / Static disable func
/
static void jess_playback_start(void); / Start playback /
static void jess_playback_stop(void); / Stop playback /
static void jess_render_pcm(gint16 pcm_data[2][512]); / Renderer PCM /
static void jess_render_freq(gint16 freq_data[2][256]); / Rendere MPEG */
/*** Some variable for the thread /
int threadExitNow = 0; / Thread should exit if value
!= 0 /
unsigned int nbFrameDisplayed; / Nb of frames displayed */
/*** SDL variables */
SDL_Surface *screen = NULL;
unsigned int width, height;
/**** Plugin data */
VisPlugin jess_vp = {
NULL,
NULL,
0,
“JESS 3.0alpha0”,
2,
2,
jess_init_xmms,
jess_cleanup,
NULL,
NULL,
NULL,
jess_playback_start,
jess_playback_stop,
jess_render_pcm,
jess_render_freq
};
/*** Main loop function (played as a thread) */
SDL_Thread *display_thread;
int display_function(void *unused) {
/** Initialize OPENGL function */
glViewport(0, 0, width, height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background
Color To Black
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // Reset The Projection Matrix
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); //
Calculate The Aspect Ratio Of The Window
glMatrixMode(GL_MODELVIEW);
while (!threadExitNow) {
// swap buffers to display, since we're double buffered.
SDL_GL_SwapBuffers();
}
return 0;
}
/*** Return the VisPlugin structure to xmms */
VisPlugin *get_vplugin_info (void) {
return &jess_vp;
}
/*** Initialize plugin */
static void jess_init_xmms(void) {
width = 640;
height = 480;
/** Initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
fprintf(stderr, “SDL Init failed: %s\n”, SDL_GetError());
return;
}
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
screen = SDL_SetVideoMode(width, height, 32, SDL_OPENGL);
if (screen == NULL)
{
fprintf(stderr, “Graphic mode is not available: %s\n”, SDL_GetError());
return;
}
/** Create Thread */
if ((display_thread = SDL_CreateThread(display_function, NULL)) == NULL) {
printf(“Create thread failed… %s\n”, SDL_GetError());
return;
}
}
/*** End the plugin when xmms leave */
static void jess_cleanup(void) {
threadExitNow = true;
/** Leave thread */
if (display_thread != NULL) {
SDL_WaitThread(display_thread, NULL);
}
/** Leave SDL */
if (screen != NULL) {
SDL_FreeSurface(screen);
SDL_Quit();
}
}
/*** Start the playback */
static void jess_playback_start(void) {
}
/*** Stop the playback */
static void jess_playback_stop(void) {
}
/*** Renderer PCM /
static void jess_render_pcm(gint16 pcm_data[2][512]) {
/* getPCMData = (tpcm*)&(pcm_data[0][0]); */
}
/*** Renderer freq */
static void jess_render_freq(gint16 freq_data[2][256]) {
/*getFreqData = (tfreq)&(freq_data[0][0]); */
}