Skip to content

Conversation

@Septirage
Copy link
Contributor

When a script calls a ScriptParameter-related function (ClearScriptParams, AddScriptParametersXXX, or ExecuteScriptEnhanced with bClearParams = true), the game tries to inspect the parameters buffer, delete all parameters in it, and free the buffer.

Currently, if a script called by our internal ExecuteScriptEnhanced uses one of those functions, the game crashes because NWN2 cannot manage the std::vector memory used.

The changes here:

  • Allocate NWN2 heap-managed memory that can be properly freed by nwn2server
  • Use NWN2's expected buffer layout: [int32_t count][NWN2Param array], where the list pointer points to the array but NWN2 reads the count at pointer-4
  • Set this "parameter count" to 0, so if deletion occurs, the game won't try to free individual string parameters and will only delete the container
  • Always call "CleanHeapParams" at the end to free this container and any memory that may have been allocated by script calls

This fixes crashes when scripts use parameter management functions within ExecuteScriptEnhanced.

- properly set the maxSize value on the NWN2ParamsList
- create a NWN2Heap managed memory buffer for parameters
- Add the "number of parameters" bytes at the start of the paramBuffer and set it to 0 to avoid deep delete.
- Properly call the CleanParameters at the end of execution.
@Septirage Septirage force-pushed the fix/ImbricatedExecuteScript branch from 6ff2d4e to 620ca71 Compare August 23, 2025 01:44
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.

1 participant