mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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 (
|
||||
"runtime"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
func init() {
|
||||
runtime.LockOSThread()
|
||||
}
|
||||
|
||||
var funcs = make(chan func())
|
||||
var (
|
||||
started = int32(0)
|
||||
funcs = make(chan func())
|
||||
)
|
||||
|
||||
// Loop starts the main-thread loop.
|
||||
//
|
||||
// Loop must be called on the main thread.
|
||||
func Loop(ch <-chan error) error {
|
||||
atomic.StoreInt32(&started, 1)
|
||||
for {
|
||||
select {
|
||||
case f := <-funcs:
|
||||
@ -41,6 +46,10 @@ func Loop(ch <-chan error) error {
|
||||
|
||||
// Run calls f on the main thread.
|
||||
func Run(f func() error) error {
|
||||
if atomic.LoadInt32(&started) == 0 {
|
||||
panic("mainthread: the mainthread loop is not started yet")
|
||||
}
|
||||
|
||||
ch := make(chan struct{})
|
||||
var err error
|
||||
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)
|
||||
|
||||
// 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 pixels != nil {
|
||||
if i.basePixels == nil {
|
||||
|
Loading…
Reference in New Issue
Block a user