-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add notice about known problems with SDL2 and V's garbage colle…
…ctor
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module main | ||
|
||
import sdl | ||
|
||
struct Data1 { | ||
mut: | ||
a int | ||
} | ||
|
||
fn main() { | ||
mut data1 := []&Data1{cap: 200} | ||
for i in 0 .. 200 { | ||
data1 << &Data1{ | ||
a: i | ||
} | ||
} | ||
|
||
sdl.init(sdl.init_video) | ||
window := sdl.create_window('Hello SDL2'.str, 300, 300, 500, 300, 0) | ||
renderer := sdl.create_renderer(window, -1, u32(sdl.RendererFlags.accelerated) | u32(sdl.RendererFlags.presentvsync)) | ||
|
||
mut should_close := false | ||
mut ticks := 0 | ||
for { | ||
ticks++ | ||
evt := sdl.Event{} | ||
for 0 < sdl.poll_event(&evt) { | ||
match evt.@type { | ||
.quit { should_close = true } | ||
else {} | ||
} | ||
} | ||
|
||
data1[0].a = ticks | ||
data1.delete(10) | ||
data1 << &Data1{ | ||
a: ticks | ||
} | ||
|
||
println('ticks: ${ticks}') | ||
if should_close || ticks == 1000 { | ||
break | ||
} | ||
|
||
sdl.set_render_draw_color(renderer, 255, 55, 55, 255) | ||
sdl.render_clear(renderer) | ||
sdl.render_present(renderer) | ||
} | ||
println('Exiting. If this was compiled without `-d sdl_memory_no_gc`, an invalid memory access error should occur') | ||
|
||
sdl.destroy_renderer(renderer) | ||
sdl.destroy_window(window) | ||
sdl.quit() | ||
} |