CyberEngineTweaks
CyberEngineTweaks copied to clipboard
Read Access Violation caused by Resource Reference mishandling causes crash
Operating system: Windows 10 Game version: 2.12a CET version: 1.32.0 GPU: GeForce RTX 3060
Description
Quoting psiberx, "when accessing res ref, cet makes a copy but doesn't increment the reference counter after passing res ref to a function, cet destroys invalid/unaccounted copies and decrements the reference counter when the counter goes to zero, the resource is freed and all res refs to the same resource are invalidated."
"CET just doesn't have a special lua wrapper to handle res refs right. It uses generic UnknownType wrapper that just copies memory." This leads to a read access violation that crashes the game when attempting to read or write to a resource multiple times, as handles are not properly destroyed.
Reproduction
Calling a method that is passed a ResourceReference multiple times will crash the game.
C++ struct TestClass { static Red::DynArrayRed::CName Test(Red::ResourceReferenceRed::anim::Rig& aResRef) { Red::HandleRed::anim::Rig rigHandle = aResRef.Get(); return rigHandle->boneNames; } } RTTI_DEFINE_CLASS(TestClass, { RTTI_METHOD(Test); });
Lua registerForEvent("onUpdate", function() player = Game.GetPlayer() deformations = ComponentParser.getComponent(player, 'deformations') --returns component by name from player ent boneNames = TestClass.Test(deformations.rig) end)