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

Prototype overwrite is broken after resource restart #106

Open
xxshady opened this issue Jan 15, 2022 · 4 comments
Open

Prototype overwrite is broken after resource restart #106

xxshady opened this issue Jan 15, 2022 · 4 comments
Labels
type: bug Something isn't working

Comments

@xxshady
Copy link
Contributor

xxshady commented Jan 15, 2022

Description of the problem

See reproduction steps

Reproduction steps

import * as alt from 'alt-server'

class MyVehicle extends alt.Vehicle {
  test () {
    return true
  }
}

// this breaks the prototype after resource restart
alt.Vehicle.all 

alt.Vehicle.prototype = MyVehicle.prototype

const veh = new alt.Vehicle('sultan2', 10000, 0, 0, 0, 0, 0)

// undefined after resource restart
console.log('veh.test():', veh.test?.())
// false after resource restart
console.log('veh instanceof MyVehicle:', veh instanceof MyVehicle)
// will be false too
console.log('veh instanceof alt.Vehicle:', veh instanceof alt.Vehicle)
// [ Entity {}, Entity {} ] after resource restart
console.log(alt.Vehicle.all)
  1. Restart resource

Expected behaviour

Prototype overwrite should work as usual after each restart

Additional context

Possible workaround

alt.on('resourceStop', () => {
  alt.Vehicle.all.forEach(v => v.destroy())
})

or set prototype explicitly on each object:

alt.Vehicle.all.forEach(v => Object.setPrototypeOf(v, alt.Vehicle.prototype))

Operating system

Windows 10

Version

dev/9.0-dev8

Scope

shared

@xxshady
Copy link
Contributor Author

xxshady commented Jan 24, 2022

I would also like to add that this bug appeared in dev 9.0

@LeonMrBonnie
Copy link
Contributor

Does this happen on both sides?

@xxshady
Copy link
Contributor Author

xxshady commented Mar 16, 2022

as far as i remember - yes

@LeonMrBonnie
Copy link
Contributor

Then this is a problem with the general approach of the system used to define classes inside JS module. And I can already say that won't be reworked any time soon, as it would be way too much work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants