{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/10636","labels_url":"https://api.github.com/repos/golang/go/issues/10636/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/10636/comments","events_url":"https://api.github.com/repos/golang/go/issues/10636/events","html_url":"https://github.com/golang/go/issues/10636","id":72133926,"number":10636,"title":"x/mobile/audio/al: current context gets GCed causing playback to stop unexpectedly","user":{"login":"TheDasc","id":12174414,"avatar_url":"https://avatars.githubusercontent.com/u/12174414?v=3","gravatar_id":"","url":"https://api.github.com/users/TheDasc","html_url":"https://github.com/TheDasc","followers_url":"https://api.github.com/users/TheDasc/followers","following_url":"https://api.github.com/users/TheDasc/following{/other_user}","gists_url":"https://api.github.com/users/TheDasc/gists{/gist_id}","starred_url":"https://api.github.com/users/TheDasc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheDasc/subscriptions","organizations_url":"https://api.github.com/users/TheDasc/orgs","repos_url":"https://api.github.com/users/TheDasc/repos","events_url":"https://api.github.com/users/TheDasc/events{/privacy}","received_events_url":"https://api.github.com/users/TheDasc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"rakyll","id":108380,"avatar_url":"https://avatars.githubusercontent.com/u/108380?v=3","gravatar_id":"","url":"https://api.github.com/users/rakyll","html_url":"https://github.com/rakyll","followers_url":"https://api.github.com/users/rakyll/followers","following_url":"https://api.github.com/users/rakyll/following{/other_user}","gists_url":"https://api.github.com/users/rakyll/gists{/gist_id}","starred_url":"https://api.github.com/users/rakyll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rakyll/subscriptions","organizations_url":"https://api.github.com/users/rakyll/orgs","repos_url":"https://api.github.com/users/rakyll/repos","events_url":"https://api.github.com/users/rakyll/events{/privacy}","received_events_url":"https://api.github.com/users/rakyll/received_events","type":"User","site_admin":false},"milestone":null,"comments":6,"created_at":"2015-04-30T11:30:12Z","updated_at":"2015-05-06T16:00:39Z","closed_at":null,"body":"reproduced with go 1.4.2 amd64 on linux/ubuntu amd64\r\nfollowing code reproduces the issue (uncomment the line for correct behaviour)\r\nsince there are no more references to context after setting it as current, GC may remove it, triggering its finalizer which calls context.Destroy() thus stopping playback\r\nthis affects x/mobile/audio as a consequence\r\n\r\n```\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"golang.org/x/mobile/audio/al\"\r\n\t\"math\"\r\n)\r\n\r\nfunc main() {\r\n\tsamplesPerSecond := int64(44100)\r\n\tfrequency := int64(1500)\r\n\r\n\tdevice := al.Open(\"\")\r\n\tcontext := device.CreateContext(nil)\r\n\tal.MakeContextCurrent(context)\r\n\r\n\tbuffers := al.GenBuffers(1)\r\n\tbytes := make([]byte, 100000)\r\n\tFillBufferMono8(bytes, samplesPerSecond, frequency)\r\n\tbuffers[0].BufferData(uint32(0x1100), bytes, int32(samplesPerSecond))\r\n\r\n\tsources := al.GenSources(1)\r\n\tsources[0].QueueBuffers(buffers)\r\n\tal.PlaySources(sources[0])\r\n\r\n\twaiter := make(chan int)\r\n\t<-waiter\r\n\tfmt.Println(\"you won't see this\")\r\n\r\n\tal.DeleteSources(sources[0])\r\n\tal.DeleteBuffers(buffers)\r\n\t//context.Destroy() // Uncomment this line\r\n\tdevice.Close()\r\n}\r\n\r\nfunc FillBufferMono8(buffer []byte, samplesPerSecond int64, frequency int64) {\r\n\tbufferLength := len(buffer)\r\n\tfor i := int64(0); i < int64(bufferLength); i++ {\r\n\t\tsampleIndex := i\r\n\t\tsinResult := math.Sin(math.Pi * 2 * (float64(sampleIndex%samplesPerSecond) / float64(samplesPerSecond)) * float64(frequency))\r\n\t\tsample := byte(255 * 0.5 * (1.0 + sinResult))\r\n\t\tbuffer[i] = sample\r\n\t}\r\n}\r\n```\r\n\r\ndiscussion [here](https://groups.google.com/forum/#!topic/golang-nuts/_VsXoDoWR5s)"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/99523178","html_url":"https://github.com/golang/go/issues/10636#issuecomment-99523178","issue_url":"https://api.github.com/repos/golang/go/issues/10636","id":99523178,"user":{"login":"gopherbot","id":8566911,"avatar_url":"https://avatars.githubusercontent.com/u/8566911?v=3","gravatar_id":"","url":"https://api.github.com/users/gopherbot","html_url":"https://github.com/gopherbot","followers_url":"https://api.github.com/users/gopherbot/followers","following_url":"https://api.github.com/users/gopherbot/following{/other_user}","gists_url":"https://api.github.com/users/gopherbot/gists{/gist_id}","starred_url":"https://api.github.com/users/gopherbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gopherbot/subscriptions","organizations_url":"https://api.github.com/users/gopherbot/orgs","repos_url":"https://api.github.com/users/gopherbot/repos","events_url":"https://api.github.com/users/gopherbot/events{/privacy}","received_events_url":"https://api.github.com/users/gopherbot/received_events","type":"User","site_admin":false},"created_at":"2015-05-06T16:00:39Z","updated_at":"2015-05-06T16:00:39Z","body":"CL https://golang.org/cl/9782 mentions this issue."}}