1

I was trying to learn SDL2 and C++ and I was following this tutorial on setting everything up, I copied the code and downloaded the necessary files and moved them, however, when I try to run the code this is what shows in the output

'1stSDLWindow.exe' (Win32): Loaded 'C:\Users\Alec\source\repos\1stSDLWindow\x64\Debug\1stSDLWindow.exe'. Symbols loaded.
'1stSDLWindow.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. 
'1stSDLWindow.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. 
'1stSDLWindow.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. 
'1stSDLWindow.exe' (Win32): Loaded 'C:\Windows\System32\shell32.dll'. 
'1stSDLWindow.exe' (Win32): Loaded 'C:\Windows\System32\msvcp_win.dll'. 
'1stSDLWindow.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbase.dll'. 
'1stSDLWindow.exe' (Win32): Loaded 'C:\Windows\System32\user32.dll'. 
'1stSDLWindow.exe' (Win32): Loaded 'C:\Windows\System32\win32u.dll'. 
'1stSDLWindow.exe' (Win32): Loaded 'C:\Windows\System32\gdi32.dll'. 
'1stSDLWindow.exe' (Win32): Loaded 'C:\Windows\System32\gdi32full.dll'. 
'1stSDLWindow.exe' (Win32): Loaded 'C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\bin\SDL2.dll'. 
'1stSDLWindow.exe' (Win32): Unloaded 'C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\bin\SDL2.dll'
The thread 0x7e8 has exited with code -1073741701 (0xc000007b).
The thread 0x32c8 has exited with code -1073741701 (0xc000007b).
The program '[6436] 1stSDLWindow.exe' has exited with code -1073741701 (0xc000007b).

There is no screen that displays green as the code should and an error pops up with this

This is the code

#include "SDL.h"

int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window* window = SDL_CreateWindow("Title", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 600, 400, SDL_WINDOW_SHOWN);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);

SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);

SDL_RenderClear(renderer);

SDL_RenderPresent(renderer);

SDL_Delay(3000);
return 0;
}

Why is it trying to load SDL2.dll from my TF2 directory? Is this causing the issue? How can I load the .dll from the actually downloaded folder?

drescherjm
  • 10,365
  • 5
  • 44
  • 64
  • 5
    What does your PATH environment variable looks like? – Jeffrey Aug 13 '20 at 02:03
  • 1
    Most likely because that version of SDL2 was found first when searching the folders listed in the `PATH` environment variable. – drescherjm Aug 13 '20 at 02:38
  • 2
    Seconding @Jeffrey's comment, see [step 6 of the `SafeDllSearchMode` procedure](https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#standard-search-order-for-desktop-applications). Though that *does* raise the question of why TF2 would be in your `PATH`. – genpfault Aug 13 '20 at 02:38
  • These seemed to do the trick, I found other cases where other Steamapps directories where part of the PATH variable – RevivingSociety Aug 13 '20 at 03:29
  • 1
    ***Is this causing the issue?*** It could cause an issue because your code may use a vastly different version of SDL2 dlls and the different version may be incompatible with the version you statically link using the import library. This is often called DLL Hell. Related: [https://stackoverflow.com/questions/1379287/i-keep-hearing-about-dll-hell-what-is-this](https://stackoverflow.com/questions/1379287/i-keep-hearing-about-dll-hell-what-is-this) – drescherjm Aug 13 '20 at 12:37

1 Answers1

3

TF2's directory was in the environment variables and that's where it was trying to load from. I removed those directories from the PATH and moved the SDL2.dll file where the exe was being built for my program