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

Send ScriptErrorEvent when load fails. #125

Merged
merged 5 commits into from
Sep 7, 2024
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
3 changes: 2 additions & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
type-complexity-threshold=1000
type-complexity-threshold = 1000
too-many-arguments-threshold = 999
5 changes: 5 additions & 0 deletions crates/bevy_mod_scripting_core/src/hosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
error::ScriptError,
event::{ScriptEvent, ScriptLoaded},
world::WorldPointer,
ScriptErrorEvent,
};

/// Describes the target set of scripts this event should
Expand Down Expand Up @@ -358,6 +359,7 @@ impl<T: Asset> Script<T> {
providers: &mut APIProviders<H>,
contexts: &mut ScriptContexts<H::ScriptContext>,
event_writer: &mut EventWriter<ScriptLoaded>,
error_writer: &mut EventWriter<ScriptErrorEvent>,
) {
debug!("reloading script {}", script.id);

Expand All @@ -374,6 +376,7 @@ impl<T: Asset> Script<T> {
providers,
contexts,
event_writer,
error_writer,
);
} else {
// remove old context
Expand All @@ -392,6 +395,7 @@ impl<T: Asset> Script<T> {
providers: &mut APIProviders<H>,
contexts: &mut ScriptContexts<H::ScriptContext>,
event_writer: &mut EventWriter<ScriptLoaded>,
error_writer: &mut EventWriter<ScriptErrorEvent>,
) {
let fd = ScriptData {
sid: new_script.id(),
Expand Down Expand Up @@ -424,6 +428,7 @@ impl<T: Asset> Script<T> {
// this script will now never execute, unless manually reloaded
// but contexts are left in a valid state
contexts.insert_context(fd, None);
error_writer.send(ScriptErrorEvent { error: e });
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_mod_scripting_core/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub fn script_add_synchronizer<H: ScriptHost + 'static>(
script_assets: Res<Assets<H::ScriptAsset>>,
mut contexts: ResMut<ScriptContexts<H::ScriptContext>>,
mut event_writer: EventWriter<ScriptLoaded>,
mut error_writer: EventWriter<ScriptErrorEvent>,
) {
debug!("Handling addition/modification of scripts");

Expand All @@ -47,6 +48,7 @@ pub fn script_add_synchronizer<H: ScriptHost + 'static>(
&mut providers,
&mut contexts,
&mut event_writer,
&mut error_writer,
)
})
} else {
Expand Down Expand Up @@ -84,6 +86,7 @@ pub fn script_add_synchronizer<H: ScriptHost + 'static>(
&mut providers,
&mut contexts,
&mut event_writer,
&mut error_writer,
)
}
}
Expand Down Expand Up @@ -120,6 +123,7 @@ pub fn script_hot_reload_handler<H: ScriptHost>(
mut providers: ResMut<APIProviders<H>>,
mut contexts: ResMut<ScriptContexts<H::ScriptContext>>,
mut event_writer: EventWriter<ScriptLoaded>,
mut error_writer: EventWriter<ScriptErrorEvent>,
) {
for e in events.read() {
let (handle, created) = match e {
Expand Down Expand Up @@ -147,6 +151,7 @@ pub fn script_hot_reload_handler<H: ScriptHost>(
&mut providers,
&mut contexts,
&mut event_writer,
&mut error_writer,
);
}
}
Expand Down
Loading