Skip to content

Conversation

@0x617374726F
Copy link
Contributor

Fix runtime panic below by bypassing the borrow checker.

thread '<unnamed>' panicked at ~/Projects/rust/omprs-gdk/omp-gdk/src/scripting/vehicles/events.rs:43:16:
already borrowed: BorrowMutError

You can easily reproduce it by implementing this:

    fn on_player_command_text(&mut self, player: Player, message: String) -> bool {
        if &message == "/spawn" {
            let vehicle = Vehicle::create(411, player.get_pos(), 0.0, -1, -1, -1, false).unwrap();
            player.send_client_message(
                Colour::from_rgba(0xFFFFFFFF),
                &format!("spawned vehicle with id {}", vehicle.get_id()),
            );
            return true;
        }
        if message.starts_with("/destroy ") {
            let id: i32 = message.split_whitespace().nth(1).unwrap().parse().unwrap();
            let vehicle = omp::vehicles::Vehicle::get_from_id(id).unwrap();
            player.send_client_message(
                Colour::from_rgba(0xFFFFFFFF),
                &format!("deleting vehicle with id {id}"),
            );
            vehicle.destroy();
            return true;
        }
        false
    }

Just make sure that the client actually streams in the vehicle before destroying it.

@Sreyas-Sreelal
Copy link
Owner

Thanks a lot!

@Sreyas-Sreelal Sreyas-Sreelal merged commit 34f788d into Sreyas-Sreelal:capi May 18, 2025
0 of 6 checks passed
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.

2 participants