[HL2DM] Variant.type crashing

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

[HL2DM] Variant.type crashing

Postby VinciT » Tue Nov 17, 2020 3:43 am

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?
ImageImageImageImageImage
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [HL2DM] Variant.type crashing

Postby L'In20Cible » Tue Nov 17, 2020 8:43 am

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))
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: [HL2DM] Variant.type crashing

Postby VinciT » Mon Nov 23, 2020 3:27 am

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:
ImageImageImageImageImage
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [HL2DM] Variant.type crashing

Postby L'In20Cible » Wed Nov 25, 2020 4:36 am

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?
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: [HL2DM] Variant.type crashing

Postby VinciT » Tue Dec 01, 2020 6:25 am

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.
ImageImageImageImageImage

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 34 guests