Sign in to follow this  

OpenGL openGL app not working outside of visual studio.

This topic is 1774 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

I'm not really sure how to go about saying this so i'll just try to explain and post pictures when ever needed.

http://puu.sh/2eQz7

 

 

as you can see, running this in visiual studio works........but when tried to run like this........

http://puu.sh/2eQv2

 

Im not sure what it could be......

Share this post


Link to post
Share on other sites

You have a broken pointer somewhere in your code. I think that one in particular is related to freeing a pointer; you're trying to free a pointer that doesn't have a valid value, for example double deleting a pointer, or deleting an uninitialized pointer.

Share this post


Link to post
Share on other sites

It could really be anything.

It can be

 

Thing *t = new Thing();
delete t;
delete t; // cleaning same memory twice

 

Or

char *c = new char[10];
c[10] = 10; // array writing out of bounds, you can overwrite some other heap object without even a warning!
// I think this is worst kind of thing, because your error will happen somewhere else, and will be unpredictable

 

Or

Thing * returnIt() {
    Thing t;
    return &t; // if you return pointer to local variable it no loger points to valid memory
}

Thing *t = returnIt();
t->use(); // crash

 

Many things. Actually here is a list from stack overflow:

 

 

Common scenarios include:

  • Writing outside the allocated space of an array (char *stuff = new char[10]; stuff[10] = 3;)
  • Casting to the wrong type
  • Uninitialized pointers
  • Typo error for -> and .
  • Typo error when using * and & (or multiple of either)
  • Mixing new [] and new with delete [] and delete
  • Missing or incorrect copy-constructors
  • Pointer pointing to garbage
  • Calling delete multiple times on the same data
  • Polymorphic baseclasses without virtual destructors
Edited by Nercury

Share this post


Link to post
Share on other sites

Ok, thanks, i figured it out, now......there's another problem.... for example i did something like this:

 

http://puu.sh/2f7Gu

 

