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

Discuss use of unsafe for create_surface #426

Closed
ajtribick opened this issue Dec 12, 2022 · 2 comments
Closed

Discuss use of unsafe for create_surface #426

ajtribick opened this issue Dec 12, 2022 · 2 comments

Comments

@ajtribick
Copy link

The code in the State::new section of the introductory tutorial includes a call to the unsafe create_surface method. I think it would be useful to include a discussion of what is required for this call to be valid and why the usage shown meets these requirements, preferably also with a comment in the source code at that line.

@ajtribick
Copy link
Author

Reading up on the requirements of create_surface, I suspect that the implementation of State::new() as written should itself be marked as unsafe because it doesn't ensure that the lifetime requirement of the surface is met. I think this can be fixed by moving the Window into the last field of the State struct (last so it gets dropped last, ensuring it outlives the created Surface).

The "will panic if not called on the main thread" behavior with Metal doesn't sound like a memory unsafety issue as described, so maybe that's not relevant for providing a safe encapsulation of the unsafe call.

sotrh added a commit that referenced this issue Dec 28, 2022
@sotrh
Copy link
Owner

sotrh commented Jan 14, 2023

Should be fixed in the current version

@sotrh sotrh closed this as completed Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants