Skip to content

fix(scripting): use onResourceStop for exports cache clearing#3785

Open
D4isDAVID wants to merge 1 commit intocitizenfx:masterfrom
D4isDAVID:exports-cache-onResourceStart
Open

fix(scripting): use onResourceStop for exports cache clearing#3785
D4isDAVID wants to merge 1 commit intocitizenfx:masterfrom
D4isDAVID:exports-cache-onResourceStart

Conversation

@D4isDAVID
Copy link
Contributor

Goal of this PR

Fix exports not working for resources when listening to onResourceStop and restarting.

For example, I have a resource A that provides an export, and resource B that wants to run the export immediately when resource A starts. This would work at first; the exports cache is still empty, so resource B can request the export from resource A. However, if I restart resource A, resource B still has the old export cached, which would now have an invalid function reference, as resource A has been stopped, resulting in an error like this:
image

How is this PR achieving the goal

This PR changes the scheduler.lua and main.js to use onResourceStop instead of onClientResourceStop/onServerResourceStop to clear the cache, to prevent delaying the cache clearing until after onResourceStart. 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

  • Code compiles and has been tested successfully.
  • Code explains itself well and/or is documented.
  • My commit message explains what the changes do and what they are for.
  • No extra compilation warnings are added by these changes.

@github-actions github-actions bot added ScRT: JS Issues/PRs related to the JavaScript scripting runtime ScRT: Lua Issues/PRs related to the Lua scripting runtime triage Needs a preliminary assessment to determine the urgency and required action labels Jan 18, 2026
@D4isDAVID D4isDAVID force-pushed the exports-cache-onResourceStart branch from f1793fe to 6b5b174 Compare January 18, 2026 14:41
@D4isDAVID D4isDAVID force-pushed the exports-cache-onResourceStart branch from 6b5b174 to b535158 Compare January 19, 2026 04:10
@D4isDAVID D4isDAVID changed the title fix(scheduler): use onResourceStart for exports cache clearing fix(scripting): use onResourceStart for exports cache clearing Jan 19, 2026
on(`on${eventType}ResourceStop`, (resource) => {
// clear cache with onResourceStop to not break cached exports for onResourceStart
on('onResourceStop', (resource) => {
exportsCallbackCache[resource] = {};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

albena

@Mathu-lmn
Copy link
Contributor

Nitpick but you might want to fix the title by replacing onResourceStart by onResourceStop, this got me confused at first 😄

@D4isDAVID
Copy link
Contributor Author

Ah, my bad

@D4isDAVID D4isDAVID changed the title fix(scripting): use onResourceStart for exports cache clearing fix(scripting): use onResourceStop for exports cache clearing Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ScRT: JS Issues/PRs related to the JavaScript scripting runtime ScRT: Lua Issues/PRs related to the Lua scripting runtime triage Needs a preliminary assessment to determine the urgency and required action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants