Skip to content

Commit

Permalink
Bug fix: objects can be GCed unexpectedly
Browse files Browse the repository at this point in the history
Fixes #73
  • Loading branch information
hajimehoshi committed Apr 2, 2019
1 parent 6e79bca commit ea42285
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions winmm_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package oto

import (
"fmt"
"runtime"
"unsafe"

"golang.org/x/sys/windows"
Expand Down Expand Up @@ -128,6 +129,7 @@ func waveOutOpen(f *waveformatex) (uintptr, error) {
var w uintptr
r, _, e := procWaveOutOpen.Call(uintptr(unsafe.Pointer(&w)), waveMapper, uintptr(unsafe.Pointer(f)),
0, 0, callbackNull)
runtime.KeepAlive(f)
if e.(windows.Errno) != 0 {
return 0, &winmmError{
fname: "waveOutOpen",
Expand Down Expand Up @@ -163,6 +165,7 @@ func waveOutClose(hwo uintptr) error {

func waveOutPrepareHeader(hwo uintptr, pwh *wavehdr) error {
r, _, e := procWaveOutPrepareHeader.Call(hwo, uintptr(unsafe.Pointer(pwh)), unsafe.Sizeof(wavehdr{}))
runtime.KeepAlive(pwh)
if e.(windows.Errno) != 0 {
return &winmmError{
fname: "waveOutPrepareHeader",
Expand All @@ -180,6 +183,7 @@ func waveOutPrepareHeader(hwo uintptr, pwh *wavehdr) error {

func waveOutWrite(hwo uintptr, pwh *wavehdr) error {
r, _, e := procWaveOutWrite.Call(hwo, uintptr(unsafe.Pointer(pwh)), unsafe.Sizeof(wavehdr{}))
runtime.KeepAlive(pwh)
if e.(windows.Errno) != 0 {
return &winmmError{
fname: "waveOutWrite",
Expand Down

0 comments on commit ea42285

Please # to comment.