Panic: if `get_resource` is called (provides None if missing), then `init_resource`, get a panic
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 30/100
Direzione di ricerca
Start by reading the shown get and init_resource implementations, then inspect contains and the resource map behavior to confirm how an empty entry is represented. Update the check so init_resource initializes when the resource has no value, and add or run a regression test for calling get_resource before init_resource to verify it no longer panics.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
world.get_resource does this:
#[track_caller]
pub fn get<T: HasSchema>(&self) -> Option<Ref<T>> {
let b = self.untyped.get(T::schema()).borrow();
if b.is_some() {
Some(Ref::map(b, |b| unsafe {
b.as_ref().unwrap().as_ref().cast_into_unchecked()
}))
} else {
None
}
}
self.untyped.get() This inserts the the schema id into OnceMap, with contents being empty.
init_resource does:
pub fn init_resource<R: HasSchema + FromWorld>(&mut self) -> RefMut<R> {
if unlikely(!self.resources.contains::<R>()) {
let value = R::from_world(self);
self.resources.insert(value);
}
self.resource_mut()
}
and contains only checks if ID is contained - not if resource has a value. This skips the init branch, and only calls self.resource_mut which panics on missing resource value.
This is the only place in bones that contains is used, I think we should update this to check if the resource has a value, and not just ID entry in map. This is what I would expect when using the function as well.
- Lingua principale
- Rust
- Stelle
- 314
- Fork
- 26
- Merge medio
- 1g 23h
- PR unite (30g)
- 1
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di fishfolk/bones
-
code:todo
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
-
add tests for EntityGridMapApertacode:todo
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
code:todo
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
code:todo
Difficoltà 3/5 Mezza giornata Idoneità per principianti 48/100
-
code:todo
Difficoltà 3/5 1-2 giorni Idoneità per principianti 67/100
Tutte le issue di fishfolk/bones
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
wormhole-foundation/wormhole#5062 ·
I maintainer di solito rispondono entro 1 giorno
-
RUSTSEC-2026-0348: Brotli certificate decompression can allocate up to 1 GiB before authenticationAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 60/100
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 62/100
-
core: Amount::from_str panics on values above 21M BTC instead of returning an errorForse già presa @bhuvan-somisetty l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
crate: spate-s3
Difficoltà 2/5 Mezza giornata Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno