*slaps forehead*

Supercell::Supercell(Renderer* r, …)
    : _renderer(r) // …
    , _cells()
{
    _cells.reserve(64) ;
    assert( _cells.empty() = false ) ;
}

 

What I don’t get is why the PC build ignored the assert…

I am going to be doing a lot of sleeping this weekend…

4 Comments

I believe that it is the initialization of the vector with a size that is creating the problem.

In C++, the vector when initialized it has no size, thus is empty. Initializing it with 64 indices gives it a size of 64, thus checking to see if the vector is empty returns 64, and it is not empty in the eyes of the program.

So the PC is not ignoring the assert, it is seeing 64 cells of garbage (at least to you) data. The only way the vector would ever read true is if, before the check, you deleted all the cells, like using the vector for a que.

No, the error was sheer tiredness induced stupidity —

assert( _cells.empty() == false

I was testing it for ‘true”.

vector::reserve only increases the capacity, you’re thinking of resize().

For some reason, when you construct a vector with a size, e.g.

std::vector bob(64) ;

Microsoft’s STL treats it as a request for 64 pre-allocated members. Under the two other STLs I looked at – and according to the STL standard itself – it’s supposed to be like calling reserve().

Anyway, the mistake here was mine – testing for “false”.

assert( false = _cells.empty())

would have gotten a compile error IIRC.

That ordering is why some programmers insist on using the if (0 == foo) ordering of things. To catch the (0 = foo) case. Me .. I just don’t like that ordering, so .. heh.

Leave a Reply

Name and email address are required. Your email address will not be published.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

You may use these HTML tags and attributes:

<a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <pre> <q cite=""> <s> <strike> <strong> 

%d bloggers like this: