Skip to content

Commit 1728491

Browse files
author
L'In20Cible
committed
Fixed TempEntity[Pre/Post]Hook from raising on unload if they failed to initialize.
1 parent 96ffc9c commit 1728491

File tree

1 file changed

+15
-4
lines changed
  • addons/source-python/packages/source-python/effects

1 file changed

+15
-4
lines changed

addons/source-python/packages/source-python/effects/hooks.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,20 @@ def __init__(self, temp_entity_name):
4141
# Store the given temp entity name...
4242
self.name = temp_entity_name
4343

44-
# Store the function to hook...
45-
self.function = get_virtual_function(
46-
temp_entity_templates[temp_entity_name], 'Create')
47-
4844
# Set the callback to None...
4945
self._callback = None
5046

47+
try:
48+
# Store the function to hook...
49+
self.function = get_virtual_function(
50+
temp_entity_templates[temp_entity_name], 'Create')
51+
except NameError:
52+
# Given name was invalid, set the function to None...
53+
self.function = None
54+
55+
# Re-raise the error...
56+
raise
57+
5158
def __call__(self, callback):
5259
"""Store the callback and try initialize the hook."""
5360
def _callback(stack_data, *args):
@@ -78,6 +85,10 @@ def hook_type(self):
7885

7986
def _unload_instance(self):
8087
"""Unload the hook."""
88+
# Was no hook registered?
89+
if self.function is None or self._callback is None:
90+
return
91+
8192
# Unregister the hook...
8293
self.function.remove_hook(self.hook_type, self._callback)
8394

0 commit comments

Comments
 (0)