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 4918

Summary: SDL failed to build due to error LNK2019: unresolved external symbol memset referenced in function SDL_SetJoystickIDForPlayerIndex with MSVC x64 on Windows
Product: SDL Reporter: LinGao <gaolin01>
Component: buildAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2 CC: sezeroz
Version: HG 2.1   
Hardware: x86   
OS: Windows 10   
Attachments: log_x64_build

Description LinGao 2019-12-26 08:49:34 UTC
Created attachment 4139 [details]
log_x64_build

Hi,

We build SDL with Visual studio 2017 compiler on Windows Server 2016, but it failed to build due to error LNK2019: unresolved external symbol memset referenced in function SDL_SetJoystickIDForPlayerIndex with MSVC x64 on Windows on latest default branch. And we found that it can be first reproduced on 6c431d30a6df changeset. Could you please help have a look about this issue? Thanks in advance!

Steps to Reproduce:
1.hg clone https://hg.libsdl.org/SDL D:\SDL\src
2.Open a VS 2017 x64 command prompt as admin and browse to D:\SDL
3.msbuild /p:Configuration=Release /p:Platform=x64 /p:WindowsTargetPlatformVersion=10.0.17134.0 VisualC\SDL.sln /t:Rebuild

Actual result:
 Creating library D:\SDL\src\VisualC\x64\Release\SDL2.lib and object D:\SDL\src\VisualC\x64\Release\SDL2.exp
SDL_joystick.obj : error LNK2019: unresolved external symbol memset referenced in function SDL_SetJoystickIDForPlayerIndex [D:\SDL\src\VisualC\SDL\SDL.vcxproj]
D:\SDL\src\VisualC\x64\Release\SDL2.dll : fatal error LNK1120: 1 unresolved externals [D:\SDL\src\VisualC\SDL\SDL.vcxproj]
Done Building Project "D:\SDL\src\VisualC\SDL\SDL.vcxproj" (Rebuild target(s)) -- FAILED.
Comment 1 Ozkan Sezer 2019-12-26 09:33:27 UTC
Here is a possible fix:

diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -158,9 +158,8 @@ SDL_SetJoystickIDForPlayerIndex(int play
         }
 
         SDL_joystick_players = new_players;
-        while (SDL_joystick_player_count <= player_index) {
-            SDL_joystick_players[SDL_joystick_player_count++] = -1;
-        }
+        SDL_memset4(SDL_joystick_players, (Uint32)(-1),
+         player_index + 1 - SDL_joystick_player_count);
     }
 
     SDL_joystick_players[player_index] = instance_id;
Comment 2 Ozkan Sezer 2019-12-27 20:31:52 UTC
(In reply to Ozkan Sezer from comment #1)
> Here is a possible fix:
My patch is obviously bad. Ignore.
Comment 3 Sam Lantinga 2019-12-30 21:19:16 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/d06fbb1b5b78