We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1273 - SDL_Init is crashing when called from DLL_main
Summary: SDL_Init is crashing when called from DLL_main
Status: RESOLVED WONTFIX
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 1.2.14
Hardware: x86 Windows (XP)
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-12 05:14 UTC by fojtik
Modified: 2011-12-30 02:08 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description fojtik 2011-08-12 05:14:05 UTC
The code hangs. If I call SDL_Init(SDL_INIT_JOYSTICK) outdide DllMain, It does not crash.

----------------------------------------------------------

SDL_Joystick *joystick;
int JoystickNumAxes;

/** Main Windows .dll initialisation entry point. */
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
  switch(fdwReason)
  {
    case DLL_PROCESS_ATTACH:
		{
	        if(SDL_Init(SDL_INIT_JOYSTICK)==0)
	        {
	          joystick = SDL_JoystickOpen(0);
		  JoystickNumAxes = SDL_JoystickNumAxes(joystick);
		}
		else
		  joystick = NULL;
		break;
		}
    case DLL_PROCESS_DETACH:		
	        if (joystick) 
                {
		   SDL_JoystickClose(joystick);	
		   joystick = NULL;
		}  //numAxes = numButtons = numHats = numTrackballs = 0;		
		break;
	
    //case DLL_THREAD_ATTACH:
    //case DLL_THREAD_DETACH:
  }
  return TRUE;
}
Comment 1 Sam Lantinga 2011-12-29 01:46:01 UTC
I suspect there's some problems on Windows with loading DLLs while a DLL is being loaded.
Comment 2 fojtik 2011-12-30 02:08:41 UTC
I have finally used native Windows joystick calls and do not use this library.

There is no other place to initialise joystick, only dll_main is available. 

The resulting DLL is intended to be a plugin for Matlab.