Skip to content

Commit dcf227f

Browse files
committed
Stop initializing the memory manager twice on startup.
Fix the crash when launching a second instance. Timestamp injected gamepad events so key repeat works. Ignore gamepad input while the window is unfocused. Let the window actually resize to the chosen resolution.
1 parent 3245114 commit dcf227f

6 files changed

Lines changed: 19 additions & 81 deletions

File tree

Core/GameEngineDevice/Source/SDL3Device/GameClient/SDL3Input.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,7 @@ void SDL3InputManager::virtualPulseKey(SDL_Scancode scancode, bool down)
931931
SDL_Event keyEvent;
932932
memset(&keyEvent, 0, sizeof(keyEvent));
933933
keyEvent.type = down ? SDL_EVENT_KEY_DOWN : SDL_EVENT_KEY_UP;
934+
keyEvent.common.timestamp = SDL_GetTicksNS();
934935
keyEvent.key.scancode = scancode;
935936
keyEvent.key.down = down;
936937

@@ -952,6 +953,7 @@ void SDL3InputManager::virtualPulseMouse(Uint8 button, bool down)
952953
SDL_Event clickEvent;
953954
memset(&clickEvent, 0, sizeof(clickEvent));
954955
clickEvent.type = down ? SDL_EVENT_MOUSE_BUTTON_DOWN : SDL_EVENT_MOUSE_BUTTON_UP;
956+
clickEvent.common.timestamp = SDL_GetTicksNS();
955957
clickEvent.button.button = button;
956958

957959
int buttonIdx = (button == SDL_BUTTON_LEFT) ? 0 : ((button == SDL_BUTTON_RIGHT) ? 1 : 2);
@@ -997,6 +999,19 @@ void SDL3InputManager::processGamepadInput()
997999
if (!m_gamepad)
9981000
return;
9991001

1002+
if (m_window && !(SDL_GetWindowFlags(m_window) & SDL_WINDOW_INPUT_FOCUS))
1003+
{
1004+
m_state = GamepadState();
1005+
m_lastUpdateTime = 0;
1006+
m_cursorSpeed = 0.0f;
1007+
m_edgeAccelTimer = 0.0f;
1008+
m_cursorRemainderX = 0.0f;
1009+
m_cursorRemainderY = 0.0f;
1010+
if (TheLookAtTranslator)
1011+
TheLookAtTranslator->setControllerInputActive(false);
1012+
return;
1013+
}
1014+
10001015
const float DEADZONE = DEFAULT_DEADZONE;
10011016
float rx = SDL_GetGamepadAxis(m_gamepad, SDL_GAMEPAD_AXIS_RIGHTX) / AXIS_MAX;
10021017
float ry = SDL_GetGamepadAxis(m_gamepad, SDL_GAMEPAD_AXIS_RIGHTY) / AXIS_MAX;
@@ -1110,6 +1125,7 @@ void SDL3InputManager::processGamepadInput()
11101125
SDL_Event motionEvent;
11111126
memset(&motionEvent, 0, sizeof(motionEvent));
11121127
motionEvent.type = SDL_EVENT_MOUSE_MOTION;
1128+
motionEvent.common.timestamp = SDL_GetTicksNS();
11131129
motionEvent.motion.xrel = (float)cursorDeltaX;
11141130
motionEvent.motion.yrel = (float)cursorDeltaY;
11151131

Core/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ void DX8Wrapper::Resize_And_Position_Window()
894894
// Resize the window to fit this resolution
895895
if (!IsWindowed)
896896
{
897-
::SetWindowPos(_Hwnd, HWND_TOPMOST, 0, 0, width, height, 0);
897+
::SetWindowPos(_Hwnd, HWND_TOPMOST, 0, 0, width, height, SWP_NOSENDCHANGING);
898898

899899
DEBUG_LOG(("Window resized to w:%d h:%d", width, height));
900900
}
@@ -917,7 +917,7 @@ void DX8Wrapper::Resize_And_Position_Window()
917917
rectClient.bottom = rectClient.top + ResolutionHeight;
918918
MoveRectIntoOtherRect(rectClient, mi.rcMonitor, &left, &top);
919919

920-
::SetWindowPos (_Hwnd, nullptr, left, top, width, height, SWP_NOZORDER);
920+
::SetWindowPos (_Hwnd, nullptr, left, top, width, height, SWP_NOZORDER | SWP_NOSENDCHANGING);
921921

922922
DEBUG_LOG(("Window positioned to x:%d y:%d, resized to w:%d h:%d", left, top, width, height));
923923
}

Core/Main/AppMain.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ Bool initAfterWindow()
113113
DEBUG_LOG(("Generals is already running...Bail!"));
114114
delete TheVersion;
115115
TheVersion = nullptr;
116-
shutdownMemoryManager();
117116
return false;
118117
}
119118
DEBUG_LOG(("Create Generals Mutex okay."));

Core/Main/SDL3Main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ int main(int argc, char* argv[])
131131
TheSDL3Window = nullptr;
132132
}
133133
SDL_Quit();
134+
AppMain::shutdown();
134135
return exitcode;
135136
}
136137

Generals/Code/Main/WinMain.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -767,9 +767,6 @@ static Bool initializeAppWindows( HINSTANCE hInstance, Int nCmdShow, Bool runWin
767767

768768
}
769769

770-
// Necessary to allow memory managers and such to have useful critical sections
771-
static CriticalSection critSec1, critSec2, critSec3, critSec4, critSec5;
772-
773770
// UnHandledExceptionFilter ===================================================
774771
/** Handler for unhandled win32 exceptions. */
775772
//=============================================================================
@@ -799,42 +796,6 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
799796
try {
800797

801798
SetUnhandledExceptionFilter( UnHandledExceptionFilter );
802-
//
803-
// there is something about checkin in and out the .dsp and .dsw files
804-
// that blows the working directory information away on each of the
805-
// developers machines so we're going to hack it for a while and set our
806-
// working directory to the directory with the .exe since that's not the
807-
// default in a DevStudio project
808-
//
809-
810-
TheAsciiStringCriticalSection = &critSec1;
811-
TheUnicodeStringCriticalSection = &critSec2;
812-
TheDmaCriticalSection = &critSec3;
813-
TheMemoryPoolCriticalSection = &critSec4;
814-
TheDebugLogCriticalSection = &critSec5;
815-
816-
// initialize the memory manager early
817-
initMemoryManager();
818-
819-
/// @todo remove this force set of working directory later
820-
Char buffer[ _MAX_PATH ];
821-
GetModuleFileName( nullptr, buffer, sizeof( buffer ) );
822-
if (Char *pEnd = strrchr(buffer, '\\'))
823-
{
824-
*pEnd = 0;
825-
}
826-
::SetCurrentDirectory(buffer);
827-
828-
829-
#ifdef RTS_DEBUG
830-
// Turn on Memory heap tracking
831-
int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
832-
tmpFlag |= (_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
833-
tmpFlag &= ~_CRTDBG_CHECK_CRT_DF;
834-
_CrtSetDbgFlag( tmpFlag );
835-
#endif
836-
837-
838799

839800
// install debug callbacks
840801
// WWDebug_Install_Message_Handler(WWDebug_Message_Callback);

GeneralsMD/Code/Main/WinMain.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,6 @@ static Bool initializeAppWindows( HINSTANCE hInstance, Int nCmdShow, Bool runWin
773773

774774
}
775775

776-
// Necessary to allow memory managers and such to have useful critical sections
777-
static CriticalSection critSec1, critSec2, critSec3, critSec4, critSec5;
778-
779776
// UnHandledExceptionFilter ===================================================
780777
/** Handler for unhandled win32 exceptions. */
781778
//=============================================================================
@@ -810,42 +807,6 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
810807
try {
811808

812809
SetUnhandledExceptionFilter( UnHandledExceptionFilter );
813-
//
814-
// there is something about checkin in and out the .dsp and .dsw files
815-
// that blows the working directory information away on each of the
816-
// developers machines so we're going to hack it for a while and set our
817-
// working directory to the directory with the .exe since that's not the
818-
// default in a DevStudio project
819-
//
820-
821-
TheAsciiStringCriticalSection = &critSec1;
822-
TheUnicodeStringCriticalSection = &critSec2;
823-
TheDmaCriticalSection = &critSec3;
824-
TheMemoryPoolCriticalSection = &critSec4;
825-
TheDebugLogCriticalSection = &critSec5;
826-
827-
// initialize the memory manager early
828-
initMemoryManager();
829-
830-
/// @todo remove this force set of working directory later
831-
Char buffer[ _MAX_PATH ];
832-
GetModuleFileName( nullptr, buffer, sizeof( buffer ) );
833-
if (Char *pEnd = strrchr(buffer, '\\'))
834-
{
835-
*pEnd = 0;
836-
}
837-
::SetCurrentDirectory(buffer);
838-
839-
840-
#ifdef RTS_DEBUG
841-
// Turn on Memory heap tracking
842-
int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
843-
tmpFlag |= (_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
844-
tmpFlag &= ~_CRTDBG_CHECK_CRT_DF;
845-
_CrtSetDbgFlag( tmpFlag );
846-
#endif
847-
848-
849810

850811
// install debug callbacks
851812
// WWDebug_Install_Message_Handler(WWDebug_Message_Callback);

0 commit comments

Comments
 (0)