Hey guys,
So I've been messing with SDL this weekend, and found some great tutorials on YouTube, but I've been running into a bizarre problem that Google has been no help in solving. Some functions, for no good reason (there is a reason, but it has been obfuscated to oblivion), will crash my program. Here's my code so far:
#include <iostream>
#include "SDL.h"
#define WINDOW_WIDTH 800;
#define WINDOW_HEIGHT 600
#define FPS 60
void DrawChessBoard(SDL_Renderer *renderer)
{
int row = 0,column = 0,x = 0;
SDL_Rect rect, screen_size;
/* Get the Size of drawing surface */
SDL_RenderGetViewport(renderer, &screen_size);
for ( ; row < 8; row++) {
column = row % 2;
x = column;
for ( ; column < 4 + (row % 2); column++) {
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
rect.w = screen_size.w/8;
rect.h = screen_size.h/8;
rect.x = x * rect.w;
rect.y = row * rect.h;
x = x + 2;
SDL_RenderFillRect(renderer, &rect);
}
}
}
int WinMain() // SDL needs WinMain, for some reason, not main
{
// Fire up SDL
SDL_Init(SDL_INIT_EVERYTHING);
// Create the window
SDL_Window *window = SDL_CreateWindow("You Geek!", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_RESIZABLE);
if (window == NULL)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
}
// Declare variables
SDL_Event *event;
bool running = true;
SDL_Renderer *renderer;
SDL_Surface *surface = SDL_GetWindowSurface(window);
renderer = SDL_CreateSoftwareRenderer(surface);
if (!renderer)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
return 1;
}
// Main loop
while (running)
{
// Draw stuff
DrawChessBoard(renderer); // This worked, ironically
SDL_UpdateWindowSurface(window);
/* Clear the rendering surface with the specified color */
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderClear(renderer);
// Handle events
while (SDL_PollEvent(event))
{
if (event->type == SDL_QUIT)
{
running = false;
break;
}
}
}
// Clean up
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
And some of the functions that cause the epic meltdown are:
SDL_LoadBMP
SDL_GetTicks
SDL_GetWindowSurface (though that one has stopped after a few hours of tinkering, reason still unknown)
And here's what my debugger has to say:
#0 0x768ba9f2 RaiseException() (C:\Windows\SysWOW64\KernelBase.dll:??)
#1 0x6c81b14c SDL_LogCritical() (C:\Media\Code\Projects\EXPERI~1\SDLTES~1\bin\Debug\SDL2.dll:??)
#2 0x406d1388 ?? () (??:??)
#3 ?? ?? () (??:??)
So apparently, whatever is happening has even stumped the debugger (lol). I've never seen a bunch of question marks like that, but I'm guessing they're bad lol. Seriously...?
Anyway, here are some other details:
My IDE is CodeBlocks with MinGW.
My OS is Windows 10 Anniversary Edition, 64-bit
I'm using SDL 2.0, and I've had to use the 32-bit version of the DLL because that seems to be how MinGW wants it (or so said Google when I was battling a different epic crash problem - using the 32-bit DLL allowed my program to run correctly - could that be what's foobarring every other function I try?).
I've been all over the documentation, their Bugzilla page, and lots and lots of Googlefishing, but no dice. Is SDL 2.0 just unstable or something? lol idk but I'm seriously considering trying Unreal again (though getting that to startup has been a way bigger struggle lol - seems the big C++ frameworks like to pile on the challenge-factor for us Windows guys lol, but anywayz). Obviously, I'm stuck outta luck here, so I'd sure appreciate any info on what this hair-jerker of a bug could be. tyvm. :)