Skip to content

Instantly share code, notes, and snippets.

@theinternetftw
Created August 21, 2021 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theinternetftw/95151dd990fe955644275e13993ef69e to your computer and use it in GitHub Desktop.
Save theinternetftw/95151dd990fe955644275e13993ef69e to your computer and use it in GitHub Desktop.
Small bug repro program for shiny win32 memory corruption issue
// Run over and over again until bug appears.
// Takes less than a minute on my system.
//
// I used a bash script like so:
//
// #!/bin/bash -e
// while true; do
// ./repro.exe
// done
package main
import (
"fmt"
"os"
"time"
"golang.org/x/exp/shiny/driver/windriver"
"golang.org/x/exp/shiny/screen"
)
func main() {
// mock data usage
{
obj := []float64{}
const size1 = 1024*1024*10
for i := 0; i < size1; i++ {
obj = append(obj, float64(i))
}
const size2 = 1024*1024*10
data := make([]float64, size2)
for i := range data {
data[i] = float64(i)
}
}
image := make([]byte, 640*360*4)
windriver.Main(func(s screen.Screen) {
_, err := s.NewWindow(&screen.NewWindowOptions{
Width: 10,
Height: 10,
})
if err != nil {
fmt.Println("err opening window:", err)
os.Exit(1)
}
startTime := time.Now()
lastChecksum := 0
for {
for i := range image {
image[i] = 0
}
for i := range image {
image[i] = byte(i)
}
checksum := 0
for i := range image {
checksum += int(image[i])
}
if lastChecksum != 0 && lastChecksum != checksum {
fmt.Println("memory corruption!")
os.Exit(1)
}
lastChecksum = checksum
if time.Now().Sub(startTime) > 333*time.Millisecond {
os.Exit(0)
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment