maximegmd / CyberEngineTweaks

Cyberpunk 2077 tweaks, hacks and scripting framework
MIT License
4.48k stars 285 forks source link

Read Access Violation caused by Resource Reference mishandling causes crash #942

Closed Mozz3d closed 1 month ago

Mozz3d commented 5 months ago

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::DynArray Test(Red::ResourceReference& aResRef) { Red::Handle 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)

Zagrthos commented 4 months ago

Can confirm this here. The game crashes here and then with activated CET because of a Memory Access Violation.

htmlboss commented 1 month ago

Same issue here, though the exception the game spits back out isn't clear that CET is the culprit. I can reliably reproduce it when entering Little China by vehicle, on foot, and fast traveling there. After removing CET per the wiki instructions, no more crashing. I plan to narrow this down by reinstalling CET, then bringing back my mods one by one. I'll report back soon.

I've attached some anonymized logs from my system.

stacktrace.txt report.txt metadata.9.json Cyberpunk2077.exe-20240717-235255-10540-10408.txt sysinfo.json