Skip to content

feat: improve errors when entity is unavailable #410

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

Merged
merged 3 commits into from
Apr 5, 2025

Conversation

makspll
Copy link
Owner

@makspll makspll commented Apr 5, 2025

Summary

Many places in BMS use Entity::from_raw(0) as an invalid entity, because that index is not naturally assigned to any entity in Bevy.

When an entity is not available in a callback, i.e. on_script_loaded people often try to interact with the entity global, this PR makes it so that using those entities, will throw a more meaningful error and point people to this fact.

Also fixes minor newline issue in docs

Copy link
Contributor

github-actions bot commented Apr 5, 2025

🐰 Bencher Report

Branchfeat/better-entity-errors
Testbedlinux-gha
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
nanoseconds (ns)
(Result Δ%)
Upper Boundary
nanoseconds (ns)
(Limit %)
component/access Lua📈 view plot
🚷 view threshold
3,414.80 ns
(-30.38%)Baseline: 4,904.69 ns
6,382.88 ns
(53.50%)
component/access Rhai📈 view plot
🚷 view threshold
5,707.20 ns
(-15.63%)Baseline: 6,764.87 ns
8,025.00 ns
(71.12%)
component/get Lua📈 view plot
🚷 view threshold
2,040.10 ns
(-29.20%)Baseline: 2,881.61 ns
3,588.65 ns
(56.85%)
component/get Rhai📈 view plot
🚷 view threshold
4,443.00 ns
(-10.22%)Baseline: 4,948.98 ns
6,020.58 ns
(73.80%)
conversions/Mut::from📈 view plot
🚷 view threshold
80.03 ns
(-40.86%)Baseline: 135.32 ns
247.94 ns
(32.28%)
conversions/Ref::from📈 view plot
🚷 view threshold
79.12 ns
(-40.62%)Baseline: 133.25 ns
245.65 ns
(32.21%)
conversions/ScriptValue::List📈 view plot
🚷 view threshold
260.66 ns
(-58.55%)Baseline: 628.82 ns
1,114.00 ns
(23.40%)
conversions/ScriptValue::Map📈 view plot
🚷 view threshold
1,233.20 ns
(-25.71%)Baseline: 1,660.03 ns
2,219.37 ns
(55.57%)
conversions/ScriptValue::Reference::from_into📈 view plot
🚷 view threshold
25.01 ns
(-38.64%)Baseline: 40.76 ns
58.69 ns
(42.61%)
conversions/Val::from_into📈 view plot
🚷 view threshold
212.72 ns
(-37.21%)Baseline: 338.78 ns
465.06 ns
(45.74%)
function/call 4 args Lua📈 view plot
🚷 view threshold
1,659.40 ns
(-20.85%)Baseline: 2,096.44 ns
2,515.75 ns
(65.96%)
function/call 4 args Rhai📈 view plot
🚷 view threshold
1,450.40 ns
(-20.19%)Baseline: 1,817.36 ns
2,213.77 ns
(65.52%)
function/call Lua📈 view plot
🚷 view threshold
227.54 ns
(-18.73%)Baseline: 279.96 ns
336.75 ns
(67.57%)
function/call Rhai📈 view plot
🚷 view threshold
448.51 ns
(-15.35%)Baseline: 529.87 ns
664.33 ns
(67.51%)
math/vec mat ops Lua📈 view plot
🚷 view threshold
5,983.50 ns
(-23.03%)Baseline: 7,774.27 ns
9,307.29 ns
(64.29%)
math/vec mat ops Rhai📈 view plot
🚷 view threshold
5,785.80 ns
(-22.34%)Baseline: 7,450.54 ns
8,647.21 ns
(66.91%)
query/10 entities Lua📈 view plot
🚷 view threshold
17,951.00 ns
(-27.33%)Baseline: 24,702.12 ns
30,757.33 ns
(58.36%)
query/10 entities Rhai📈 view plot
🚷 view threshold
19,860.00 ns
(-18.48%)Baseline: 24,362.53 ns
28,815.47 ns
(68.92%)
query/100 entities Lua📈 view plot
🚷 view threshold
38,669.00 ns
(-22.60%)Baseline: 49,962.59 ns
61,449.55 ns
(62.93%)
query/100 entities Rhai📈 view plot
🚷 view threshold
29,698.00 ns
(-24.16%)Baseline: 39,159.35 ns
48,132.14 ns
(61.70%)
query/1000 entities Lua📈 view plot
🚷 view threshold
252,460.00 ns
(-19.29%)Baseline: 312,780.59 ns
385,749.00 ns
(65.45%)
query/1000 entities Rhai📈 view plot
🚷 view threshold
159,140.00 ns
(-27.84%)Baseline: 220,545.59 ns
300,234.48 ns
(53.01%)
reflection/10 Lua📈 view plot
🚷 view threshold
5,559.10 ns
(-15.29%)Baseline: 6,562.77 ns
7,568.86 ns
(73.45%)
reflection/10 Rhai📈 view plot
🚷 view threshold
14,866.00 ns
(-9.61%)Baseline: 16,446.68 ns
18,023.75 ns
(82.48%)
reflection/100 Lua📈 view plot
🚷 view threshold
47,372.00 ns
(-11.58%)Baseline: 53,578.06 ns
60,456.54 ns
(78.36%)
reflection/100 Rhai📈 view plot
🚷 view threshold
721,470.00 ns
(-2.28%)Baseline: 738,277.94 ns
871,654.45 ns
(82.77%)
resource/access Lua📈 view plot
🚷 view threshold
3,009.80 ns
(-30.25%)Baseline: 4,315.15 ns
5,549.45 ns
(54.24%)
resource/access Rhai📈 view plot
🚷 view threshold
5,018.50 ns
(-17.00%)Baseline: 6,046.35 ns
7,452.39 ns
(67.34%)
resource/get Lua📈 view plot
🚷 view threshold
1,685.00 ns
(-29.79%)Baseline: 2,399.81 ns
3,034.45 ns
(55.53%)
resource/get Rhai📈 view plot
🚷 view threshold
3,733.10 ns
(-13.05%)Baseline: 4,293.55 ns
5,336.37 ns
(69.96%)
🐰 View full continuous benchmarking report in Bencher

@makspll makspll merged commit 1077d48 into main Apr 5, 2025
19 checks passed
@makspll makspll deleted the feat/better-entity-errors branch April 5, 2025 17:18
@github-actions github-actions bot mentioned this pull request Apr 4, 2025
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

Successfully merging this pull request may close these issues.

1 participant