Hey guys! My code has a memory issue. Here's the code:
https://github.com/Chubek/pong-q-learning-nim
It's a rather lengthy code so let me tell you what it's made up of:
1- The Pong game with SDL2. 2- The opponent AI with classical AI. 3- Q-learning player AI.
Now it gives SIEGV error segmentation fault after like 2-3 minutes of running the game and having it play itself. I was promised memory safety in Nim and I deman memory safety dammit! Knowing that cdecl functions are not memory safe, it could be one of them.
My question is, how to debug segmentation fault memory issues? Is here an easy, straeamlined way to do so?
Thanks!
Thanks, I tried with threads:on when I was using SDL threads. But why was I using SDL threads instead of Nim threads? BECAUSE I COULD NOT USE NIM THREADS DUE TO NAMING ISSUE.
I mean I can't import sys/threads, I can't use threads.Thread directly. I don't really know how to use Nim threads when using SDL?
It's not just about using Nim threads vs SDL threads - if SDL uses threads, Nim also needs to know that to ensure that GC and other things work correctly, so you have to pass --threads:on anyway.
And also - you don't need to import threads yourself, they're automatically imported if you compile with --threads:on.
You could just create an alias for the type and re-export it ?
# localsdl.nim
import sdl
type
SdlThread* = sdl.Thread
export sdl except Thread
Then use import localsdl
Callbacks passed to C need to be in a {.push stacktrace:off.} section, maybe we can have that implied when we use the {.cdecl.} pragma?
See: https://github.com/mratsim/trace-of-radiance/blob/e928285/trace_of_radiance/io/mp4.nim#L115-L126