as u can see, added vertices all around the circles (need to do some management down the line and if look at the console, you can see that both points are the same but theyt shouldn't be what i did was basically this:

 

	void draw() {
		glBegin(GL_POLYGON);

		
		for(mAngle = 0.0; mAngle <= 2 * 3.14; mAngle += (3.14/this->mNumSegments))
		{
			
			glVertex2d(mXpos + mRadius * -cos(mAngle),
				       mYpos + mRadius * sin(mAngle));
			
			glColor3d(mRed,mGreen,mBlue);
			
		}
		glColor3d(mRed,1,1);
		
		glEnd();
		
			for(mAngle = 0.0; mAngle <= 2 * 3.14; mAngle += (3.14/mNumSegments))
			{
				for(int i = 0; i < mNumSegments; i++)
				{
				
					points.reserve(i);
					points.resize(i);
					points.push_back(new Points);
				
					glColor3d(1,0,0);
					for(vector<Points*>::iterator i = points.begin(); i != points.end(); i++)
					{
						Points* p = (*i);
						if(p != NULL) {
							p->setPosition(mXpos + mRadius * cos(mAngle),
									  mYpos + mRadius * sin(mAngle));
							glPointSize(5);
							p->draw();
						}
						else
						{
							delete p;
							p = 0;
						}
					}
				}
				
				
			}
	

as u can see, it adds 1 point to each segment of the circle. I added this to an array vector so i know it works. As you can see, all the points render to their respective segments on the circle. My problem is getting the points and them being different.....as i said, I got two points that I thought would be with different values since all the points got rendered to the circle, I figured it would be ok........but it's not.

 

Points* getPoint(int index) 
	{
		vector<Points*>::iterator i = points.begin();

		for(i; i != points.end();i++)
		{
			return points[index];
		}
	}

this gets the points based on index (ignore that for loop doesn't really do anything.....so you would expect p[0] and p[1] to have different values? but they don't. this is the same problem i've been having in java with a programming assignment in class.

 

here's what im trying to do (you might of guessed from the screen shot.)

 

	cout << "Num of points = " << faces[0]->getNumPoints() << endl;
	Points* p1 = faces[0]->getPoint(0);
	cout << "p0 pos = " << p1->getX() << " " << p1->getY() << endl;
	glBegin(GL_LINES);
		glVertex2d(p1->getX(),p1->getY());
		glVertex2d(p1->getX()+40,p1->getY()+10);
	glEnd();
	Points* p2 = faces[0]->getPoint(4);
	cout << "p1 pos = " << p2->getX() << " " << p2->getY() << endl;
	glBegin(GL_LINES);
		glVertex2d(p2->getX(),p2->getY());
		glVertex2d(p2->getX()+10,p2->getY()+10);
	glEnd();
	

Share this post


Link to post
Share on other sites

Ok, I am just going to glance over your code...

 

for(mAngle = 0.0; mAngle <= 2 * 3.14; mAngle += (3.14/this->mNumSegments))
{
    //
}

 

 

Never use floating-point values for iteration, because floating point errors accumulate and can cause problems sooner than you think. Use integers:

 

double segmentSize = 3.14/this->mNumSegments;
for (int segment = 0; segment <= this->mNumSegments; segment++) {
     mAngle = segment * segmentSize;
}

 

 

You would make your life easier if you avoid modifying or creating your data on draw. Set up everything beforehand, and just read what to draw.

I especially suggest to rethink this one:

 

points.reserve(i);
points.resize(i);
points.push_back(new Points);

glColor3d(1,0,0);
for(vector<Points*>::iterator i = points.begin(); i != points.end(); i++)
{
	Points* p = (*i);
	if(p != NULL) {
		p->setPosition(mXpos + mRadius * cos(mAngle),
				  mYpos + mRadius * sin(mAngle));
		glPointSize(5);
		p->draw();
	}
	else
	{
		delete p;
		p = 0;
	}
}

 

It looks like it would be extremely hard to manage point lifecycle when they are created and deleted in this way. Of course, I do notice that you try to attempt to delete a null pointer sometimes:

Points* p = (*i);
if(p != NULL) {
	// ...
}
else
{
	delete p; // p is NULL!
	p = 0;
}

 

And.. it looks like for every new triangle point, you are iterating and drawing all the points.

Ok, so my advice is to create/delete objects away from drawing, use update step for that. Only read data in draw.

Edited by Nercury

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Similar Content

    • By _OskaR
      Hi,
      I have an OpenGL application but without possibility to wite own shaders.
      I need to perform small VS modification - is possible to do it in an alternative way? Do we have apps or driver modifictions which will catch the shader sent to GPU and override it?
    • By xhcao
      Does sync be needed to read texture content after access texture image in compute shader?
      My simple code is as below,
      glUseProgram(program.get());
      glBindImageTexture(0, texture[0], 0, GL_FALSE, 3, GL_READ_ONLY, GL_R32UI);
      glBindImageTexture(1, texture[1], 0, GL_FALSE, 4, GL_WRITE_ONLY, GL_R32UI);
      glDispatchCompute(1, 1, 1);
      // Does sync be needed here?
      glUseProgram(0);
      glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
      glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                     GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, texture[1], 0);
      glReadPixels(0, 0, kWidth, kHeight, GL_RED_INTEGER, GL_UNSIGNED_INT, outputValues);
       
      Compute shader is very simple, imageLoad content from texture[0], and imageStore content to texture[1]. Does need to sync after dispatchCompute?
    • By Jonathan2006
      My question: is it possible to transform multiple angular velocities so that they can be reinserted as one? My research is below:
      // This works quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); quat quaternion2 = GEMultiplyQuaternions(quaternion1, GEQuaternionFromAngleRadians(angleRadiansVector2)); quat quaternion3 = GEMultiplyQuaternions(quaternion2, GEQuaternionFromAngleRadians(angleRadiansVector3)); glMultMatrixf(GEMat4FromQuaternion(quaternion3).array); // The first two work fine but not the third. Why? quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); vec3 vector1 = GETransformQuaternionAndVector(quaternion1, angularVelocity1); quat quaternion2 = GEQuaternionFromAngleRadians(angleRadiansVector2); vec3 vector2 = GETransformQuaternionAndVector(quaternion2, angularVelocity2); // This doesn't work //quat quaternion3 = GEQuaternionFromAngleRadians(angleRadiansVector3); //vec3 vector3 = GETransformQuaternionAndVector(quaternion3, angularVelocity3); vec3 angleVelocity = GEAddVectors(vector1, vector2); // Does not work: vec3 angleVelocity = GEAddVectors(vector1, GEAddVectors(vector2, vector3)); static vec3 angleRadiansVector; vec3 angularAcceleration = GESetVector(0.0, 0.0, 0.0); // Sending it through one angular velocity later in my motion engine angleVelocity = GEAddVectors(angleVelocity, GEMultiplyVectorAndScalar(angularAcceleration, timeStep)); angleRadiansVector = GEAddVectors(angleRadiansVector, GEMultiplyVectorAndScalar(angleVelocity, timeStep)); glMultMatrixf(GEMat4FromEulerAngle(angleRadiansVector).array); Also how do I combine multiple angularAcceleration variables? Is there an easier way to transform the angular values?
    • By dpadam450
      I have this code below in both my vertex and fragment shader, however when I request glGetUniformLocation("Lights[0].diffuse") or "Lights[0].attenuation", it returns -1. It will only give me a valid uniform location if I actually use the diffuse/attenuation variables in the VERTEX shader. Because I use position in the vertex shader, it always returns a valid uniform location. I've read that I can share uniforms across both vertex and fragment, but I'm confused what this is even compiling to if this is the case.
       
      #define NUM_LIGHTS 2
      struct Light
      {
          vec3 position;
          vec3 diffuse;
          float attenuation;
      };
      uniform Light Lights[NUM_LIGHTS];
       
       
    • By pr033r
      Hello,
      I have a Bachelor project on topic "Implenet 3D Boid's algorithm in OpenGL". All OpenGL issues works fine for me, all rendering etc. But when I started implement the boid's algorithm it was getting worse and worse. I read article (http://natureofcode.com/book/chapter-6-autonomous-agents/) inspirate from another code (here: https://github.com/jyanar/Boids/tree/master/src) but it still doesn't work like in tutorials and videos. For example the main problem: when I apply Cohesion (one of three main laws of boids) it makes some "cycling knot". Second, when some flock touch to another it scary change the coordination or respawn in origin (x: 0, y:0. z:0). Just some streng things. 
      I followed many tutorials, change a try everything but it isn't so smooth, without lags like in another videos. I really need your help. 
      My code (optimalizing branch): https://github.com/pr033r/BachelorProject/tree/Optimalizing
      Exe file (if you want to look) and models folder (for those who will download the sources):
      http://leteckaposta.cz/367190436
      Thanks for any help...

  • Popular Now