Note that there are some explanatory texts on larger screens.

plurals
  1. POOverzealous method doing work without a call? C++ Glut initialization gone rogue
    text
    copied!<p>rookie C++ programmer here still. </p> <p>I'm using VC++ VS2008 compiler and glut library. All working fine and up to date ( I know there's 2010 just cba because of XNA (C#) support reasons)</p> <p>Ok this time I have a question that is code related but I can make the code work. What I can not do is figure out what is happening under the hood. That's what I'd like to figure out.</p> <p>Assume all works, because clearly in runtime it works!</p> <p>Here's the code (minimized to what is actually running to it's bare core to help speed this up)</p> <pre><code>#include "stdafx.h" #include "Controller.h" #include "glut.h" #include &lt;iostream&gt; void main(int argc, char** argv) { glutInit(&amp;argc, argv); //controller_ptr-&gt;InitController(); &lt;---- no link to controller--&gt;DrawScene //INIT GLUT //glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); //glutInitWindowSize(400, 400); //Set the window size //glutCreateWindow("Some Program"); //INIT RENDERING glEnable(GL_DEPTH_TEST); glutDisplayFunc(drawScene); glutKeyboardFunc(handleKeypress); glutReshapeFunc(handleResize); glutMainLoop(); } </code></pre> <p>You may be thinking, hey you have the init code commented. I do indeed. Guess what , it is still working! Why? I don't really KNOW glut except on BBQ's so ye.... &lt;---- This could be a good point for you to call the fail if any</p> <p>I have a drawscene class with this method</p> <pre><code>void DrawScene::initGlut() { //Enables depth culling/front face culling?????? &lt;----- what about that, some depth thingy was involved is all I'm sure of glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(400, 400); //Set the window size glutCreateWindow("Some Program"); } </code></pre> <p>When I comment this and uncomment the one in the main, same result. I comment none, glut says init is done twice, I comment neither, init is not done it all goes boom. So the only logical conclusion would be to say this method is called, right?</p> <p>There's a bunch of other methods around and classes but there is no instance of the displayescene class nor controller class. I can comment the includes and it will do all the same.</p> <p>Is there some design part I do not understand in MSbuild or VC++ development which allows methods to sift along some stream or flow that I am unaware of? As far as my knowledge goes, if I do not make an instance of a class it's not relevant, at least it's non-static members. So how can this code being active or inactive in this member have an effect on my program then?</p> <p>Probably forgetting something incredibly stupid, but I'd rather find out a.s.a.p. anyway, the good part about being a rookie is that I couldn't care less about falling flat on my face and trying again so fire away with the comments ^^</p> <p>Thank you very much in advance!</p> <p>EDIT: What the ? Now the console without any change to the code did report once a double call to init with the main init in comment and the one in drawscene not in comment...I am very much confused.</p> <p>EDIT 2: 14:45 29/08/2010</p> <p>Ok I found something....</p> <p>The constructor in drawscene calls the initGlut and initRendering methods of the class. The controller makes a pointer to the heap holding a drawScene object there which causes the methods to run the init code.</p> <p>The controller however is not included in the main nor is it instantiated. That drawScene code is run before the main starts and can I then conclude that the build itself is the problem so I should avoid init code in constructors?</p> <p>EDIT 3: 15:02 29/08/2010</p> <p>Found another , the double call does occur when only the drawScene is the active init code. Could it be that every include of drawscene causes constructor code to run init code and cause the double init?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload