Sign in to follow this  

SDL_PollEvent crashes when adding an additional line.

This topic is 681 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Whenever FindPath is commented out, the program runs fine,

Otherwise, it crashes, it is about to say that the stack has corrupted.

Any ideas?

Thanks

Jack

 

#include <SDL.h>
#include <thread>
#include <chrono>
#include "general_part.h"
#include "Path.h"   
 

bool gbSmoothSimple = false;
bool gbDirectional = true;
bool gbCurved = true;
bool gbSmooth48 = true;
bool gbSmooth = true;
double gGranularity = 0.5f;
bool gbIgnoreBounds = true;
bool gbFixed = true;
double gTurnRadius = 0.01f;
double gShipWidth = 0.8f;
bool gGrid[MAX_GRIDSIZE][MAX_GRIDSIZE];
int gSearch = 8;

void initGrid();

SDL_Surface* screen = NULL;
SDL_Event event;

int main(int argc, char* argv[]) {

    SDL_Init(SDL_INIT_VIDEO);

    SDL_WM_SetCaption("Pinter Demo", NULL);

    screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

    bool running = true;

    
    FPOINT start, end;

    start.x = 0.0f;
    start.y = 0.0f;

    end.x = 10.0f;
    end.y = 10.0f;

    FINFO* path = new FINFO();    

    double startDirection = 0.1f;
    initGrid();
    SetupSqrtTable();
    SetupDirOffsets();
    SetupTurnTable();
    SetupHeuristicTable();
    
    
    
    
    
    while (running)
    {
        if (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                running = false;
            }
        }



        int status = FindPath(start, end, startDirection, path);

        //std::this_thread::sleep_for(std::chrono::seconds(5));
    }

    SDL_Quit();
    
    return 0;
}

void initGrid() {
    for (int i = 0; i < MAX_GRIDSIZE; i++) {
        for (int j = 0; j < MAX_GRIDSIZE; j++) {
            gGrid[i][j] = false;
        }
    }
}

Share this post


Link to post
Share on other sites

Yes, run it under debugger, set breakpoint at FindPath line, step into and step by step see what's going on. Check the backtrace, check variables. This way you will solve your problem within minutes. How are we supposed to tell why it crashes if you give us only scraps of code ( without the most relevant part which is body of FindPath()  ) and without any clue what and how your code supposed to be doing? 

Share this post


Link to post
Share on other sites

This topic is 681 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this