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

  • SEARCH
  • Home
  • 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 6784949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:03:49+00:00 2026-05-26T17:03:49+00:00

I have global variables: point4 * mypoints; color4 * mycolors; And a block of

  • 0

I have global variables:

point4 * mypoints;
color4 * mycolors;

And a block of code thats part of a function drawPlyFiles

vector<point4> retpolys;
retpolys.resize(polynum * 3);
GLint polyx, polyy, polyz;
for (int i = 0; i < polynum; i++)
{
    inStream >> polyx;
    inStream >> polyx >> polyy >> polyz;
    //cout << "x: " << polyx << " y: " << polyy << " z: " << polyz << "\n";
    retpolys[i*3] = retVerts[polyx];
    retpolys[(i*3) + 1] = retVerts[polyy];
    retpolys[(i*3) + 2] = retVerts[polyz];
    //retpolys[i] = point4( polyx, polyy,  polyz, 1.0 );
}

mypoints = &retpolys[0];
return true;

The important part to take away from the code is that I set global mypoints(array) equal to retpolys(vector). Retpolys gets filled with data from the for loop. When I debug, all the data in retpolys is fine and proper. (retVerts is a vector of point4)

later on in my main init function this gets run:

drawPlyFile("ply_files/airplane.ply");
//colorcube();
point4 temp = mypoints[1];
int thissize = sizeof(mypoints)/sizeof(mypoints[0]);
for (int i = 0; i < thissize; i++)
{
    mycolors[i] = color4( 0.0, 0.0, 0.0, 1.0 );
}

The code compiles fine but I have a runtime exception. I debug in order to find the problem. I check the value of mypoints after drawPlyFiles, and it looks like it just contains a pointer to where retpolys began. However, when I debug, it doesn’t let me view other parts of the array, just that first pointer.(I can see all the separate values of retpolys when im in the function) I then check the value of this size and i get a number like -12894161, which doesn’t make sense since it should be the size of mypoints.

I think the issue lies in the conversion from retpolys to mypoints but I have no idea how to fix it, or even if thats the actual reason for error. Any help?

p.s. I want mycolors to have the same number of elements as mypoints and for all of em to be color4( 0.0, 0.0, 0.0, 1.0 )

  • 1 1 Answer
  • 1 View
  • 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-26T17:03:49+00:00Added an answer on May 26, 2026 at 5:03 pm

    The following line is incorrect:

    mypoints = &retpolys[0];
    

    Here, you’re taking the pointer on the content of a vector that is automatically destroyed when you exit the function. The vector destructor will deallocate this piece of memory making your global variable pointing to a deallocated memory space.

    You should make an actual memory allocation and copy the content.

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

Sidebar

Related Questions

I have many js methods that uses global variables like: function DoSomething() { var
In Actionscript you can have global variables like this: var number : Number =
I have global static variables in a C library, which generate exceptions in a
I have a global variables that I am using as a default variable. Depending
I have two questions: 1) I have a few global variables for my website
I have made latitude and longtitude global variables. It works fine in the MyLocationListener
Can Dynamic libraries have global, local and static variables in linux? If yes, then
I have list view and its adapter stored as global variables. I am not
I have searched and tried every example regarding singleton, public, and global variables in
For some reason I have to access Jenkins global environment variables like BUILD ID,

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.