Fix memory leak with events
This commit is contained in:
@@ -132,36 +132,40 @@ namespace OpenVulkano
|
||||
|
||||
void NamedEventProcessor::Notify(const std::string& eventName, const std::vector<Parameters>& parameters) const
|
||||
{
|
||||
if (Class eventClass = FindGenericEventClass(m_classNamePrefixes, m_classNameSuffixes, eventName))
|
||||
@autoreleasepool
|
||||
{
|
||||
if (SEL init = GetInitForClass(eventClass, BuildTypeName(parameters)))
|
||||
if (Class eventClass = FindGenericEventClass(m_classNamePrefixes, m_classNameSuffixes, eventName))
|
||||
{
|
||||
NSObject* event = [eventClass alloc];
|
||||
auto inv = [NSInvocation invocationWithMethodSignature:[event methodSignatureForSelector:init]];
|
||||
[inv setTarget:event];
|
||||
[inv setSelector:init];
|
||||
for (int i = 0; i < parameters.size(); i++)
|
||||
if (SEL init = GetInitForClass(eventClass, BuildTypeName(parameters)))
|
||||
{
|
||||
auto arg = std::visit([](auto&& arg) { return CreateValue(arg); }, parameters[i]);
|
||||
[inv setArgument:&arg atIndex:(i + 2)];
|
||||
NSObject* event = [eventClass alloc];
|
||||
auto inv = [NSInvocation invocationWithMethodSignature:[event methodSignatureForSelector:init]];
|
||||
[inv setTarget:event];
|
||||
[inv setSelector:init];
|
||||
for (int i = 0; i < parameters.size(); i++)
|
||||
{
|
||||
auto arg = std::visit([](auto&& arg) { return CreateValue(arg); }, parameters[i]);
|
||||
[inv setArgument:&arg atIndex:(i + 2)];
|
||||
}
|
||||
[inv invoke];
|
||||
for (Class clazz = eventClass; clazz && clazz != NSObject.class; clazz = class_getSuperclass(clazz))
|
||||
{
|
||||
NSString* notificationName;
|
||||
if (m_useClassNameAsEventName) notificationName = NSStringFromClass(clazz);
|
||||
else notificationName = [NSString stringWithUTF8String:eventName.c_str()];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:event userInfo:nil];
|
||||
}
|
||||
[event release];
|
||||
}
|
||||
[inv invoke];
|
||||
for (Class clazz = eventClass; clazz && clazz != NSObject.class; clazz = class_getSuperclass(clazz))
|
||||
else
|
||||
{
|
||||
NSString* notificationName;
|
||||
if (m_useClassNameAsEventName) notificationName = NSStringFromClass(clazz);
|
||||
else notificationName = [NSString stringWithUTF8String:eventName.c_str()];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:event userInfo:nil];
|
||||
Logger::MANAGER->error("Cannot find constructor for named event %s", eventName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::MANAGER->error("Cannot find constructor for named event %s", eventName);
|
||||
Logger::MANAGER->debug("Cannot find implementation for named event %s", eventName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::MANAGER->debug("Cannot find implementation for named event %s", eventName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user