   Memory heap corruption with vectors
  Hi,Recently I learnt about the vector class in c++ and it's been of great help. However, now I've run into some errors. I googled around a bit and I did solve a part of my problems in the last 5 hours, but I really need someone else to look at it.Here's the code causing the problems:(For some reason the 'plus' characters are invisible when I preview my post, any fix for this?)It's about this vector// TowerHandler membersstd::vector<Tower> m_tower;This function is used to add an element at the end of the vectorvoid TowerHandler::CraftTower( const unsigned id ) {    // Temp gold cost variable    unsigned temp_gold, temp_targettype, temp_targettype_modifier;    // Set temporary variables depending on tower type    switch( id ) {case TEX_BASIC_TOWER: temp_gold = BASIC_TOWER_GOLD;temp_targettype = m_default_target_type[ 0 ];  temp_targettype_modifier = m_default_target_type_modifier[ 0 ];    break;   case TEX_CANON_TOWER: temp_gold = CANON_TOWER_GOLD;temp_targettype = m_default_target_type[ 1 ];    temp_targettype_modifier = m_default_target_type_modifier[ 1 ];    break;case TEX_FROST_TOWER: temp_gold = FROST_TOWER_GOLD;temp_targettype = m_default_target_type[ 2 ];  temp_targettype_modifier = m_default_target_type_modifier[ 2 ];  break;case TEX_SNIPER_TOWER: temp_gold = SNIPER_TOWER_GOLD;temp_targettype = m_default_target_type[ 3 ];    temp_targettype_modifier = m_default_target_type_modifier[ 3 ];    break;case TEX_RAPID_TOWER: temp_gold = RAPID_TOWER_GOLD;temp_targettype = m_default_target_type[ 4 ];    temp_targettype_modifier = m_default_target_type_modifier[ 4 ];    break;    }    // Create the new tower    if( temp_gold <= gold ) {gold -= temp_gold;   m_tower.push_back( Tower( point( m_tower_crafter.rect.topleft.x , m_tower_crafter.rect.topleft.y ), id ) );m_tower[ m_tower.size() - 1 ].SetCraftGoldSpent( temp_gold );m_tower[ m_tower.size() - 1 ].GetGunner().SetTargetType( temp_targettype );m_tower[ m_tower.size() - 1 ].GetGunner().SetTargetTypeModifier( temp_targettype_modifier );    }    // else not enough gold to craft}This function is used to erase a given element from the vectorUsed when only 1 tower is selectedvoid TowerHandler::SellTower( const unsigned t_nr ) {   // Sell tower   gold += m_tower[ t_nr ].GetUpgradeTotalSpent(); // 100% refund   m_tower.erase( m_tower.begin() + t_nr );}This function is used to erase all selected elements from the vectorUsed when more than 1 tower is selectedvoid TowerHandler::SellTower() {    // Temp variables    unsigned temp_selected_towers = GetAmountSelectedTowers();    unsigned temp_sell_counter = 0;    // Sell selected towers    while( temp_sell_counter != temp_selected_towers )for( unsigned i = 0; i < m_tower.size(); i++ )if( m_tower.GetSelected() ) {   <span class="cpp-comment">// Sell tower</span>   gold += m_tower.GetUpgradeTotalSpent(); <span class="cpp-comment">// 100% refund</span>m_tower.erase( m_tower.begin() + i );temp_sell_counter++;<span class="cpp-comment">// Increase counter</span>i = m_tower.size() + <span class="cpp-number">1</span>;<span class="cpp-comment">// End loop</span>    }}</pre></div><!–ENDSCRIPT–>And finally, this function is used to select the elements<!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre><span class="cpp-keyword">void</span> TowerHandler::MassSelect() {    <span class="cpp-comment">// Temporary variables</span>    std::vector&lt;<span class="cpp-keyword">unsigned</span>&gt; tower_selection_filter;    <span class="cpp-comment">// Look for towers inside the mass selector rectangle</span>    <span class="cpp-keyword">for</span>( <span class="cpp-keyword">unsigned</span> i = <span class="cpp-number">0</span>; i &lt; m_tower.size(); i++ )  <span class="cpp-comment">// Rectangle going from topleft to bottomright</span>   <span class="cpp-keyword">if</span>( ( m_mass_selector.rect.topleft.x &lt; m_tower.GetOffset().rect.bottomright.x &amp;&amp; m_mass_selector.rect.topleft.y &lt; m_tower.GetOffset().rect.bottomright.y &amp;&amp;  m_mass_selector.rect.bottomright.x &gt; m_tower.GetOffset().rect.topleft.x &amp;&amp; m_mass_selector.rect.bottomright.y &gt; m_tower.GetOffset().rect.topleft.y ) ||   <span class="cpp-comment">// Rectangle going from topright to bottomleft</span>    ( m_mass_selector.rect.topleft.x &gt; m_tower.GetOffset().rect.bottomright.x &amp;&amp; m_mass_selector.rect.topleft.y &lt; m_tower.GetOffset().rect.bottomright.y &amp;&amp;  m_mass_selector.rect.bottomright.x &lt; m_tower.GetOffset().rect.topleft.x &amp;&amp; m_mass_selector.rect.bottomright.y &gt; m_tower.GetOffset().rect.topleft.y ) )    <span class="cpp-comment">// Add index of tower to vector</span>    tower_selection_filter.push_back( i );    <span class="cpp-comment">// Filter only the smallest distances in vector, remove others</span>    <span class="cpp-keyword">while</span>( tower_selection_filter.size() &gt; MAX_SELECTABLE_TOWERS ) {<span class="cpp-comment">// Temp variables</span><span class="cpp-keyword">unsigned</span> temp_largest_distance_index = <span class="cpp-number">0</span>;<span class="cpp-keyword">double</span> temp_largest_distance = <span class="cpp-number">0</span>;<span class="cpp-comment">// Find largest distance</span><span class="cpp-keyword">for</span>( <span class="cpp-keyword">unsigned</span> i = <span class="cpp-number">0</span>; i &lt; tower_selection_filter.size(); i++ )    <span class="cpp-keyword">if</span>( CalcDistance( m_mass_selector_middle, m_tower[ tower_selection_filter ].GetGunner().GetOffset().circ.middle ) &gt; temp_largest_distance ) {temp_largest_distance_index = i;temp_largest_distance = CalcDistance( m_mass_selector_middle, m_tower[ tower_selection_filter ].GetGunner().GetOffset().circ.middle );    }<span class="cpp-comment">// Remove largest distance from vector</span>tower_selection_filter.erase( tower_selection_filter.begin() + temp_largest_distance_index );    }    <span class="cpp-comment">// Select the filtered towers</span>    <span class="cpp-keyword">for</span>( <span class="cpp-keyword">unsigned</span> i = <span class="cpp-number">0</span>; i &lt; tower_selection_filter.size(); i++ ) {m_tower[ tower_selection_filter ].Select( <span class="cpp-keyword">true</span> );m_tower[ tower_selection_filter ].ShowRange( <span class="cpp-keyword">true</span> );    }}</pre></div><!–ENDSCRIPT–>The program runs fine; I can build towers, sell them, build them again, sell them again etc. It works all fine. However:When MassSelect() is used to select more than 1 towers, followed with SellTower() they DO sell. But &#111;nce I quit the game the following breakpoint pops up, which according to google is caused when certain memory is tried to be deleted more than &#111;nce in a row. Windows has triggered a breakpoint in Game2.exe.This may be due to a corruption of the heap, which indicates a bug in Game2.exe or any of the DLLs it has loaded.<!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre><span class="cpp-comment">/* _WIN64 */</span>   {  retval = HeapFree(_crtheap, <span class="cpp-number">0</span>, pBlock);  <span class="cpp-keyword">if</span> (retval == <span class="cpp-number">0</span>)  { errno = _get_errno_from_oserr(GetLastError());  }   }</pre></div><!–ENDSCRIPT–>When I used to select &#111;nly 1 tower each time, followed by SellTower( const unsigned t_nr ), then the exception doesn't occur upon exit. So there is something wrong in MassSelect() or SellTower(), but I can't seem to find what.Another kind of breakpoint pops up when I build a lot of towers ( around 50 ) and then use MassSelect():Windows has triggered a breakpoint in Game2.exe.This may be due to a corruption of the heap, which indicates a bug in Game2.exe or any of the DLLs it has loaded.crtexe.c<!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre>#<span class="cpp-keyword">else</span>  <span class="cpp-comment">/* WPRFLAG */</span>  __initenv = envp;  mainret = main(argc, argv, envp);<span class="cpp-directive">#endif</span>  <span class="cpp-comment">/* WPRFLAG */</span></pre></div><!–ENDSCRIPT–>The compiler produced this call stack, I'm not sure what to get out of it.. ntdll.dll!7c901230()  [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] ntdll.dll!7c96c943()  ntdll.dll!7c95db9c()  ntdll.dll!7c96cd11()  ntdll.dll!7c96df66()  ntdll.dll!7c94a5d0()  ntdll.dll!7c9268ad()  ntdll.dll!7c91056d()  ntdll.dll!7c96e0d4()  user32.dll!77d48709()  user32.dll!77d48709()  UnlockerHook.dll!10001253()  user32.dll!77d48709()  user32.dll!77d487eb()  user32.dll!77d48832()  user32.dll!77d487ff()  SDL.dll!6810659c()  Game2.exe!_main()  + 0x69 bytesC&gt;Game2.exe!__tmainCRTStartup()  Line 582 + 0x17 bytesC kernel32.dll!7c816d4f()  kernel32.dll!7c8399f3() This never occurs with a few towers, around 10-15.. no matter howmany times I MassSelect() them. And thus I am really confused now.This is what I get in Release build.In debug build I get this (but I guess it's the same problem): HEAP CORRUPTION DETECTED: after block (#451) at 0x0232A628. CRT detected that the application wrote to memory after end of heap buffer. Memory allocated at f:\dd\vctools\crt_bld\self_x86\crt\xlocnum(242).<!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre><span class="cpp-keyword">if</span> (pHead-&gt;szFileName) {_RPT5(_CRT_ERROR, <span class="cpp-literal">"HEAP CORRUPTION DETECTED: after %hs block (#%d) at 0x%p.\n"</span>    <span class="cpp-literal">"CRT detected that the application wrote to memory after end of heap buffer.\n"</span>    _ALLOCATION_FILE_LINENUM,    szBlockUseName[_BLOCK_TYPE(pHead-&gt;nBlockUse)],    pHead-&gt;lRequest,    (BYTE *) pbData(pHead),    pHead-&gt;szFileName,    pHead-&gt;nLine); }</pre></div><!–ENDSCRIPT–>The whole program is basically finished except for these errors that I found yesterday (sadly but also fortunately). Anyhow, I've been struggling with this vector for many hours now and I hope someone could explain to me what I am doing wrong. Thank you for your time and effort!
  I have always had problems calling erase on a vector many times in one frame (never found the reason why). Erasing in the middle of a vector is extremely expensive and a list would be better if order matters or use the vector swap trick if it doesn't (copy the last entry into the entry you want to delete and pop_back) as it is a lot cheaper then calling erase.Example (as an added bonus, I got rid of the while loop for optimisation)    // Sell selected towers    while( temp_sell_counter != temp_selected_towers )for( unsigned i = 0; i < m_tower.size(); i++ )if( m_tower.GetSelected() ) {<br>   <span class="cpp-comment">// Sell tower</span><br>   gold += m_tower.GetUpgradeTotalSpent(); <span class="cpp-comment">// 100% refund</span><br>m_tower.erase( m_tower.begin() + i );<br>temp_sell_counter++;<span class="cpp-comment">// Increase counter</span><br>i = m_tower.size() + <span class="cpp-number">1</span>;<span class="cpp-comment">// End loop</span><br>    }<br><br></pre></div><!–ENDSCRIPT–><br><br>To:<br>    <br><!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre><span class="cpp-comment">// Sell selected towers</span><br><span class="cpp-keyword">unsigned</span> i = <span class="cpp-number">0</span>;<br><span class="cpp-keyword">while</span>( i &lt; m_tower.size() &amp;&amp; temp_sell_counter &lt; temp_selected_towers ) {<br>    <span class="cpp-keyword">if</span>( m_tower.GetSelected() ) {<br>   <span class="cpp-comment">// Sell tower</span><br>   gold += m_tower.GetUpgradeTotalSpent(); <span class="cpp-comment">// 100% refund</span><br>m_tower = m_tower.back();<br>m_tower.pop_back();<br>temp_sell_counter++;<span class="cpp-comment">// Increase counter</span><br>    }<br>    <span class="cpp-keyword">else</span> {<br>i+=<span class="cpp-number">1</span>;<br>    }<br>}<br><br></pre></div><!–ENDSCRIPT–> ;  It's code like this that should never have come into existence.    for( unsigned i = 0; i < m_tower.size(); i++ )  // Rectangle going from topleft to bottomright   if( ( m_mass_selector.rect.topleft.x < m_tower.GetOffset().rect.bottomright.x &amp;&amp; m_mass_selector.rect.topleft.y &lt; m_tower.GetOffset().rect.bottomright.y &amp;&amp; <br> m_mass_selector.rect.bottomright.x &gt; m_tower.GetOffset().rect.topleft.x &amp;&amp; m_mass_selector.rect.bottomright.y &gt; m_tower.GetOffset().rect.topleft.y ) || <br>  <span class="cpp-comment">// Rectangle going from topright to bottomleft</span><br>    ( m_mass_selector.rect.topleft.x &gt; m_tower.GetOffset().rect.bottomright.x &amp;&amp; m_mass_selector.rect.topleft.y &lt; m_tower.GetOffset().rect.bottomright.y &amp;&amp; <br> m_mass_selector.rect.bottomright.x &lt; m_tower.GetOffset().rect.topleft.x &amp;&amp; m_mass_selector.rect.bottomright.y &gt; m_tower.GetOffset().rect.topleft.y ) )<br>    <span class="cpp-comment">// Add index of tower to vector</span><br>    tower_selection_filter.push_back( i );<br><br></pre></div><!–ENDSCRIPT–>There's absolutely no reason that code has to index into the m_tower vector 8 times, and call GetOffset 8 times.<br>At the very least start by declaring a reference to that rect:<!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre><br>    <span class="cpp-keyword">for</span>( <span class="cpp-keyword">unsigned</span> i = <span class="cpp-number">0</span>; i &lt; m_tower.size(); i++ )<br>    {<br>   RECT &amp;r = m_tower.GetOffset().rect;<br>  <span class="cpp-comment">// Rectangle going from topleft to bottomright</span><br>   <span class="cpp-keyword">if</span>( ( m_mass_selector.rect.topleft.x &lt; r.bottomright.x &amp;&amp; m_mass_selector.rect.topleft.y &lt; r.bottomright.y &amp;&amp; <br> m_mass_selector.rect.bottomright.x &gt; r.topleft.x &amp;&amp; m_mass_selector.rect.bottomright.y &gt; r.topleft.y ) || <br>  <span class="cpp-comment">// Rectangle going from topright to bottomleft</span><br>    ( m_mass_selector.rect.topleft.x &gt; r.bottomright.x &amp;&amp; m_mass_selector.rect.topleft.y &lt; r.bottomright.y &amp;&amp; <br> m_mass_selector.rect.bottomright.x &lt; r.topleft.x &amp;&amp; m_mass_selector.rect.bottomright.y &gt; r.topleft.y ) )<br>    <span class="cpp-comment">// Add index of tower to vector</span><br>    tower_selection_filter.push_back( i );<br>    }<br><br></pre></div><!–ENDSCRIPT–>If you are using a RECT structure then bits like bottomright.x are the same as just right, so you can do that too.<br>Then the next step is to put that entire if-expression into its own function as that'll shorten it furthur as well. Or at least using a reference for m_mass_selector.rect as well would shorten it more.<br><br>This might not be someone directly pointing out where the bug is, but with so much duplication like that it's so easy to make a simple typo and never see it. You'd be surprised how often after tidying up code like that that the bug just jumps out at you.;  Does your Tower class dynamically allocate memory?If so do you implement the copy constructor properly?   ;  Hello again, first of all thank you for your replies.To yaustar: Placing the element on the end of the vector and then removing it worked. It seems you were right saying that erasing in the middle of the vector is expensive, but I still don't get why the error occured. I guess I need more understanding of the erasing, and probably other things too, (though I started programming only a few months ago so can't get it all in one shot), anyhow thanks!Edit: Seems I was mistaken, the error still occurs when I exit the game. The exception didn't pop the first time I tested for some reason.. weirdTo iMalc: Making the code smaller using references did point out mistakes as you said might have happened. I find this tip very useful. Thanks!To Black Knight: I did overload the copy constructor, which basically does memberwise copying. The tower class has a gunner class, and the gunner class has a vector of bullets. So, yes, there is other dynamically allocated memory in the tower class. As I said, the copy constructor of the tower class does memberwise copying and re-calculates some gunner variables by calling a setter function. Also copying the gunner is done with the gunner copy constructor, which also does only memberwise copying (the bullet vector is also copied with the membership operator).For now there still a bug when /only/ mass-selecting the towers. I'm guessing something is wrong with the local vector in the MassSelect() function. Unhandled exception at 0x7855ac1c (msvcr90.dll) in Game2.exe: 0xC0000005: Access violation writing location 0x4067c000.The breakpoint was in memcpy.asm, lots of assembly code there but got no clue about them.void TowerHandler::MassSelect() {// Temporary variables    std::vector<unsigned> tower_selection_filter;    for( unsigned i = 0; i < m_tower.size(); i++ )// Look if tower is inside mass selectorif( WithinMassSelector( m_tower.GetOffset().rect, m_mass_selector.rect ) )<br>    tower_selection_filter.push_back( i );<span class="cpp-comment">// Add tower index to vector</span><br>    <span class="cpp-keyword">else</span> { <span class="cpp-comment">// Unselect towers outside mass selector</span><br>m_tower.Select( <span class="cpp-keyword">false</span> );<br>m_tower.ShowRange( <span class="cpp-keyword">false</span> );<br>    }<br><br>    <span class="cpp-comment">// Filter only the smallest distances in vector, remove others</span><br>    <span class="cpp-keyword">while</span>( tower_selection_filter.size() &gt; MAX_SELECTABLE_TOWERS ) {<br><span class="cpp-comment">// Temp variables</span><br><span class="cpp-keyword">unsigned</span> temp_largest_distance_index = <span class="cpp-number">0</span>;<br><span class="cpp-keyword">double</span> temp_largest_distance = <span class="cpp-number">0</span>;<br><br><span class="cpp-comment">// Find most distant distance</span><br><span class="cpp-keyword">for</span>( <span class="cpp-keyword">unsigned</span> i = <span class="cpp-number">0</span>; i &lt; tower_selection_filter.size(); i++ )<br>    <span class="cpp-keyword">if</span>( CalcDistance( m_mass_selector_middle, m_tower[ tower_selection_filter ].GetGunner().GetOffset().circ.middle ) &gt; temp_largest_distance ) {<br><span class="cpp-comment">// Remember tower</span><br>temp_largest_distance = CalcDistance( m_mass_selector_middle, m_tower[ tower_selection_filter ].GetGunner().GetOffset().circ.middle );<br>temp_largest_distance_index = i;<br>    }<br><br><span class="cpp-comment">// Remove most distant tower index from vector</span><br>   <span class="cpp-comment">// Getting same exception with 'erase', 'swap + pop_back' and 'back + pop back</span><br><span class="cpp-comment">//std::swap( tower_selection_filter[ temp_largest_distance_index ], tower_selection_filter[ tower_selection_filter.size() - 1 ] );</span><br>tower_selection_filter[ temp_largest_distance_index ] = tower_selection_filter.back();<br>tower_selection_filter.pop_back();<br><span class="cpp-comment">//tower_selection_filter.erase( tower_selection_filter.begin() + temp_largest_distance_index );</span><br>    }<br><br>    <span class="cpp-comment">// Select the filtered towers</span><br>    <span class="cpp-keyword">for</span>( <span class="cpp-keyword">unsigned</span> i = <span class="cpp-number">0</span>; i &lt; tower_selection_filter.size(); i++ ) {<br>m_tower[ tower_selection_filter ].Select( <span class="cpp-keyword">true</span> );<br>m_tower[ tower_selection_filter ].ShowRange( <span class="cpp-keyword">true</span> );<br>    }<br>}<br><br><br><br></pre></div><!–ENDSCRIPT–><br><br>I'll be trying to fix this the rest of the day and will update if I find something new.<br><br>Thanks.;Quote:Original post by LaschaThe tower class has a gunner class, and the gunner class has a vector of bullets.What happens to the gunner and the bullets when you destroy a tower (for example, by selling it)?Either way, personally I find that once my classes become 'heavy' or more complicated than POD's (Plain Old Data), I'd rather store pointers in a vector than actual instances. This keeps the vector light-weight and fast to work with, avoids copying potentially expensive objects (only pointer values are copied), and also enables you to use pointers/references to the actual objects without the risk of these becoming invalidated after the vector has changed. Also, you can save yourself the hassle of writing a copy constructor and assignment operator yourself (be aware: if you leave them out, the compiler will generate default ones for you, so to ensure that they won't be used, declare them as private and leave them without implementation).Of course, storing raw pointers is inconvenient, because you'll have to manage the memory lifetime yourself again. However, storing smart pointers instead will solve that problem.Bytheway, you may want to write some utility functions for your rectangle class/struct, to avoid duplicating that rectangle collision check:m_mass_selector.rect.contains(m_tower.GetOffset().rect);Quote: What happens to the gunner and the bullets when you destroy a tower (for example, by selling it)? Good question. I did ask myself that too. And I thought the vector itself handles the memory deletion. So my destructors there are empty. One thing that might have a role in this is that my TowerHandler class (which has the Tower vector) is a pointer object in the Game class. It is deleted when for example the game state changes to 'Map Crafting' state and everything un-initializes fine; all towers get removed etc etc. And when I go back into 'Playing' state a new TowerHandler is created. The weird thing is that the exception with the SellTower() occurs /after/ the main() loop, where there destructor for the Game class is called. That destructors deletes Towerhandler only if the state is on 'Playing'. It could be though that the memory dis-management starts when the towers are created. Maybe the Tower constructor as parameter is the problem?Is it perhaps useful if I post my classes with their constructors?Edit: Switched back to debug mode and instead of getting an exception I get weird things like random rectangle with a random color appears on the screen.. as if the tower data is corrupt and shows a random values for his appearance. Greetings.   ;Quote:Original post by LaschaGood question. I did ask myself that too. And I thought the vector itself handles the memory deletion. So my destructors there are empty.Can you show the headers of your Tower, Gunner and Bullet classes? Things are probably indeed being taken care of automatically - and that's also why I pointed this out: why do towers own they bullets they have shot? If you destroy a tower, that means that all its bullets are destroyed as well. That's probably not what you want (imagine a cannon-ball suddenly disappearing because the tower that shot it is being taken down...).Quote:Is it perhaps useful if I post my classes with their constructors?Constructors, destructors, and snippets of usage, yes. Oh, and class definition too.   ;Quote: Also, you can save yourself the hassle of writing a copy constructor and assignment operator yourself (be aware: if you leave them out, the compiler will generate default ones for you, so to ensure that they won't be used, declare them as private and leave them without implementation). These are the copy contructors I was using. I commented them out and the call stack in the vector seemed to have changed; no more random (corrupt) data is created and also _Destroy() isn't called anymore like before (which is pretty weird right after a push_back ). Bullet::Bullet( const Bullet &b ) { // Copy stuffm_offset = b.m_offset;m_speed = b.m_speed;m_direction = b.m_direction;m_target = b.m_target;}Gunner::Gunner( const Gunner &g ) {// Copy stuffm_offset = g.m_offset;m_bullet = g.m_bullet;m_specs = g.m_specs;m_direction = g.m_direction;m_shoot_delay = g.m_shoot_delay;m_target_type = g.m_target_type;m_target_type_modifier = g.m_target_type_modifier;}Tower::Tower( const Tower &t ) {// Copy stuffm_name = t.m_name; // Tower namem_level = t.m_level;m_offset = t.m_offset;// Tower texture and offsetm_gunner = Gunner( t.m_gunner );// Tower Gunnerm_is_selected = t.m_is_selected;// For selectionm_show_range_radius = t.m_show_range_radius;m_show_range = t.m_show_range;m_upgrade_gold_cost = t.m_upgrade_gold_cost;m_upgrade_total_spent = t.m_upgrade_total_spent;SetTowerSpecs( m_level );}I think I am one step closer to fixing my problem.;  Class definitions (header files) please? It's hard to tell what types you're using without that information. ;)   