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

Add 'Unsafe textures' feature #683

Merged
merged 4 commits into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ before_script:
export PATH=$HOME/.local/bin:$PATH
script:
- |
travis-cargo build -- --all-features &&
travis-cargo test -- --all-features &&
travis-cargo --only stable doc -- --all-features
travis-cargo build -- --features "gfx image ttf mixer" &&
travis-cargo test -- --features "gfx image ttf mixer" &&
travis-cargo --only stable doc -- --features "gfx image ttf mixer"
after_success:
- travis-cargo --only stable doc-upload
env:
Expand Down
78 changes: 78 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ optional = true

[features]

unsafe_textures = []
default = []
ttf = []
image = []
Expand All @@ -43,3 +44,80 @@ mixer = []

use-pkgconfig = [ "sdl2-sys/use-pkgconfig" ]
use_mac_framework = ["sdl2-sys/use_mac_framework"]

[[example]]
name = "animation"

[[example]]
name = "audio-queue-squarewave"

[[example]]
name = "audio-wav"

[[example]]
name = "audio-whitenoise"

[[example]]
name = "demo"

[[example]]
name = "game-controller"

[[example]]
required-features = ["unsafe_textures"]
name = "game-of-life-unsafe-textures"

[[example]]
name = "game-of-life"

[[example]]
required-features = ["gfx"]
name = "gfx-demo"

[[example]]
name = "haptic"

[[example]]
required-features = ["image"]
name = "image-demo"

[[example]]
name = "joystick"

[[example]]
name = "keyboard-state"

[[example]]
name = "message-box"

[[example]]
required-features = ["mixer"]
name = "mixer-demo"

[[example]]
name = "mouse-state"

[[example]]
name = "no-renderer"

[[example]]
name = "relative-mouse-state"

[[example]]
name = "renderer-target"

[[example]]
name = "renderer-texture"

[[example]]
name = "renderer-yuv"

[[example]]
name = "resource-manager"

[[example]]
required-features = ["ttf"]
name = "ttf-demo"

[[example]]
name = "window-properties"
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ If you want a library compatible with earlier versions of SDL, please see

# Documentation

* [master documentation](https://rust-sdl2.github.io/rust-sdl2/sdl2/)
* [crates.io documentation](https://docs.rs/sdl2/)
* [crates.io documentation](https://docs.rs/sdl2/), with no features at all.
* [master documentation](https://rust-sdl2.github.io/rust-sdl2/sdl2/) with the following features:
* gfx
* image
* mixer
* ttf

# Requirements

Expand Down Expand Up @@ -299,6 +303,19 @@ You can see the full list in the `examples/` folder. Some examples require some

Replace "gfx" by the feature(s) needed for the example you want.

# About the `unsafe_textures` feature

In the `sdl2::render` module, `Texture` has by default lifetimes to prevent it from out-living its parent `TextureCreator`.
These lifetimes are sometimes too hard to deal with in Rust, and so you have the option to enable the `unsafe_textures` feature.

This removes the lifetimes on the `Texture`s, at the cost of optional manual memory management. If you want to manually destroy
the `Texture`s you use, you can call the `destroy` method of your `Texture`s, but beware that *it should not* be called if none of
the parents (`Canvas` or `TextureCreator`) are alive. If you do not call this method, the memory will simply be freed when
the last `Canvas` or the last `TextureCreator` will be freed.

There is no online documentation for this feature, however you can build it yourself in your project by enabling the feature in your
Cargo.toml, running `cargo doc` and accessing `target/doc/sdl2/index.html` via a browser.

# OpenGL

If you want to use OpenGL, you also need the
Expand Down
Loading