bmx-ng / sdl.mod

SDL backend for BlitzMax
7 stars 6 forks source link

TSDLTimer crashes on Windows 8.1 #28

Closed RNavega closed 4 years ago

RNavega commented 4 years ago

Hi, I'm running this code on a Windows 8.1 64 system:

SuperStrict

Framework SDL.SDL
Import SDL.sdltimer
Import BRL.standardio

Print("Before timer.")

Local myTimer:TTimer = TSDLTimer.Create(30)
myTimer.Wait()

Print("After timer. Ticks: " + String(myTimer.Ticks()))
End

It causes this:
bmx01

Debug mode doesn't say what's the problem (no stack trace), but it locks on line 57 of sdl.mod/sdlsystem.mod/sdlsystem.bmx:
bmx02

GWRon commented 4 years ago

Segfaults on Linux too.

GWRon commented 4 years ago

GDB stacktrace:

Thread 1 "untitled1.debug" received signal SIGSEGV, Segmentation fault.
0x000000000040b639 in bbSDLSystemEmitEvent (extra=<optimized out>, y=0, x=0, 
    mods=0, data=<optimized out>, source=0x7ffff7e5cf60, id=2049)
    at /home/ronny/Arbeit/Tools/BlitzMaxNG/mod/sdl.mod/sdlsystem.mod/glue.c:42
42      BBObject *event=brl_event_CreateEvent( id,source,data,mods,x,y,extra );
(gdb) bt
#0  0x000000000040b639 in bbSDLSystemEmitEvent (extra=<optimized out>, y=0, x=0, mods=0, data=<optimized out>, 
    source=0x7ffff7e5cf60, id=2049) at /home/ronny/Arbeit/Tools/BlitzMaxNG/mod/sdl.mod/sdlsystem.mod/glue.c:42
#1  bmx_SDL_EmitSDLEvent (source=<optimized out>, event=0x7fffffffdcb0)
    at /home/ronny/Arbeit/Tools/BlitzMaxNG/mod/sdl.mod/sdlsystem.mod/glue.c:143
#2  bmx_SDL_WaitEvent () at /home/ronny/Arbeit/Tools/BlitzMaxNG/mod/sdl.mod/sdlsystem.mod/glue.c:204
#3  0x0000000000408732 in _sdl_sdlsystem_TSDLSystemDriver_Wait (o=<optimized out>)
    at /home/ronny/Arbeit/Tools/BlitzMaxNG/mod/sdl.mod/sdlsystem.mod/sdlsystem.bmx:57
#4  0x000000000040bc46 in brl_system_WaitSystem () at /home/ronny/Arbeit/Tools/BlitzMaxNG/mod/brl.mod/system.mod/system.bmx:119
#5  0x0000000000407087 in _sdl_sdltimer_TSDLTimer_Wait (o=<optimized out>)
    at /home/ronny/Arbeit/Tools/BlitzMaxNG/mod/sdl.mod/sdltimer.mod/sdltimer.bmx:131
#6  0x00000000004066ce in _bb_main () at /home/ronny/Arbeit/Tools/BlitzMaxNG/tmp/untitled1.bmx:10
#7  0x0000000000557173 in __bb_brl_appstub_appstub () at /home/ronny/Arbeit/Tools/BlitzMaxNG/mod/brl.mod/appstub.mod/appstub.bmx:77
#8  0x000000000040644f in main (argc=1, argv=0x7fffffffe1c8)
    at /home/ronny/Arbeit/Tools/BlitzMaxNG/mod/brl.mod/appstub.mod/appstub.linux.c:20
RNavega commented 4 years ago

Thanks for the extra info @GWRon

RNavega commented 4 years ago

Here's some progress, adding a new import (because that brl_event_CreateEvent() function was missing):

SuperStrict

Framework SDL.SDL
Import BRL.systemdefault '<-- Added.
Import BRL.standardio
Import SDL.sdltimer

Print("Before timer.")

Local myTimer:TTimer = TSDLTimer.Create(30)
myTimer.Wait()
Print("After timer. Ticks: " + String(myTimer.Ticks()))
End

Output:

Executing:timerTest.exe
Cannot initialise SDLSystemDriver. System driver already configured as Win32SystemDriver
Process complete

I wouldn't know how to make SDLSystemDriver take priority.

GWRon commented 4 years ago

sdl system driver is in sdl.system (which would import sdl.sdl already).

TSDLSystemDriver in sdl.mod/sdlsystem.mod contains this:


    Method Emit( osevent:Byte Ptr,source:Object )
        ' TODO
    End Method

I replaced it with:

    Method Emit( osevent:Byte Ptr,source:Object )
        bmx_SDL_EmitSDLEvent(osevent, source)
        ' TODO
    End Method

and in common.bmx (of the same dir) I replaced:

    Function bmx_SDL_WaitEvent()

with

    Function bmx_SDL_WaitEvent()
    Function bmx_SDL_EmitSDLEvent( event:Byte Ptr, source:object )

but compilation then fails:

[100%] Linking:untitled1.debug
/home/ronny/Arbeit/Tools/BlitzMaxNG/mod/sdl.mod/sdlsystem.mod/sdlsystem.debug.linux.x64.a(sdlsystem.bmx.debug.linux.x64.o): In Funktion »__bb_sdl_sdlsystem_sdlsystem«:
/home/ronny/Arbeit/Tools/BlitzMaxNG/mod/sdl.mod/sdlsystem.mod/sdlsystem.bmx:149: Warnung: undefinierter Verweis auf »_bb_sdl_sdlsystem_common«
collect2: error: ld returned 1 exit status
Build Error: Failed to link /home/ronny/Arbeit/Tools/BlitzMaxNG/tmp/untitled1.debug
Process complete

Maybe something else. I better do not even try to fix it and am better waiting for Brucey to do an official fix.

RNavega commented 4 years ago

Wow, that's a lot of work, thanks!
If there are some parts that need to be implemented then that's okay, at least we found out.

GWRon commented 4 years ago

Aaaand.... Bruceys fix looks totally different to what I expected ... seems it did try to access some memory it did not reserve first.

Wonder what that "todo" in Emit() is for.

RNavega commented 4 years ago

I would never have guessed that, thanks a lot for the fix.
@GWRon I guess that Emit() is probably the public API, for when you want to manually emit the event (based on the good ol' manual: https://en.wikibooks.org/wiki/BlitzMax/Modules/Events/Events#TEvent:_Methods). So the SDL-based event hook system is the TODO.