New/Cloned Instances reusing existing RefNum indices
Upon saving an .omwaddon, I've been getting newly created objects disappearing when reloading in CS or OpenMW. I checked out the output in wxHexEditor and have found FRMR blocks with duplicate index numbers in the same CELL record, causing every duplicate but the last to be ignored when the ESMLoader runs.
It appears that CS takes every Cell's word that the number in NAM0 will be higher than any RefNum.mIndex already in use and I assume blindly uses that number when counting up in CSMDoc::WriteCellCollectionStage::perform. Worse, cloning an instance copies the original's index verbatim as well. Presumably both of these are just from the view tables copying data directly and dumping it into CSMWorld::Data without checking for duplicates first.
It would be best I think to flag each new/cloned instance as needing a new cell index and sorting it out at save-time. Would also be a good idea to add this flag when moving an "Added" instance into a different cell.
I've attached an example file from me toying around with some Tamriel Rebuilt assets. The CELL that starts at offset 4755 has a two FRMRs of type "T_MW_DPflora_bertpd01" at offsets 4823 and 6825, each with an index of 3
I'm going to poke around and try to fix this myself, I'll submit a pull request if I can get a simple solution, but I'm not particularly fond of Qt's architecture so digging through slots and signals may take me a while.