Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6639729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:35:19+00:00 2026-05-25T23:35:19+00:00

I’m creating a maze program, that randomly generates a path. I’m using an idle

  • 0

I’m creating a maze program, that randomly generates a path. I’m using an idle function to calculate the next direction and shape of the path, but for some reason the idle function is not being called by glutIdleFunc. I checked this with visual studio’s debugger and having it step through each line of code. When the debugger gets to the “glutIdleFunc(idle)”, it just skips over it rather than going into the function.

A previous build had idle getting called, but the logic in it was not right, so I had to completely rewrite the idle function. I did get rid of some global variables that I no longer needed with my new logic, but I don’t think they should have affected whether or not idle gets called.

This is the main that calls glutIdleFunc.

//<<<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>>
void main(int argc, char **argv){

  glutInit(&argc, argv);          // initialize the toolkit
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set the display mode
  glutInitWindowSize(640,480);     // set the window size
  glutInitWindowPosition(100, 150); // set the window position on the screen
  glutCreateWindow("Maze"); // open the screen window(with its exciting title)
  glutDisplayFunc(myDisplay);     // register the redraw function
  myInit();   
  glutIdleFunc(idle);  // IDLE FUNCTION IS CALLED HERE
  glutMainLoop();            // go into a perpetual loop

}

Here is the idle function

 void idle(){

 int c; // holds column value for square
 int r; // holds row value for square

 if((done == false) && just_visited.empty()){

     // initialize random seed
     srand ( time(NULL) );

     // randomly select first maze square indices
      c = rand() % num_col + 1;
      r = rand() % num_row + 1;
 }
 else if(done == false){

     // set c and r to index values for last
     // accessed block
     c = just_visited.top().col;
     r = just_visited.top().row;

     vector<square> possible_paths;
     bool open_path = false;    // will set to true if there is an untouched adjacent square to move to

     // will not exit loop until an open path is found or the maze has been completed
     while(open_path != true || done != true){

         // if statements check each adjacent square to see if they are possible_paths
         // if they are then they get put into possible paths vector for access later
         if(map[r][c].north == true && map[r+1][c].east == true && map[r+1][c].north == true && map[r+1][c-1].east == true){
             possible_paths.push_back(map[r+1][c]);
             open_path = true;
         }

         if(map[r][c].east == true && map[r][c+1].east == true && map[r][c+1].north == true && map[r-1][c+1].north == true){
             possible_paths.push_back(map[r][c+1]);
             open_path = true;
         }

         if(map[r-1][c].north == true && map[r-1][c].east == true && map[r-2][c].north == true && map[r-1][c-1].east == true){
             possible_paths.push_back(map[r-1][c]);
             open_path = true;
         }

         if(map[r][c-1].north == true && map[r][c-1].east == true && map[r][c-2].east == true && map[r-1][c].north == true){
             possible_paths.push_back(map[r][c-1]);
             open_path = true;
         }

         if(!open_path){ // if no direction around current square is open, backtrack in maze
                 just_visited.pop(); // pop last off the stack

                 if(just_visited.empty()){ // if stack is empty then the maze is done

                     done = true;
                 }

                 // set and c and r to new square values
                 c = just_visited.top().col;
                 r = just_visited.top().row;
        }
    } // end of while loop

    if(!done && open_path){

        //choose a direction to go
        int dir = rand() % possible_paths.size(); 

        if(possible_paths[dir].col > c){
            map[c][r].east = false;
            just_visited.push(map[c+1][r]);
        }
        else if(possible_paths[dir].col < c){
            map[c-1][r].east = false;
            just_visited.push(map[c-1][r]);
        }
        else if(possible_paths[dir].row > r){
            map[c][r].north = false;
            just_visited.push(map[c][r+1]);
        }
        else if(possible_paths[dir].row < r){
            map[c][r-1].north = false;
            just_visited.push(map[c][r-1]);
        }
    } // end of if statement

    glutPostRedisplay();

   } //end of if statement
 } // end of idle

Can anyone help me out? What am I missing doing wrong that idle isn’t getting called?

(Also I’m having trouble pasting code into here from visual studios, the formatting gets super messed up. I’m using chrome for my browser)

Here is a link to my full visual studios project folder

http://dl.dropbox.com/u/15786901/Maze.rar

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:35:19+00:00Added an answer on May 25, 2026 at 11:35 pm

    When the debugger gets to the “glutIdleFunc(idle)”, it just skips over it rather than going into the function.

    glutIdleFunc() just registers the function pointer with GLUT. Logic inside of glutMainLoop() takes care of actually calling it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.