View Single Post
Author Message
Miu
Veteran Member
Join Date: Nov 2013
Old 03-22-2015 , 19:48   Creating threads
Reply With Quote #1

I'm trying to make a sourcemod extension to create a thread to execute any given plugin function with the simple code:

Code:
DWORD WINAPI thr(LPVOID param)
{
	((IPluginFunction *)param)->CallFunction(0, 0, 0);
	return 0;
}

cell_t CreateThreadNative(IPluginContext *pContext, const cell_t *params)
{
	IPluginFunction *pfn = pContext->GetFunctionById(params[1]);
	CreateThread(0, 0, thr, pfn, 0, 0);
	return 0;
}
Testing this on arbitrary functions in a plugin seemingly works fine on some functions, gives the unclear "Plugin encountered error 17: Stack memory leaked by native" other times, and completely crashes the server other times again. Sourcemod can also no longer unload the plugin.

I'm not sure why the code I wrote causes this erratic behavior. Any help?
Miu is offline