AmigaPorts / SDL

Simple Directmedia Layer, 2.x / 3.x for AmigaOS 4. SDL3 is in "main" branch and SDL2 is in "SDL2" branch. SDL1 is in another repo (https://github.com/AmigaPorts/SDL-1.2).
https://libsdl.org
zlib License
14 stars 2 forks source link

should SDL_CreateThread() work? #95

Open javierdlr opened 6 months ago

javierdlr commented 6 months ago

Hi, I just updated ZGloom (https://github.com/javierdlr/ZGloom_amigaos4 forked from https://github.com/Swizpig/ZGloom) and whne I enable "multithread rendering" option system crashes (attached). Crashlog_ZGloom.zip Crashlog_SDL thread floorthread.zip

it uses SDL_CreateThread() and SDL_LockMutex() in renderer.cpp

I build using "-athread=native -lpthread" ppc-amigaos-g++ zgui.o binresource.o config.o decrunchmania.o font.o gamelogic.o gloommap.o gloommaths.o hud.o iffhandler.o menuscreen.o monsterlogic.o objectgraphics.o quick.o renderer.o script.o soundhandler.o titlescreen.o zgloom.o -I./LIBS/include -L./LIBS/lib -L/work/local/newlib/lib -fstack-protector -lSDL2_mixer -lxmp-lite -lmodplug -lSDL2_image -ltiff -lwebp -lpng16 -ljpeg -lSDL2 -lz -athread=native -lpthread -o ZGloom.debug

capehill commented 6 months ago

First crashlog has nothing todo with SDL as far as I can see, some C++ issue?

SDL thread is used to play audio, for example, so it is expected to work. There are also thread test programs in test/ directory.

However, in this case, on AmigaOS 4, I don't any sense to enable this multithread rendering for the following reasons:

1) Single-core operating system 2) This game engine is creating 2 threads (== AmigaOS processes) during each frame! This is horrible. Those threads should be pooled. 3) Thread creation result is not checked. If it fails, crash.

Please don't enable multirendering.

If you are more curious about the problem, use debug variants of SDL2 libraries and look at the serial.

PS. Not sure why -lpthread is used, at least SDL2 doesn't use it.

javierdlr commented 5 months ago

Hola capehill

El 21-04-2024, escribiste:

First crashlog has nothing todo with SDL as far as I can see, some C++ issue?

SDL thread is used to play audio, for example, so it is expected to work. There are also thread test programs in test/ directory.

However, in this case, on AmigaOS 4, I don't any sense to enable this multithread rendering for the following reasons:

1) Single-core operating system 2) This game engine is creating 2 threads (== AmigaOS processes) during each frame! This is horrible. Those threads should be pooled. 3) Thread creation result is not checked. If it fails, crash. [...]

ok, thx for clarification, will disable such option.

Saludos -- AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonRX550/SSD240GB/DVDRW :-P

javierdlr commented 5 months ago

Hola capehill

El 21-04-2024, escribiste:

First crashlog has nothing todo with SDL as far as I can see, some C++ issue?

SDL thread is used to play audio, for example, so it is expected to work. There are also thread test programs in test/ directory. [...] If you are more curious about the problem, use debug variants of SDL2 libraries and look at the serial.

PS. Not sure why -lpthread is used, at least SDL2 doesn't use it. Seems webp "package" uses pthreads: ... /SDK/local/newlib/lib/libwebp.a(libwebpdecode_la-vp8_dec.o): In function InitGetCoeffs': /home/michael/libwebp-1.3.2/src/dec/vp8_dec.c:499: undefined reference topthread_mutex_lock' /home/michael/libwebp-1.3.2/src/dec/vp8_dec.c:499: undefined reference to pthread_mutex_unlock' ... /SDK/local/newlib/lib/libsharpyuv.a(libsharpyuv_la-sharpyuv.o): In functionSharpYuvInit': /home/michael/libwebp-1.3.2/sharpyuv/sharpyuv.c:448: undefined reference to pthread_mutex_lock' /home/michael/libwebp-1.3.2/sharpyuv/sharpyuv.c:462: undefined reference topthread_mutex_unlock'

Saludos -- AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonRX550/SSD240GB/DVDRW :-P