M
Modular4mo ago
Helehex

Dustbin

I made a little falling sand game today in mojo. https://github.com/helehex/dustbin
GitHub
GitHub - helehex/dustbin
Contribute to helehex/dustbin development by creating an account on GitHub.
27 Replies
Darin Simmons
Darin Simmons4mo ago
Next up, model gym for learning lunar lander but all in mojo Wheeeeee
dlopen failed: /lib/x86_64-linux-gnu/libSDL2-2.0.so: cannot open shared object file: No such file or directory
[53663:53663:20240820,192200.276429:ERROR elf_dynamic_array_reader.h:64] tag not found
[53663:53663:20240820,192200.276745:ERROR elf_dynamic_array_reader.h:64] tag not found
[53663:53663:20240820,192200.277896:ERROR elf_dynamic_array_reader.h:64] tag not found
[53663:53663:20240820,192200.278108:ERROR elf_dynamic_array_reader.h:64] tag not found
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0. Program arguments: mojo game.mojo
[53663:53664:20240820,192200.282478:ERROR directory_reader_posix.cc:42] opendir /home/darin/.modular/crashdb/attachments/f2c3991d-7e5c-49d1-a008-2a286cd8d294: No such file or directory (2)
#0 0x00005ad3377633cb llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) Signals.cpp:0:0
#1 0x00005ad337761329 llvm::sys::RunSignalHandlers() Signals.cpp:0:0
#2 0x00005ad337763a6d SignalHandler(int) Signals.cpp:0:0
#3 0x000072fb24842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x000072faa0036000
mojo crashed!
Please file a bug report.
Illegal instruction (core dumped)
dlopen failed: /lib/x86_64-linux-gnu/libSDL2-2.0.so: cannot open shared object file: No such file or directory
[53663:53663:20240820,192200.276429:ERROR elf_dynamic_array_reader.h:64] tag not found
[53663:53663:20240820,192200.276745:ERROR elf_dynamic_array_reader.h:64] tag not found
[53663:53663:20240820,192200.277896:ERROR elf_dynamic_array_reader.h:64] tag not found
[53663:53663:20240820,192200.278108:ERROR elf_dynamic_array_reader.h:64] tag not found
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0. Program arguments: mojo game.mojo
[53663:53664:20240820,192200.282478:ERROR directory_reader_posix.cc:42] opendir /home/darin/.modular/crashdb/attachments/f2c3991d-7e5c-49d1-a008-2a286cd8d294: No such file or directory (2)
#0 0x00005ad3377633cb llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) Signals.cpp:0:0
#1 0x00005ad337761329 llvm::sys::RunSignalHandlers() Signals.cpp:0:0
#2 0x00005ad337763a6d SignalHandler(int) Signals.cpp:0:0
#3 0x000072fb24842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x000072faa0036000
mojo crashed!
Please file a bug report.
Illegal instruction (core dumped)
Thoughts?
Helehex
HelehexOP4mo ago
I had to do it
Helehex
HelehexOP4mo ago
tell me if running sudo apt install libsdl2-dev in your terminal works, if not i might have to make some changes to sdl bindings if your still awake i didnt see the message until now i have a feeling you'r gonna have to install all the satellite libraries aswell which im not even using working on improving sdl bindings rn to give better errors and such How can I incorporate both magnets and digital intelligence into my little dustbin
Darkmatter
Darkmatter4mo ago
https://anaconda.org/conda-forge/sdl2 It might make sense to use the conda-forge version of sdl2.
Helehex
HelehexOP4mo ago
that would probly be really helpful
Moosems / Three chickens
I didn’t realize there were SDL bindings already
Ryulord
Ryulord4mo ago
I was looking into doing this but the sdl bindings currently use mojo nightly and magic doesn't support nightly yet. Definitely going to try to get that working once next stable drops
Darkmatter
Darkmatter4mo ago
We really just need nightly in magic.
Ryulord
Ryulord4mo ago
yeah this would also work
Helehex
HelehexOP4mo ago
getting some random segfaults in the nightly that just dropped, same with thermo i think maybe something with the sdl event system
Moosems / Three chickens
What’re tonight’s changes?
Helehex
HelehexOP4mo ago
ok, it's definitely something with the event system causing segfaults.. but now mojo is refusing to compile because of commented out code.. nvm i forgot the sdl example file was using the packaged version 😮‍💨
Helehex
HelehexOP4mo ago
i fixed the aforementioned segfault in sdl bindings btw, but also, tonight i added camera movement and zoom
Helehex
HelehexOP4mo ago
rendering took a performance hit, but it can definitely be improved back to it's former glory
ziyu4huang
ziyu4huang4mo ago
I found it broken in Ubuntu 24 , this is because the Window in sdl-binding will construct Surface , and it's forbidden in SDL2 / Ubuntu2 . I fix it by remove it . because dustbin use Render and not allow Surface bind to Window ++ b/src/render.mojo @@ -10,25 +10,25 @@ struct Renderer[lif: AnyLifetime[False].type]: var sdl: Reference[SDL, lif] var _renderer_ptr: Ptr[_Renderer] var window: Window[lif] - var surface: Surface[lif] + #var surface: Surface[lif] fn init(inout self, owned window: Window[lif], index: Int = -1, flags: UInt32 = RendererFlags.SDL_RENDERER_ACCELERATED) raises: self.sdl = window.sdl self._renderer_ptr = self.sdl[]._sdl.create_renderer(window._window_ptr, index, flags) self.window = window^ - self.surface = Surface(self.sdl[]) + #self.surface = window.surface fn init(inout self, owned surface: Surface[lif]) raises: self.sdl = surface.sdl self._renderer_ptr = self.sdl[]._sdl.create_software_renderer(surface._surface_ptr) self.window = Window(self.sdl[]) - self.surface = surface^ + #self.surface = window.surface fn moveinit(inout self, owned other: Self): self.sdl = other.sdl self._renderer_ptr = other._renderer_ptr self.window = other.window^ - self.surface = other.surface^ + #self.surface = other.surface Renderer could not be created! SDL_Error: Surface already associated with window. in Ubuntu 22 it works fine , it's seems Ubuntu 24 forbidden it .
Helehex
HelehexOP4mo ago
im aware that your not supposed to use surface and renderer together, but i didn't know it was that bad that just calling get surface would cause issues.. everything worked fin for me. Also, as of yesterday, im not actually using renderer in dustbin other than creating it. Things got changed when adding camera movement to directly modifying the window surface pixels, but i'm going to work on improving render performance today, so it'll likely change back to using renderer. For sdl-bindings, we could destroy the window surface once a window is passed into a renderer's initializer... but not sure if theres a better way *edit: i'm actually still using renderer to draw the cursor rect, and to get the output size. hopefully i can come up with something better for the draw loop today If you have a fix, definitely open a pr in sdl-bindings https://github.com/Ryul0rd/sdl-bindings I updated dustbin, hopefully this problem is resolved? The world is by default 6000x800 cells now, and it runs pretty good, my target is 100 fps Also, zooming in gives better performance currently, but the whole world is still being simulated
Helehex
HelehexOP4mo ago
i dont think i've seen anyone do stone like this, but i kinda like it... I'm sure someone's tried it, they just didn't like it enough to keep it afaik
Helehex
HelehexOP4mo ago
I'll push it before i go to sleep, there was one other thing i wanted to try fixing in the sdl.mojopkg im using aswell I maybe fixed the sdl-bindings thing... I thought destroy_window_surface() would do what i want, but using it segfaults, so I'm just destroying it manually... Tonight I abstracted particle logic into their own functions for each particle type, and also added pausing and frame stepping.
Moosems / Three chickens
Nice!! Make that a trait and wrap it in a bow 😉
Helehex
HelehexOP4mo ago
Managed to get this working.
No description
Helehex
HelehexOP4mo ago
@Darin Simmons also suggested changing the cursor color based on what's selected, so i added that theres still another 2 bytes i could add to Particle to make it 64 bits if i move color to a separate allocation, that frees up even more for other things i can also change skip to a byte for various flags at some point i'm gonna try doing a hybrid of frame swapping, and skip marking so that i can have a game of life particle
seewind
seewind4mo ago
do you know is it can run under wsl2? I try in wsl2, raise: Unhandled exception caught during execution: SDL_Error: Could not create renderer, Surface already associated with window
Helehex
HelehexOP4mo ago
yeah, that's what i'm using are you sure you have the latest version? I was getting that error on my debian laptop but fixed it yesterday
seewind
seewind4mo ago
my version: Ubuntu 24.04 LTS Linux ub24.04 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Helehex
HelehexOP4mo ago
did some testing, and i dont think having color be a separate allocation to avoid the cpu copy would give as much rendering speed up as i would hope, which is wierd.. The render.copy actually takes more time than the cpu copy loop, and since it seems a render.copy is required either way, not sure it's worth it for the added complexity and overhead it would cause for the particle loop i tried with both RENDER_ACCELERATED and RENDER_SOFTWARE, hardware acceleration actually causes everything to be about twice as slow not sure whats going on there, even if i comment out my cpu copy loop which is the thing locking/unlocking the texture which i'm assuming locking/unlocking would cause issues with passing back and forth between cpu and gpu but maybe render.copy does as well, since thats even slower than my cpu copy loop all in all, i'm very confused about the performance of everything, and not sure how to improve rendering yet so for now i'm just gonna say the rending is good'nuff if anyone knows more about sdl rendering and want to give me some tips, that be much appreciated. i've only started learning sdl about a month ago I removed all noticeable sideways bias by flipping the x scan direction every frame. It was already barely noticeable, but even better now. I also tried some different things for pseudorandom number generation, but decided to just stick with xorshift One of the things i tried today was caching a large batch of random numbers at the start of each frame, then iterating an index every call to rand() But that was the same speed as xorshift Maybe to squeeze more out, i could keep a bigger random state, and make batched calls to random inside each particles update loop, so each particle would only have to call rand() once. then there would be no index to increment, and should free up the cpu pipes i also just added update regioning, which was very easy so only particles in view get updated i have a field with 268435456 particles running at 100 fps :] I can feel my L2 cache as i move around to fast though made it per-axis as well, since you probably dont want y regioning
Darin Simmons
Darin Simmons4mo ago
:mojonightly:
Helehex
HelehexOP3mo ago
dustbin uses magic now, so you no longer have to manually install SDL. I'm using my fork of the sdl-bindings package, but not sure how to make it a dependency in magic yet, so it's still inside the repo
Want results from more Discord servers?
Add your server