Page 1 of 1

[HL2DM] Variant.type crashing

Posted: Tue Nov 17, 2020 3:43 am
by VinciT
Running the following code with an npc_cscanner that's set to hate players (e.g. temp_scanner) causes a crash:

Syntax: Select all

# ../scanner_output/scanner_output.py

# Source.Python
from listeners import OnEntityOutput


@OnEntityOutput
def on_entity_output(output, activator, caller, value, delay):
if 'OnFoundPlayer' in output:
# print(value): <_entities._datamaps.Variant object at 0x1E800228>
print(value.type)
Looking through the HL2SDK, I found that the OnFoundPlayer output is defined as a COutputEHANDLE data type. Seeing as other outputs are defined as COutputEvent, could this difference in type be the cause of the crash?

Re: [HL2DM] Variant.type crashing

Posted: Tue Nov 17, 2020 8:43 am
by L'In20Cible
VinciT wrote:Running the following code with an npc_cscanner that's set to hate players (e.g. temp_scanner) causes a crash:

Syntax: Select all

# ../scanner_output/scanner_output.py

# Source.Python
from listeners import OnEntityOutput


@OnEntityOutput
def on_entity_output(output, activator, caller, value, delay):
if 'OnFoundPlayer' in output:
# print(value): <_entities._datamaps.Variant object at 0x1E800228>
print(value.type)
Looking through the HL2SDK, I found that the OnFoundPlayer output is defined as a COutputEHANDLE data type. Seeing as other outputs are defined as COutputEvent, could this difference in type be the cause of the crash?

The problem is likely the value being invalid and whatever value is retrieved is larger than (1 << 30) causing a crash when FieldType.__str__ is invoked because the internal downcast fails consequently causing a segfault when the enum's name is accessed. This has been an issue with Boost's enum forever, and is one of the main reason why the majority of them are forwarded and wrapped using the Python class. Anyways, you should be able to see the value by casting it as an integer:

Syntax: Select all

print(int(variant.type))

Re: [HL2DM] Variant.type crashing

Posted: Mon Nov 23, 2020 3:27 am
by VinciT
Ah, I see. Thank you for the detailed explanation. It's still crashing after casting it to an integer. The value is most likely invalid, as you pointed out.

I wanted to avoid using my own loop for gathering conditions for the scanner (PlayerIter() -> range check -> line of sight check), but I guess now I'll have to.
Another way could be to mess around with some CAI_Senses functions.. Probably not, we'll see. :tongue:

Re: [HL2DM] Variant.type crashing

Posted: Wed Nov 25, 2020 4:36 am
by L'In20Cible
VinciT wrote:Ah, I see. Thank you for the detailed explanation. It's still crashing after casting it to an integer. The value is most likely invalid, as you pointed out.

Perhaps it's related to something else. The scenario I was referring to was:

Syntax: Select all

from entities.datamaps import FieldType

# CRASH
print(FieldType(1 << 30))

# OK
print(int(FieldType(1 << 30)))

# OK
print(FieldType((1 << 30) - 1))

# OK
class Foo(FieldType):
def __str__(self):
return str(int(self))

print(Foo(1 << 30))


Which should make it okay for you to print as int.

VinciT wrote:I wanted to avoid using my own loop for gathering conditions for the scanner (PlayerIter() -> range check -> line of sight check), but I guess now I'll have to.
Another way could be to mess around with some CAI_Senses functions.. Probably not, we'll see. :tongue:

Since you know it is an entity, does get_entity returns a valid result?

Re: [HL2DM] Variant.type crashing

Posted: Tue Dec 01, 2020 6:25 am
by VinciT
Sorry for taking so long to reply, both int(value.type) and value.get_entity() cause a crash without print() as soon as the output fires.