Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile/geom: concurrent modification to Width, Height global vars #10461

Closed
nigeltao opened this issue Apr 15, 2015 · 6 comments
Closed

x/mobile/geom: concurrent modification to Width, Height global vars #10461

nigeltao opened this issue Apr 15, 2015 · 6 comments

Comments

@nigeltao
Copy link
Contributor

geom.Width and geom.Height look like they're meant to be initialized once and not mutated afterwards, since they're plain global variables without any locking.

However, x/mobile/app and in particular loop_android.go updates these global vars when e.g. the phone rotates.

There is no clear line between the UI goroutine and the others. Should we protect each value or should we restrict them being accessible from the UI goroutine? This is a design question and requires discussion.

@nigeltao
Copy link
Contributor Author

Adding @rakyll @crawshaw @hyangah for x/mobile expertise.

@slimsag
Copy link

slimsag commented Apr 15, 2015

I would imagine that they are not intended to be accessed except in the UI goroutine (i.e. Draw callbacks etc), much as x/mobile/gl cannot be used except in that goroutine.

@crawshaw
Copy link
Member

There is a goroutine, locked to an OS thread, that is both responsible for updating geom.{Width, Height} and calling app.Draw. So there is no data race at the moment as long as width and height are only used from the Draw function (which is also the only safe place to use GL).

This however, is not a particularly goroutine-friendly design, and I'm open to alternatives.

@crawshaw
Copy link
Member

My current thinking on this is that these values should be folded into the app package. Stored in a type like:

type Config struct {
        Width       geom.Pt
        Height      geom.Pt
        PixelsPerPt float32
        Orientation Orientation
}

With a package function, func State() Config and a field of the Callbacks struct: State: func(Config).

But I'm not going to think about this again until after the Go 1.5 freeze. Then I'll prototype it in some apps and if it works, send out a CL. I believe there's some other Issue opened somewhere about app configuration updates, this would cover that too.

@rakyll
Copy link
Contributor

rakyll commented Apr 15, 2015

I like the idea of passing the current state to a callback. As an improvement, making the state available on each callback would be more user-friendly.

Start func(c Config)
Stop func(c Config)
Draw func(c Config)
Touch func(c Config, e event.Touch)

#10442 lists a number of other configuration related properties. We might provide a few of them as a part of Config if querying them are not costly.

Related to #10442 and #10327.

@gopherbot
Copy link

CL https://golang.org/cl/9708 mentions this issue.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 10, 2021
Config provides a way to concurrently access Width and Height.

Register provides a way for packages to run code on app state change
without plumbing changes all the way to the process main function.
This is motivated by gl/glutil.Image which needs to rebuild its
textures on start/stop and can be deeply nested.
(See golang.org/cl/9707 for the followup.)

Tested manually on android and darwin/amd64. Doing this kind makes it
clear any CL modifying this code needs a lot of manual testing right
now, so some kind of trybot support is something I'm going to
prioritise.

Fixes golang/go#10686
Fixes golang/go#10461
Fixes golang/go#10442
Fixes golang/go#10226
Updates golang/go#10327

Change-Id: I2882ebf3995b6ed857cda823e94fbb17c54b43a8
Reviewed-on: https://go-review.googlesource.com/9708
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 11, 2021
Config provides a way to concurrently access Width and Height.

Register provides a way for packages to run code on app state change
without plumbing changes all the way to the process main function.
This is motivated by gl/glutil.Image which needs to rebuild its
textures on start/stop and can be deeply nested.
(See golang.org/cl/9707 for the followup.)

Tested manually on android and darwin/amd64. Doing this kind makes it
clear any CL modifying this code needs a lot of manual testing right
now, so some kind of trybot support is something I'm going to
prioritise.

Fixes golang/go#10686
Fixes golang/go#10461
Fixes golang/go#10442
Fixes golang/go#10226
Updates golang/go#10327

Change-Id: I2882ebf3995b6ed857cda823e94fbb17c54b43a8
Reviewed-on: https://go-review.googlesource.com/9708
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
@rsc rsc unassigned rakyll Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants