HomeWildfire Games

Fix entities being able to attack allied structures in rare cases.

Description

Fix entities being able to attack allied structures in rare cases.

Caused by not checking the attack type while performing an attack.

Closes: #5511
Differential revision: D3840
References #3484

Event Timeline

Langbart raised a concern with this commit.Apr 12 2021, 5:55 PM
Langbart added a subscriber: Langbart.

Beginning with this changeset I get a segmentation fault, when starting a match.

Process 13459 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x7ffeef3ffe98)
    frame #0: 0x000000010015c804 pyrogenesis`void ScriptInterface::ToJSVal<IComponent*>(rq=0x00007ffeef4001a0, ret=JS::MutableHandleValue @ r15, val=0x00007ffeef400198) at EngineScriptConversions.cpp:46:39 [opt]
   43  		}
   44  	
   45  		// If this is a scripted component, just return the JS object directly
-> 46  		JS::RootedValue instance(rq.cx, val->GetJSInstance());
   47  		if (!instance.isNull())
   48  		{
   49  			ret.set(instance);
Target 0: (pyrogenesis) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x7ffeef3ffe98)
  * frame #0: 0x000000010015c804 pyrogenesis`void ScriptInterface::ToJSVal<IComponent*>(rq=0x00007ffeef4001a0, ret=JS::MutableHandleValue @ r15, val=0x00007ffeef400198) at EngineScriptConversions.cpp:46:39 [opt]
    frame #1: 0x000000010018e0a4 pyrogenesis`bool ScriptFunction::ToJSNative<&(CComponentManager::QueryInterface(unsigned int, int) const), &(CComponentManager* ScriptFunction::ObjectFromCBData<CComponentManager>(ScriptRequest const&, JS::CallArgs&))>(cx=<unavailable>, argc=<unavailable>, vp=0x00007ffeef400238) at FunctionWrapper.h:277:4 [opt]
    frame #2: 0x00000cef028ddcfc
    frame #3: 0x0000000100ea66b0 pyrogenesis`js::jit::MaybeEnterJit(JSContext*, js::RunState&) at Jit.cpp:105:5 [opt]
    frame #4: 0x0000000100ea6446 pyrogenesis`js::jit::MaybeEnterJit(cx=0x000000010583d600, state=0x0000000000002043) at Jit.cpp:196 [opt]
    frame #5: 0x0000000100767479 pyrogenesis`js::RunScript(cx=0x000000010583d600, state=0x00007ffeef400550) at Interpreter.cpp:450:32 [opt]
    frame #6: 0x00000001007771f4 pyrogenesis`js::InternalCallOrConstruct(cx=0x000000010583d600, args=<unavailable>, construct=<unavailable>, reason=<unavailable>) at Interpreter.cpp:620:13 [opt]
    frame #7: 0x00000001007775f6 pyrogenesis`InternalCall(cx=<unavailable>, args=<unavailable>, reason=<unavailable>) at Interpreter.cpp:648:10 [opt] [artificial]
    frame #8: 0x0000000100777629 pyrogenesis`js::Call(cx=0x000000010583d600, fval=<unavailable>, thisv=JS::HandleValue @ scalar, args=0x00007ffeef4005f8, rval=JS::MutableHandleValue @ r14, reason=<unavailable>) at Interpreter.cpp:665:8 [opt]
    frame #9: 0x0000000100880e04 pyrogenesis`js::fun_call(cx=0x000000010583d600, argc=1, vp=0x00007ffeef400c08) at JSFunction.cpp:1132:10 [opt]
    frame #10: 0x00000001008811fc pyrogenesis`js::fun_apply(cx=0x000000010583d600, argc=1, vp=0x00007ffeef400c08) at JSFunction.cpp:1152:12 [opt]
(lldb)
This commit now has outstanding concerns.Apr 12 2021, 5:55 PM

To reproduce: start Acropolis Bay skirmish map with an AI.

This stack trace looks identical to infinite loop stack traces that we've had recently.

Reverted in rP25246.

A quick investigation leads me to conclude that the "wantedType" being "Slaughter" caused an infinite loop in UnitAI's gather/hunting logic (as usual). I am not very familiar with the wanted type code, so I'll let Freagarach handle it

Freagarach requested verification of this commit.Apr 13 2021, 6:33 AM

(Since it has been reverted.)

This commit now requires verification by auditors.Apr 13 2021, 6:33 AM
Langbart resigned from this commit.Apr 13 2021, 9:38 PM
This commit no longer requires audit.Apr 13 2021, 9:38 PM