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

GTA 3 Definitive Edition car spawning freeze #103

Open
Matixk opened this issue Jan 6, 2024 · 4 comments
Open

GTA 3 Definitive Edition car spawning freeze #103

Matixk opened this issue Jan 6, 2024 · 4 comments

Comments

@Matixk
Copy link

Matixk commented Jan 6, 2024

When I spawn a car in async mode then it freezes the whole script:

protected spawnCar(modelId: number) {
        log('spawnCar: loadModel ' + new Date().toTimeString());
        loadModel(modelId);

        log('spawnCar: create car' + new Date().toTimeString());
        // Car.Create this freeze game
        this.currentCar = Car.Create(modelId, this.playerPos.x, this.playerPos.y, this.playerPos.z);
        log('spawnCar: after create car' + new Date().toTimeString());

        log('spawnCar: MarkModelAsNoLongerNeeded ' + new Date().toTimeString());
        Streaming.MarkModelAsNoLongerNeeded(modelId);
        log('spawnCar: end ' + new Date().toTimeString());
    }

I got a stack trace from cleo_redux.log:

21:25:28 [INFO] ["cheat-m"] "spawnCar: loadModel 20:25:28 GMT+0000"
21:25:28 [INFO] ["cheat-m"] "spawnCar: createCar 20:25:28 GMT+0000"
21:25:30 [ERROR] script cheat-m has timed out after the default timeout of 2 seconds
21:25:30 [INFO] LastCommandDebugInfo { name: "CREATE_CAR", input: [Int(105), Float(-1125.0), Float(169.0), Float(60.0)], output: [], if_result: false }
21:25:30 [INFO] Last event: Some(CleoEvent { name: "OnObjectDelete", payload: Some("{\"address\":2333035135664}") })
21:25:30 [INFO] script "cheat-m" has been disposed
21:25:33 [ERROR] script debug has timed out after the default timeout of 2 seconds
21:25:33 [INFO] LastCommandDebugInfo { name: "IS_KEY_PRESSED", input: [Int(17)], output: [], if_result: false }
21:25:33 [INFO] Last event: None
@Matixk Matixk changed the title GTA 3 car spawning freeze GTA 3 Definitive Edition car spawning freeze Jan 6, 2024
@x87
Copy link
Contributor

x87 commented Jan 7, 2024

It may happen if the model (modelId) was not loaded. Can you show loadModel?
also what do you mean as "async mode"? I don't see any async/await keywords in this code.

@Matixk
Copy link
Author

Matixk commented Jan 7, 2024

export const loadModel = (modelId: number) => {
    Streaming.RequestModel(modelId);

    while (!Streaming.HasModelLoaded(modelId)) {
        wait(250);
    }
}

It's ok when it's like:

    while (true) {
        wait(250);

        if (Pad.IsKeyPressed(KeyCode.F1))
           spawnCar(CAR_ID);
    }

but when I use it in an async loop then the game freezes:

(async () => {
    while (true) {
        await asyncWait(250);

        if (Pad.IsKeyPressed(KeyCode.F1))
            spawnCar(CAR_ID);
    }
)();

@x87
Copy link
Contributor

x87 commented Jan 7, 2024

you can't use wait in async scripts. rewrite loadModel to be an async function and use asyncWait


export const loadModel = async (modelId: number) => {
    Streaming.RequestModel(modelId);

    while (!Streaming.HasModelLoaded(modelId)) {
        await asyncWait(250);
    }
}


async function spawnCar(modelId: number) {
    log('spawnCar: loadModel ' + new Date().toTimeString());
    await loadModel(modelId);

    log('spawnCar: create car' + new Date().toTimeString());
    // Car.Create this freeze game
    this.currentCar = Car.Create(modelId, this.playerPos.x, this.playerPos.y, this.playerPos.z);
    log('spawnCar: after create car' + new Date().toTimeString());

    log('spawnCar: MarkModelAsNoLongerNeeded ' + new Date().toTimeString());
    Streaming.MarkModelAsNoLongerNeeded(modelId);
    log('spawnCar: end ' + new Date().toTimeString());
}

(async () => {
    while (true) {
        await asyncWait(250);

        if (Pad.IsKeyPressed(KeyCode.F1))
            await spawnCar(CAR_ID);
    }
)();

@Matixk
Copy link
Author

Matixk commented Jan 8, 2024

Sorry, I've copied the latest script where I've removed all async methods.

I've copied and pasted your code with asyncWait and the problem still occurs:
image

Vice City DE and San Andreas DE works correctly 🤔

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

No branches or pull requests

2 participants