fix(scripting): use onResourceStop for exports cache clearing#3785
Open
D4isDAVID wants to merge 1 commit intocitizenfx:masterfrom
Open
fix(scripting): use onResourceStop for exports cache clearing#3785D4isDAVID wants to merge 1 commit intocitizenfx:masterfrom
onResourceStop for exports cache clearing#3785D4isDAVID wants to merge 1 commit intocitizenfx:masterfrom
Conversation
f1793fe to
6b5b174
Compare
6b5b174 to
b535158
Compare
onResourceStart for exports cache clearingonResourceStart for exports cache clearing
| on(`on${eventType}ResourceStop`, (resource) => { | ||
| // clear cache with onResourceStop to not break cached exports for onResourceStart | ||
| on('onResourceStop', (resource) => { | ||
| exportsCallbackCache[resource] = {}; |
Contributor
|
Nitpick but you might want to fix the title by replacing onResourceStart by onResourceStop, this got me confused at first 😄 |
Contributor
Author
|
Ah, my bad |
onResourceStart for exports cache clearingonResourceStop for exports cache clearing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal of this PR
Fix exports not working for resources when listening to
onResourceStopand restarting.For example, I have a resource

Athat provides an export, and resourceBthat wants to run the export immediately when resourceAstarts. This would work at first; the exports cache is still empty, so resourceBcan request the export from resourceA. However, if I restart resourceA, resourceBstill has the old export cached, which would now have an invalid function reference, as resourceAhas been stopped, resulting in an error like this:How is this PR achieving the goal
This PR changes the
scheduler.luaandmain.jsto useonResourceStopinstead ofonClientResourceStop/onServerResourceStopto clear the cache, to prevent delaying the cache clearing until afteronResourceStart. C# doesn't seem to cache exports like this, so no changes were made there, as the error does not occur.This PR applies to the following area(s)
ScRT: Lua, ScRT: JS
Successfully tested on
Platforms: Windows
Checklist