Comments (9)
I used a workaround : Declare egui_backend
at each .draw
method don't work (egui never draw). So, I use unsafe
code to set egui_backend
outside of my state (which is thread shared) : buxx/OpenCombat@2bb3f65
from ggegui.
I did not expect someone to use the gui asynchronously so I used Rc
instead of Arc
, when I have time I will make that little change
from ggegui.
Hello. Great news ! Thanks for your work.
from ggegui.
If it's not too much trouble, can you explain exactly why you use egui asynchronously and if possible, could you give me an example to test the changes I made (and maybe I'll add it to the examples folder)
from ggegui.
I use parallel iteration on the main state which own egui_backend
. Maybe there is another way to organize data ? In any case, there is a minimal reproducible example :
Cargo.toml
[package]
name = "demo"
version = "0.1.0"
edition = "2021"
[dependencies]
ggez = "0.8.1"
ggez-egui = "0.3.1"
rayon = "1"
src/main.rs
use ggez::{
event,
glam::Vec2,
graphics::{Canvas, Color, DrawParam},
Context, GameResult,
};
use ggez_egui::{egui, EguiBackend};
use rayon::prelude::*;
struct Monster;
impl Monster {
fn do_stuff(&self) {}
}
struct MainState {
monsters: Vec<Monster>,
egui_backend: EguiBackend,
}
impl MainState {
fn new() -> GameResult<MainState> {
Ok(Self {
monsters: vec![Monster {}, Monster {}],
egui_backend: EguiBackend::default(),
})
}
}
impl event::EventHandler<ggez::GameError> for MainState {
fn update(&mut self, ctx: &mut Context) -> GameResult {
let egui_ctx = self.egui_backend.ctx();
egui::Window::new("egui-window").show(&egui_ctx, |_ui| {});
self.egui_backend.update(ctx);
// Do something requiring thread safe
(0..self.monsters.len())
.into_par_iter()
.for_each(|i| self.update_monster(i));
Ok(())
}
fn draw(&mut self, ctx: &mut Context) -> GameResult {
let mut canvas = Canvas::from_frame(ctx, Color::BLACK);
canvas.draw(
&self.egui_backend,
DrawParam::default().dest(Vec2::new(0., 0.)),
);
canvas.finish(ctx)?;
Ok(())
}
}
impl MainState {
fn update_monster(&self, monster_i: usize) {}
}
pub fn main() -> GameResult {
let cb = ggez::ContextBuilder::new("x", "");
let (ctx, events_loop) = cb.build()?;
let state = MainState::new().unwrap();
event::run(ctx, events_loop, state)
}
from ggegui.
Now I understand what happened, how rust implements Sync
to a struct when all its fields implement Sync
too and EguiBackend used Rc
, then it failed because Rc
not implement Sync
because cannot be shared safely between threads.
And I already tried your example and everything works fine, now I will only make some changes that occurred to me right now and if it doesn't take me too long I will publish the new version today or torrow.
from ggegui.
I'm done, but you will have to change in Cargo.toml and in the imports of the library from ggez-egui
to ggegui
since the idea of changing the name of the library occurred, without knowing what would happen. Anyway, try the new version and if the change worked, you can close the issue
from ggegui.
Thank you ! I will try it as soon as possible !
from ggegui.
It's perfectly working @NemuiSen ! I close the issue :)
from ggegui.
Related Issues (12)
- Update to new egui release HOT 2
- ScrollArea's content leaking outside the ScrollArea's rect HOT 4
- ComboBox's selectable_value cannot be selected using left click HOT 2
- Right clicking a button spams it rly fast HOT 1
- Examples don't render HOT 1
- Scale seems to not be working HOT 2
- Focus/Cursor position is changing too fast HOT 1
- Delta pos HOT 2
- Semi-automatic dependency update with dependabot HOT 2
- Changing text styles may cause an error HOT 1
- clic / drag event is based on frames not time. HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ggegui.