mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 12:32:05 +01:00
mainthread: Cause panic when trying to run before initialization
This commit is contained in:
parent
bcd9db669d
commit
05d78b4232
@ -16,18 +16,23 @@ package mainthread
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
}
|
}
|
||||||
|
|
||||||
var funcs = make(chan func())
|
var (
|
||||||
|
started = int32(0)
|
||||||
|
funcs = make(chan func())
|
||||||
|
)
|
||||||
|
|
||||||
// Loop starts the main-thread loop.
|
// Loop starts the main-thread loop.
|
||||||
//
|
//
|
||||||
// Loop must be called on the main thread.
|
// Loop must be called on the main thread.
|
||||||
func Loop(ch <-chan error) error {
|
func Loop(ch <-chan error) error {
|
||||||
|
atomic.StoreInt32(&started, 1)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case f := <-funcs:
|
case f := <-funcs:
|
||||||
@ -41,6 +46,10 @@ func Loop(ch <-chan error) error {
|
|||||||
|
|
||||||
// Run calls f on the main thread.
|
// Run calls f on the main thread.
|
||||||
func Run(f func() error) error {
|
func Run(f func() error) error {
|
||||||
|
if atomic.LoadInt32(&started) == 0 {
|
||||||
|
panic("mainthread: the mainthread loop is not started yet")
|
||||||
|
}
|
||||||
|
|
||||||
ch := make(chan struct{})
|
ch := make(chan struct{})
|
||||||
var err error
|
var err error
|
||||||
funcs <- func() {
|
funcs <- func() {
|
||||||
|
@ -189,6 +189,13 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
|||||||
}
|
}
|
||||||
i.image.ReplacePixels(pixels, x, y, width, height)
|
i.image.ReplacePixels(pixels, x, y, width, height)
|
||||||
|
|
||||||
|
// TODO: We wanted to skip copying pixels, but this can cause reading-pixels before the driver is initialized.
|
||||||
|
//
|
||||||
|
// if !IsRestoringEnabled() {
|
||||||
|
// i.makeStale()
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
if x == 0 && y == 0 && width == w && height == h {
|
if x == 0 && y == 0 && width == w && height == h {
|
||||||
if pixels != nil {
|
if pixels != nil {
|
||||||
if i.basePixels == nil {
|
if i.basePixels == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user