Create/CloneCommand can reuse refNums, causing severe issues in-game
Originally described as an example suite in #7530 (closed)
Unfortunately, this problem is not exclusive to the example suite and can occur when adding or deleting references in OpenCS, regardless of the original plugin.
In MWWorld::PtrRegistry, the engine proper tracks the highest assigned refNum and progressively increments it as new references are created. I think a similar measure will ultimately be necessary to resolve this in the construction set.
There are multiple instances in which this can occur, since it has potential to happen any time that a reference is created. Deleting references especially is prone to cause this issue.
One of the easiest ways to reproduce this issue is as follows:
- Create a new plugin, make Morrowind.esm a master of that plugin
- Open an existing cell
- Place three instances of the same object
- Delete the second one
- Place a instance of a different thing
- Launch from the CS in testing mode
You will now find that the third reference is either replaced by or has replaced the second. I forget which, tbh.
Best place to start appears to be in refCollection.cpp, as it appears to already use the mNextId field for a similar purpose during loading.