10 Replies - 334 Views - Last Post: 19 January 2019 - 08:19 PM Rate Topic: -----

#1 tolazytbh   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 24-December 18

Is this just too large?

Posted 18 January 2019 - 02:25 AM

terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 1297000) >= this->size() (which is 1297000)



in initialization of class
    curScreen.resize(1297000);



In the perform method (functions at framerate)
        int g = 0;
        for(int i = 0; i < 1430; i++) {
            for(int b = 0; b < 890; i++) {
                curScreen.at(g).setActive(true, curScreen.at(g));
                curScreen.at(g).setColor(0,240,0, curScreen.at(g));
                curScreen.at(g).setPos((short) i, (short) b, 1, curScreen.at(g));
                /*curScreenTile add;
                add.setColor(0,240,0);
                add.setPos((short) 0, (short) 0, 10);
                curScreen.push_back(add);*/
                g++;
            }
            g++;
        }



the variables
struct curScreenTile {
        RECT r;
        unsigned long rgb;
        bool activeTile = false;

        static void setColor(int b, int g, int r, curScreenTile tile) {
            tile.rgb = ((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff);
        }

        static void setPos(short x, short y, short pixelSize, curScreenTile tile) {
                tile.r.left = x;
                tile.r.top = y;
                tile.r.right = y+pixelSize;
                tile.r.bottom = x+pixelSize;
        }

        static void setActive(bool toSet, curScreenTile tile) {
            tile.activeTile = toSet;
        }

        static RECT getR(curScreenTile tile) {
            return tile.r;
        }

        static unsigned long getColor(curScreenTile tile) {
            return tile.rgb;
        }

        static bool active(curScreenTile tile) {
            return tile.activeTile;
        }
};



std::vector<curScreenTile> curScreen;



There's something like 1,269,900 pixels on my screen
If this isn't possible is simply just doing a normal
 curScreenTile tiles[];


Possible at that size?
kind of just a worse case scenario doing a color for each pixel on the screen...

Is This A Good Question/Topic? 0
  • +

Replies To: Is this just too large?

#2 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2726
  • View blog
  • Posts: 4,365
  • Joined: 21-June 11

Re: Is this just too large?

Posted 18 January 2019 - 02:35 AM

You're getting an out_of_range exception because you're calling at with the argument 1297000, which is the size of your vector (the maximum valid index for a vector is one less than its size). The problem has nothing to do with the vector being too large - just with your index being out of bounds.
Was This Post Helpful? 1
  • +
  • -

#3 tolazytbh   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 24-December 18

Re: Is this just too large?

Posted 18 January 2019 - 02:42 AM

Can you point out exactly where?
or what the solution would look like? I just started c++ from programming Java for a while and i'm confused

This post has been edited by tolazytbh: 18 January 2019 - 02:47 AM

Was This Post Helpful? 0
  • +
  • -

#4 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2726
  • View blog
  • Posts: 4,365
  • Joined: 21-June 11

Re: Is this just too large?

Posted 18 January 2019 - 02:48 AM

On the line where the exception is being thrown. I imagine that'd be line 4 of the code you've shown from the perform method, but when in doubt, you can just use the debugger to find out.
Was This Post Helpful? 1
  • +
  • -

#5 tolazytbh   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 24-December 18

Re: Is this just too large?

Posted 18 January 2019 - 03:02 AM

It's not giving a line, the for loop doesn't hit the max value, I even changed the 1 to a 5
Was This Post Helpful? 0
  • +
  • -

#6 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2726
  • View blog
  • Posts: 4,365
  • Joined: 21-June 11

Re: Is this just too large?

Posted 18 January 2019 - 03:10 AM

View Posttolazytbh, on 18 January 2019 - 11:02 AM, said:

It's not giving a line


If your debugger is not telling you line numbers, you probably forgot to enable debug symbols when compiling.


Quote

the for loop doesn't hit the max value


How do you know that? Did you look at the value of g in the debugger or print it before calling .at(g)?

Quote

I even changed the 1 to a 5


I don't know what you mean by that. Which 1?
Was This Post Helpful? 0
  • +
  • -

#7 Salem_c   User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 2310
  • View blog
  • Posts: 4,418
  • Joined: 30-May 10

Re: Is this just too large?

Posted 18 January 2019 - 04:08 AM

Quick quiz, how many times do you increment g when b == 890 ?
Was This Post Helpful? 0
  • +
  • -

#8 tolazytbh   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 24-December 18

Re: Is this just too large?

Posted 18 January 2019 - 05:40 PM

View PostSalem_c, on 18 January 2019 - 04:08 AM, said:

Quick quiz, how many times do you increment g when b == 890 ?

For Each line of 1430 pixels across SIR!

yeah i'm surprised there's a couple million pixels on the screen aswell…

oh it increments g after the entire loop is done of 890 down

This post has been edited by tolazytbh: 18 January 2019 - 05:41 PM

Was This Post Helpful? 0
  • +
  • -

#9 Salem_c   User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 2310
  • View blog
  • Posts: 4,418
  • Joined: 30-May 10

Re: Is this just too large?

Posted 18 January 2019 - 07:31 PM

Well since you didn't get my point that you increment g TWICE at the end of each row (thus creating holes in your vector), I thought I'd do a quick example.

In doing so, I discovered yet another problem!
02 for(int i = 0; i < 1430; i++) {
03 for(int b = 0; b < 890; i++) {


You're incrementing the WRONG variable. This loop never exits.
You just keep adding to the vector until it blows up.


And this is what I was trying to get across to you about your g variable.
$ cat foo.cpp
#include <iostream>
int main ( ) {
    int g = 0;
    for(int i = 0; i < 10; i++) {
        for(int b = 0; b < 10; b++) {
            g++;
        }
        g++;  // do it again
    }
    std::cout << "g=" << g << std::endl;
}

$ ./a.out 
g=110


A 10x10 loop should increment g to 100, not 110.

This post has been edited by Salem_c: 18 January 2019 - 07:31 PM

Was This Post Helpful? 0
  • +
  • -

#10 tolazytbh   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 24-December 18

Re: Is this just too large?

Posted 19 January 2019 - 07:44 PM

Thanks didn't notice the I in the second loop I thought I had fixed that in the middle of typing it,
And I should just have it inside the b for loop then?

This post has been edited by Skydiver: 19 January 2019 - 08:19 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#11 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6763
  • View blog
  • Posts: 23,067
  • Joined: 05-May 12

Re: Is this just too large?

Posted 19 January 2019 - 08:19 PM

There is no need to quote the post above yours. Just use the big Reply button or the Fast Reply area.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1