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
|
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];
|
if (SEL init = GetInitForClass(eventClass, BuildTypeName(parameters)))
|
||||||
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]);
|
NSObject* event = [eventClass alloc];
|
||||||
[inv setArgument:&arg atIndex:(i + 2)];
|
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];
|
else
|
||||||
for (Class clazz = eventClass; clazz && clazz != NSObject.class; clazz = class_getSuperclass(clazz))
|
|
||||||
{
|
{
|
||||||
NSString* notificationName;
|
Logger::MANAGER->error("Cannot find constructor for named event %s", eventName);
|
||||||
if (m_useClassNameAsEventName) notificationName = NSStringFromClass(clazz);
|
|
||||||
else notificationName = [NSString stringWithUTF8String:eventName.c_str()];
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:event userInfo:nil];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
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