Problem with libSmpeg + SDL + GL. [running a callback by a thread, with GL functions]

Hello.
I’m trying with libSmpeg + SDL + GL.
First…
libSmpeg uses a thread to play the movies fast, and uses a callback, by our
hands, to we make the updates, like we decide.
I used te glmovie.c, example that comes with libsmpeg, and it gets the same
bug - segfault when calling glClear.
What sounds strange, is that when called by main() [thread], glClear works
well.
When called by my update() callback - that is called b smpeg thread -, it
get problems.

my main is like:

glClear(GL_COLOR_BUFFER_BIT)
MPEG_play(mpeg);
while(SMPEG_status(mpeg) == SMPEG_PLAYING) {
SDL_Delay(100);
}

It cant have problem about locking some information in GL, cause i dont make
any GL command after mpeg thread to start.

my update() callback have just:
gClear(GL_COLOR_BUFFER_BIT);

Its my test!

I will paste the debug, and write my vision about it in and after…
diego at zeus(~/tmp/smpeg-0.4.4)$ gdb -q .libs/glmovie
(gdb) break main
// First we need to have our real gClear in memory, opened by dlopen(), in
main we get it.
Breakpoint 1 at 0x80494ef: file glmovie.c, line 24.
(gdb) r …/abertura.mpg
Starting program: /home/diego/tmp/smpeg-0.4.4/.libs/glmovie …/abertura.mpg
[New Thread 1085001888 (LWP 27782)]
[Switching to Thread 1085001888 (LWP 27782)]

Breakpoint 1, main (argc=2, argv=0x40015020) at glmovie.c:24
24 if( argc < 2 ) {
Current language: auto; currently c++
(gdb) x/2i glClear
0x4007d59c : mov %gs:0xffffffc8,%eax
0x4007d5a2 <glClear+6>: jmp *0x270(%eax)
// we make a break point on jmp by glClear [where we have bug].
(gdb) break *0x4007d5a2
Breakpoint 2 at 0x4007d5a2
(gdb) c
Continuing.

// here we break at main() glClear (before starts second thread).
Breakpoint 2, 0x4007d5a2 in glClear () from /usr/lib/libGL.so.1
(gdb) bt
#0 0x4007d5a2 in glClear () from /usr/lib/libGL.so.1
#1 0x080495ca in main (argc=134517984, argv=0x804e3c0) at glmovie.c:77
#2 0x42015704 in __libc_start_main () from /lib/tls/libc.so.6
(gdb) info registers
// Look, our EAX is right! A Bealtifull pointer, that will be jmped at
glClear+6.
eax 0x40079d40 1074240832
ecx 0x80d2ef0 135081712
edx 0x1 1
ebx 0x8052898 134555800
esp 0xbfffe15c 0xbfffe15c
ebp 0xbfffe218 0xbfffe218
esi 0x804e3c0 134538176
edi 0x805b080 134590592
eip 0x4007d5a2 0x4007d5a2
eflags 0x246 582
cs 0x23 35
ss 0x2b 43
ds 0x2b 43
es 0x2b 43
fs 0x0 0
gs 0x33 51
// lets look the next call.
(gdb) c
Continuing.
Clear! // my printf after first glClear.
// our thread is started.
[New Thread 1116957488 (LWP 27785)]
[Switching to Thread 1116957488 (LWP 27785)]
// here is our call by smpeg thread!
Breakpoint 2, 0x4007d5a2 in glClear () from /usr/lib/libGL.so.1
(gdb) bt
#0 0x4007d5a2 in glClear () from /usr/lib/libGL.so.1
#1 0x080496ac in glmpeg_update (surface=0x805f008, x=134646664,
y=134646664, w=1074928007, h=1116957072) at glmovie.c:126
#2 0x4012192a in MPEGvideo::DisplayFrame(vid_stream*) (this=0x805f008,
vid_stream=0x8068b88) at gdith.cpp:357
#3 0x401219b6 in MPEGvideo::ExecuteDisplay(vid_stream*) (this=0x805f008,
vid_stream=0x8068b88) at gdith.cpp:395
#4 0x4012e5a3 in DoPictureDisplay (vid_stream=0x401b16a0) at video.cpp:4678
#5 0x4012666e in mpegVidRsrc(double, vid_stream*, int) (time_stamp=0,
vid_stream=0x8068b88, first=0) at video.cpp:1314
#6 0x4011fe98 in Play_MPEGvideo(void*) (udata=0x805f008) at
MPEGvideo.cpp:253
#7 0x401a8742 in SDL_RunThread (data=0x805bdc0) at SDL_thread.c:218
#8 0x401a891f in RunThread (data=0x805bdc0) at SDL_systhread.c:82
#9 0x401f0484 in start_thread () from /lib/tls/libpthread.so.0
(gdb) info registers
// ***** Where is our EAX?.. ***
eax 0x0 0
ecx 0x401b16a0 1075517088
edx 0x804969c 134518428
ebx 0x4013aee8 1075031784
esp 0x42936844 0x42936844
ebp 0x42936860 0x42936860
esi 0x4168b008 1097379848
edi 0x805f008 134606856
eip 0x4007d5a2 0x4007d5a2
eflags 0x212 530
cs 0x23 35
ss 0x2b 43
ds 0x2b 43
es 0x2b 43
fs 0x0 0
gs 0x33 51

// Here im looking the EAX by main() GlClear() jmp, and it continues there.
I dont think that we had any dlclose() by smped thread - that could make
some problem like this.
(gdb) x/i 0x40079d40
0x40079d40 <_nv000668gl+34400>: loopne 0x40079d02 <_nv000668gl+34338>
(gdb)

// And if we continue, we get:
(gdb) c
Continuing.
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1116957488 (LWP 26831)]
0x4007d5a2 in glClear () from /usr/lib/libGL.so.1
(gdb) bt
#0 0x4007d5a2 in glClear () from /usr/lib/libGL.so.1
#1 0x080496ac in glmpeg_update (surface=0x805f008, x=134555880,
y=134555880, w=1074928007, h=1116957072) at glmovie.c:126
#2 0x4012192a in MPEGvideo::DisplayFrame(vid_stream*) (this=0x805f008,
vid_stream=0x80528e8) at gdith.cpp:357
#3 0x401219b6 in MPEGvideo::ExecuteDisplay(vid_stream*) (this=0x805f008,
vid_stream=0x80528e8) at gdith.cpp:395
#4 0x4012e5a3 in DoPictureDisplay (vid_stream=0x401b16a0) at video.cpp:4678
#5 0x4012666e in mpegVidRsrc(double, vid_stream*, int) (time_stamp=0,
vid_stream=0x80528e8, first=0) at video.cpp:1314
#6 0x4011fe98 in Play_MPEGvideo(void*) (udata=0x805f008) at
MPEGvideo.cpp:253
#7 0x401a8742 in SDL_RunThread (data=0x805bdc0) at SDL_thread.c:218
#8 0x401a891f in RunThread (data=0x805bdc0) at SDL_systhread.c:82
#9 0x401f0484 in start_thread () from /lib/tls/libpthread.so.0
(gdb)

Then… any idea, about why we are losting the context? :expressionless:

Thanks by now.

Diego Contezini________________________________________________
Message sent using UebiMiau 2.7.2