Revision: 2439
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2439&view=rev
Author:   ulteq
Date:     2012-02-03 15:52:26 +0000 (Fri, 03 Feb 2012)
Log Message:
-----------
fixed several warnings:
- null pointer dereferencing
- invalid array indexing
- possible memory leaking
- array initialization

Modified Paths:
--------------
    trunk/source/main/framework/AppStateManager.cpp
    trunk/source/main/gameplay/CacheSystem.cpp
    trunk/source/main/gameplay/RoRFrameListener.cpp
    trunk/source/main/gameplay/RoRFrameListener.h
    trunk/source/main/gameplay/Savegame.cpp
    trunk/source/main/gameplay/road2.cpp
    trunk/source/main/gfx/Skidmark.cpp
    trunk/source/main/gfx/WaterOld.cpp
    trunk/source/main/gfx/vidcam.cpp
    trunk/source/main/gui/Console.cpp
    trunk/source/main/gui/TruckHUD.cpp
    trunk/source/main/gui/gui_menu.cpp
    trunk/source/main/network/IRC/dcc.c++
    trunk/source/main/network/IRC/libircclient.cpp
    trunk/source/main/network/IRCWrapper.cpp
    trunk/source/main/network/NetworkStreamManager.cpp
    trunk/source/main/physics/Beam.cpp
    trunk/source/main/physics/BeamFactory.cpp
    trunk/source/main/physics/air/turbojet.cpp
    trunk/source/main/physics/collision/collisions.cpp
    trunk/source/main/scripting/GameScript.cpp
    trunk/source/main/utils/CollisionTools.cpp
    trunk/source/main/utils/InputEngine.cpp
    trunk/source/main/utils/InputEngine.h
    trunk/source/main/utils/MeshObject.cpp

Modified: trunk/source/main/framework/AppStateManager.cpp
===================================================================
--- trunk/source/main/framework/AppStateManager.cpp     2012-02-03 03:52:47 UTC 
(rev 2438)
+++ trunk/source/main/framework/AppStateManager.cpp     2012-02-03 15:52:26 UTC 
(rev 2439)
@@ -106,13 +106,8 @@
        unsigned long timeSinceLastFrame = 1;
        unsigned long startTime          = 0;
        unsigned long minTimePerFrame    = 0;
-       unsigned long maxFPS = ISETTING("Max FPS", 0);
+       unsigned long maxFPS             = ISETTING("Max FPS", 0);
 
-       
-       // useful or not?
-       Ogre::Root::getSingleton().setFrameSmoothingPeriod(4);
-
-
        if (maxFPS)
        {
                minTimePerFrame = 1000 / maxFPS;

Modified: trunk/source/main/gameplay/CacheSystem.cpp
===================================================================
--- trunk/source/main/gameplay/CacheSystem.cpp  2012-02-03 03:52:47 UTC (rev 
2438)
+++ trunk/source/main/gameplay/CacheSystem.cpp  2012-02-03 15:52:26 UTC (rev 
2439)
@@ -1451,35 +1451,34 @@
                }
 
                size_t fsize = 0;
-               char *buffer=0;
+               char *buffer = 0;
                {
                        DataStreamPtr 
ds=ResourceGroupManager::getSingleton().openResource(minifn, group);
                        fsize = ds->size();
                        buffer = (char*)malloc(fsize);
                        memset(buffer, 0, fsize);
                        size_t read = ds->read(buffer, fsize);
-                       if(read!=fsize)
+                       if(read != fsize)
                                return;
                }
 
                bool written=false;
-               FILE *f = fopen(dst.c_str(),"wb");
-               if(f)
+               if (buffer)
                {
-                       fwrite(buffer, 1, fsize,  f);
-                       fclose(f);
-                       written=true;
-               }
-               if(buffer)
+                       FILE *f = fopen(dst.c_str(),"wb");
+                       if (f)
+                       {
+                               fwrite(buffer, 1, fsize,  f);
+                               fclose(f);
+                               written=true;
+                       }
                        free(buffer);
-               if(written)
+               }
+               if(!written)
                {
-                       //setProgress(counter/(float)size, "Caching Mini Files 
...");
-               } else
-               {
                        deleteFileCache(const_cast<char*>(dst.c_str()));
                }
-       }catch(Ogre::Exception& e)
+       } catch(Ogre::Exception& e)
        {
                LOG("error while generating File cache: " + 
e.getFullDescription());
                LOG("trying to continue ...");
@@ -1780,47 +1779,39 @@
 void CacheSystem::readCategoryTitles()
 {
        LOG("Loading category titles from "+configlocation+"categories.cfg");
-       FILE *fd;
-       char line[1024];
        String filename = configlocation + String("categories.cfg");
-       fd=fopen(filename.c_str(), "r");
-       if(!fd)
+       FILE *fd = fopen(filename.c_str(), "r");
+       if (!fd)
        {
                LOG("error opening file: "+configlocation+"categories.cfg");
                return;
        }
+       char line[1024] = {0};
        while (!feof(fd))
        {
-               int res = fscanf(fd," %[^\n\r]",line);
-               if (line[0]==';')
-               {
-                       continue;
-               };
-               int number=0;
-               char title[256];
+               int res = fscanf(fd, " %[^\n\r]", line);
+               if (line[0] == ';')     continue;
+               int number = 0;
+               char title[256] = {0};
                const char delimiters[] = ",";
-               char *token, str_work[1024]="";
+               char str_work[1024] = {0};
+
                strncpy(str_work, line, 1024);
-               token = strtok(str_work, delimiters);
-               if(token != NULL)
-                       number = atoi(token);
-               else
-                       continue;
 
+               char *token = strtok(str_work, delimiters);
+               if (token == NULL) continue;
+               number = atoi(token);
                token = strtok(NULL, delimiters);
-               if(token != NULL)
-               {
-                       //strip spaces at the beginning
-                       while(*token == ' ') token++;
-                       strncpy(title, token, 255);
-               }
-               else
-                       continue;
+               if (token == NULL) continue;
+               //strip spaces at the beginning
+               while(*token == ' ') token++;
+               strncpy(title, token, 255);
+
                //LOG(String(title));
                Category_Entry ce;
                ce.title = Ogre::String(title);
                ce.number = number;
-               if(!ce.title.empty())
+               if (!ce.title.empty())
                        categories[number] = ce;
        }
        fclose(fd);
@@ -1845,15 +1836,14 @@
 bool CacheSystem::checkResourceLoaded(Ogre::String &filename, Ogre::String 
&group)
 {
        // check if we already loaded it via ogre ...
-       bool exists = 
ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(filename);
-       if(exists)
+       if 
(ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(filename))
        {
                group = 
ResourceGroupManager::getSingleton().findGroupContainingResource(filename);
                return true;
        }
 
        std::vector<Cache_Entry>::iterator it;
-       //int counter=0;
+
        for(it = entries.begin(); it != entries.end(); it++)
        {
                // case insensitive comparison
@@ -1863,13 +1853,13 @@
                StringUtil::toLowerCase(fname);
                StringUtil::toLowerCase(filename_lower);
                StringUtil::toLowerCase(fname_without_uid_lower);
-               if(fname == filename_lower || fname_without_uid_lower == 
filename_lower)
+               if (fname == filename_lower || fname_without_uid_lower == 
filename_lower)
                {
                        // we found the file, load it
                        filename = it->fname;
                        bool res = checkResourceLoaded(*it);
                        bool exists = 
ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(filename);
-                       if(!exists)
+                       if (!exists)
                                return false;
                        group = 
ResourceGroupManager::getSingleton().findGroupContainingResource(filename);
                        return res;

Modified: trunk/source/main/gameplay/RoRFrameListener.cpp
===================================================================
--- trunk/source/main/gameplay/RoRFrameListener.cpp     2012-02-03 03:52:47 UTC 
(rev 2438)
+++ trunk/source/main/gameplay/RoRFrameListener.cpp     2012-02-03 15:52:26 UTC 
(rev 2439)
@@ -697,7 +697,7 @@
        {
                //BOAT GUI
                int fsp = curr_truck->free_screwprop;
-               //throtles
+               //throttles
                
ow->bthro1->setTop(ow->thrtop+ow->thrheight*(0.5-curr_truck->screwprops[0]->getThrottle()/2.0)-1.0);
                if (fsp>1)
                        
ow->bthro2->setTop(ow->thrtop+ow->thrheight*(0.5-curr_truck->screwprops[1]->getThrottle()/2.0)-1.0);
@@ -1413,22 +1413,21 @@
                return;
 
        //FILE *fd;
-       char fname[1024];
-       char oname[1024];
-       char mesh[1024];
-       char line[1024];
-       float scx, scy, scz;
-       float lx, hx, ly, hy, lz, hz;
-       float srx, sry, srz;
-       float drx, dry, drz;
-       float fcx, fcy, fcz;
+       char fname[1024] = {};
+       char oname[1024] = {};
+       char mesh[1024] = {};
+       char line[1024] = {};
+       char collmesh[1024] = {};
+       float scx = 0, scy = 0, scz = 0;
+       float lx = 0, hx = 0, ly = 0, hy = 0, lz = 0, hz = 0;
+       float srx = 0, sry = 0, srz = 0;
+       float drx = 0, dry = 0, drz = 0;
+       float fcx = 0, fcy = 0, fcz = 0;
        bool forcecam=false;
-       char collmesh[1024];
-       Quaternion rotation;
        bool ismovable=false;
 
        int event_filter = EVENT_ALL;
-       rotation=Quaternion(Degree(rx), Vector3::UNIT_X)*Quaternion(Degree(ry), 
Vector3::UNIT_Y)*Quaternion(Degree(rz), Vector3::UNIT_Z);
+       Quaternion rotation = Quaternion(Degree(rx), 
Vector3::UNIT_X)*Quaternion(Degree(ry), Vector3::UNIT_Y)*Quaternion(Degree(rz), 
Vector3::UNIT_Z);
 
        // try to load with UID first!
        String odefgroup = "";
@@ -2227,10 +2226,9 @@
                        else //we are in a vehicle
                        {
                                // get commands
-                               int i;
-// -- maxbe here we should define a maximum numbers per trucks. Some trucks 
does not have that much commands
-// -- available, so why should we iterate till MAX_COMMANDS?
-                               for (i=1; i<=MAX_COMMANDS; i++)
+                               // -- here we should define a maximum numbers 
per trucks. Some trucks does not have that much commands
+                               // -- available, so why should we iterate till 
MAX_COMMANDS?
+                               for (int i=1; i<=MAX_COMMANDS; i++)
                                {
                                        float oldVal = 
curr_truck->commandkey[i].commandValue;
                                        
@@ -2790,16 +2788,14 @@
                                        //reverse
                                        if 
(INPUTENGINE.getEventBoolValueBounce(EV_AIRPLANE_REVERSE))
                                        {
-                                               int i;
-                                               for (i=0; 
i<curr_truck->free_aeroengine; i++)
+                                               for (int i=0; 
i<curr_truck->free_aeroengine; i++)
                                                        
curr_truck->aeroengines[i]->toggleReverse();
                                        }
 
                                        // toggle engines
                                        if 
(INPUTENGINE.getEventBoolValueBounce(EV_AIRPLANE_TOGGLE_ENGINES))
                                        {
-                                               int i;
-                                               for (i=0; 
i<curr_truck->free_aeroengine; i++)
+                                               for (int i=0; 
i<curr_truck->free_aeroengine; i++)
                                                        
curr_truck->aeroengines[i]->flipStart();
                                        }
 
@@ -2861,36 +2857,32 @@
                                        }
                                        if 
(INPUTENGINE.getEventBoolValueBounce(EV_AIRPLANE_THROTTLE_DOWN, 0.1f))
                                        {
-                                               //throtle down
-                                               int i;
-                                               for (i=0; 
i<curr_truck->free_aeroengine; i++)
+                                               //throttle down
+                                               for (int i=0; 
i<curr_truck->free_aeroengine; i++)
                                                        
curr_truck->aeroengines[i]->setThrottle(curr_truck->aeroengines[i]->getThrottle()-0.05);
                                        }
                                        if 
(INPUTENGINE.getEventBoolValueBounce(EV_AIRPLANE_THROTTLE_UP, 0.1f))
                                        {
-                                               //throtle up
-                                               int i;
-                                               for (i=0; 
i<curr_truck->free_aeroengine; i++)
+                                               //throttle up
+                                               for (int i=0; 
i<curr_truck->free_aeroengine; i++)
                                                        
curr_truck->aeroengines[i]->setThrottle(curr_truck->aeroengines[i]->getThrottle()+0.05);
                                        }
 
                                        if 
(INPUTENGINE.getEventBoolValueBounce(EV_AIRPLANE_THROTTLE_NO, 0.1f))
                                        {
-                                               // no throtle
-                                               int i;
-                                               for (i=0; 
i<curr_truck->free_aeroengine; i++)
+                                               // no throttle
+                                               for (int i=0; 
i<curr_truck->free_aeroengine; i++)
                                                        
curr_truck->aeroengines[i]->setThrottle(0);
                                        }
                                        if 
(INPUTENGINE.getEventBoolValueBounce(EV_AIRPLANE_THROTTLE_FULL, 0.1f))
                                        {
-                                               // full throtle
-                                               int i;
-                                               for (i=0; 
i<curr_truck->free_aeroengine; i++)
+                                               // full throttle
+                                               for (int i=0; 
i<curr_truck->free_aeroengine; i++)
                                                        
curr_truck->aeroengines[i]->setThrottle(1);
                                        }
                                        if (curr_truck->autopilot)
                                        {
-                                               for (i=0; 
i<curr_truck->free_aeroengine; i++)
+                                               for (int i=0; 
i<curr_truck->free_aeroengine; i++)
                                                        
curr_truck->aeroengines[i]->setThrottle(curr_truck->autopilot->getThrottle(curr_truck->aeroengines[i]->getThrottle(),
 dt));
                                        }
 
@@ -2912,16 +2904,14 @@
                                        }
                                        if 
(INPUTENGINE.getEventBoolValueBounce(EV_BOAT_THROTTLE_DOWN, 0.1f))
                                        {
-                                               //throtle down
-                                               int i;
-                                               for (i=0; 
i<curr_truck->free_screwprop; i++)
+                                               //throttle down
+                                               for (int i=0; 
i<curr_truck->free_screwprop; i++)
                                                        
curr_truck->screwprops[i]->setThrottle(curr_truck->screwprops[i]->getThrottle()-0.05);
                                        }
                                        if 
(INPUTENGINE.getEventBoolValueBounce(EV_BOAT_THROTTLE_UP, 0.1f))
                                        {
-                                               //throtle up
-                                               int i;
-                                               for (i=0; 
i<curr_truck->free_screwprop; i++)
+                                               //throttle up
+                                               for (int i=0; 
i<curr_truck->free_screwprop; i++)
                                                        
curr_truck->screwprops[i]->setThrottle(curr_truck->screwprops[i]->getThrottle()+0.05);
                                        }
 
@@ -2939,23 +2929,21 @@
                                        }
                                        
if(INPUTENGINE.isEventDefined(EV_BOAT_STEER_LEFT_AXIS) && 
INPUTENGINE.isEventDefined(EV_BOAT_STEER_RIGHT_AXIS))
                                        {
-                                               float tmp_steer_left = 
INPUTENGINE.getEventValue(EV_BOAT_STEER_LEFT_AXIS);
-                                               float tmp_steer_right = 
INPUTENGINE.getEventValue(EV_BOAT_STEER_RIGHT_AXIS);
-                                               float sum_steer = 
(tmp_steer_left - tmp_steer_right);
+                                               tmp_steer_left = 
INPUTENGINE.getEventValue(EV_BOAT_STEER_LEFT_AXIS);
+                                               tmp_steer_right = 
INPUTENGINE.getEventValue(EV_BOAT_STEER_RIGHT_AXIS);
+                                               sum_steer = (tmp_steer_left - 
tmp_steer_right);
                                                for (int i=0; 
i<curr_truck->free_screwprop; i++)
                                                        
curr_truck->screwprops[i]->setRudder(sum_steer);
                                        }
                                        if 
(INPUTENGINE.getEventBoolValueBounce(EV_BOAT_CENTER_RUDDER, 0.1f))
                                        {
-                                               int i;
-                                               for (i=0; 
i<curr_truck->free_screwprop; i++)
+                                               for (int i=0; 
i<curr_truck->free_screwprop; i++)
                                                        
curr_truck->screwprops[i]->setRudder(0);
                                        }
 
                                        if 
(INPUTENGINE.getEventBoolValueBounce(EV_BOAT_REVERSE))
                                        {
-                                               int i;
-                                               for (i=0; 
i<curr_truck->free_screwprop; i++)
+                                               for (int i=0; 
i<curr_truck->free_screwprop; i++)
                                                        
curr_truck->screwprops[i]->toggleReverse();
                                        }
                                }
@@ -3313,38 +3301,39 @@
                        int current_truck = 
BeamFactory::getSingleton().getCurrentTruckNumber();
                        int free_truck    = 
BeamFactory::getSingleton().getTruckCount();
                        Beam **trucks     = 
BeamFactory::getSingleton().getTrucks();
-                       if (current_truck==-1)
+                       if (current_truck == -1)
                        {
                                //find the nearest truck
-                               int i;
-                               float mindist=1000.0;
-                               int minindex=-1;
-                               for (i=0; i<free_truck; i++)
+                               float mindist   =  1000.0;
+                               int   minindex  = -1;
+                               for (int i=0; i<free_truck; i++)
                                {
                                        if (!trucks[i]) continue;
-                                       if (!trucks[i]->driveable)
-
-                                               continue;
+                                       if (!trucks[i]->driveable) continue;
                                        if (trucks[i]->cinecameranodepos[0]==-1)
                                        {
                                                LOG("cinecam missing, cannot 
enter truck!");
                                                continue;
                                        }
-                                       float 
len=(trucks[i]->nodes[trucks[i]->cinecameranodepos[0]].AbsPosition-(person->getPosition()+Vector3(0.0,
 2.0, 0.0))).length();
-                                       if (len<mindist)
+                                       float len = 
(trucks[i]->nodes[trucks[i]->cinecameranodepos[0]].AbsPosition-(person->getPosition()+Vector3(0.0,
 2.0, 0.0))).length();
+                                       if (len < mindist)
                                        {
                                                mindist=len;
                                                minindex=i;
                                        }
                                }
-                               if (mindist<20.0) 
BeamFactory::getSingleton().setCurrentTruck(minindex);
+                               if (mindist < 20.0)
+                               {
+                                       
BeamFactory::getSingleton().setCurrentTruck(minindex);
+                               }
                        }
                        else if 
(curr_truck->nodes[curr_truck->cinecameranodepos[0]].Velocity.length()<1)
                        {
                                BeamFactory::getSingleton().setCurrentTruck(-1);
-                       } else
+                       }
+                       else
                        {
-                               curr_truck->brake=curr_truck->brakeforce*0.66;
+                               curr_truck->brake    = curr_truck->brakeforce * 
0.66;
                                mTimeUntilNextToggle = 0.0; //No delay in this 
case: the truck must brake like braking normally
                        }
                }
@@ -5264,8 +5253,7 @@
        // in netmode, dont load other trucks!
        if (!netmode)
        {
-               int i;
-               for (i=0; i<truck_preload_num; i++)
+               for (int i=0; i<truck_preload_num; i++)
                {
                        Beam *b = 
BeamFactory::getSingleton().createLocal(Vector3(truck_preload[i].px, 
truck_preload[i].py, truck_preload[i].pz), truck_preload[i].rotation, 
truck_preload[i].name, 0, truck_preload[i].ismachine, flaresMode, truckconfig, 
0, truck_preload[i].freePosition);
 #ifdef USE_MYGUI
@@ -5390,9 +5378,12 @@
                                position=previousTruck->nodes[0].AbsPosition;
                        }
                }
-               //                      
position.y=hfinder->getHeightAt(position.x,position.z);
-               if(position != Vector3::ZERO) person->setPosition(position);
-               //person->setVisible(true);
+               //position.y=hfinder->getHeightAt(position.x,position.z);
+               if(person && position != Vector3::ZERO)
+               {
+                       person->setPosition(position);
+                       //person->setVisible(true);
+               }
                if(ow) ow->showDashboardOverlays(false, currentTruck);
                if(ow) ow->showEditorOverlay(false);
 #ifdef USE_OPENAL
@@ -5924,8 +5915,7 @@
        //set LOD per truck
        /*
        // TODO: XXX: fix below
-       int i;
-       for (i=0; i<free_truck; i++)
+       for (int i=0; i<free_truck; i++)
        {
                if(!trucks[i]) continue;
                
trucks[i]->setDetailLevel((mCamera->getPosition()-trucks[i]->getPosition()).length()>trucks[i]->fadeDist);

Modified: trunk/source/main/gameplay/RoRFrameListener.h
===================================================================
--- trunk/source/main/gameplay/RoRFrameListener.h       2012-02-03 03:52:47 UTC 
(rev 2438)
+++ trunk/source/main/gameplay/RoRFrameListener.h       2012-02-03 15:52:26 UTC 
(rev 2439)
@@ -402,7 +402,7 @@
        int raceStartTime;
 
        int objcounter;
-       char terrainmap[256];
+       char terrainmap[1024];
 
        Ogre::String terrainUID;
        Road *road;

Modified: trunk/source/main/gameplay/Savegame.cpp
===================================================================
--- trunk/source/main/gameplay/Savegame.cpp     2012-02-03 03:52:47 UTC (rev 
2438)
+++ trunk/source/main/gameplay/Savegame.cpp     2012-02-03 15:52:26 UTC (rev 
2439)
@@ -56,7 +56,7 @@
        FILE *f = fopen(filename.c_str(), "wb");
 
        // wait for engine sync
-       BeamWaitNoLock sync();
+       BEAMLOCK();
 
        // TODO: show error
        if(!f)
@@ -472,8 +472,8 @@
 
                // important: active all vehicles upon loading!
                // they will go sleeping automatically
-               if(t->state != ACTIVATED || t->state != DESACTIVATED)
-                       t->state = DESACTIVATED; // deactivated = active but 
not leading
+               if(t->state > DESACTIVATED)
+                       t->state = DESACTIVATED; // desactivated = active but 
not leading
        }
 
        // try to set the current truck

Modified: trunk/source/main/gameplay/road2.cpp
===================================================================
--- trunk/source/main/gameplay/road2.cpp        2012-02-03 03:52:47 UTC (rev 
2438)
+++ trunk/source/main/gameplay/road2.cpp        2012-02-03 15:52:26 UTC (rev 
2439)
@@ -581,6 +581,7 @@
        //compute normals
        for (i=0; i<(int)nTris; i++)
        {
+               // TODO: fix warning C6011: Dereferencing NULL pointer 
'$S5.covertices'
                Vector3 v1, v2;
                v1=covertices[tris[i*3+1]].vertex-covertices[tris[i*3]].vertex;
                v2=covertices[tris[i*3+2]].vertex-covertices[tris[i*3]].vertex;

Modified: trunk/source/main/gfx/Skidmark.cpp
===================================================================
--- trunk/source/main/gfx/Skidmark.cpp  2012-02-03 03:52:47 UTC (rev 2438)
+++ trunk/source/main/gfx/Skidmark.cpp  2012-02-03 15:52:26 UTC (rev 2439)
@@ -137,7 +137,7 @@
 , mNode(snode)
 , hfinder(hfinder)
 , mDirty(true)
-, lenght(_lenght%2 ? _lenght - (_lenght%2) : _lenght)
+, lenght((_lenght%2) ? (_lenght-(_lenght%2)) : _lenght)
 , bucketCount(bucketCount)
 , wheel(wheel)
 , minDistance(0.1f)
@@ -145,7 +145,6 @@
 , minDistanceSquared(minDistance * minDistance)
 , maxDistanceSquared(maxDistance * maxDistance)
 {
-       if(lenght%2) lenght -= lenght%2; // round it!
 }
 
 Skidmark::~Skidmark()
@@ -159,7 +158,8 @@
        skid.pos=0;
        skid.lastPointAv=start;
        skid.facecounter=0;
-       for(int i=0;i<3;i++) skid.face[i] = Ogre::Vector3::ZERO;
+       skid.face[0] = Ogre::Vector3::ZERO;
+       skid.face[1] = Ogre::Vector3::ZERO;
        skid.colour = ColourValue(Ogre::Math::RangeRandom(0, 100)/100.0f, 
Ogre::Math::RangeRandom(0, 100)/100.0f, Ogre::Math::RangeRandom(0, 100)/100.0f, 
0.8f);
 
 

Modified: trunk/source/main/gfx/WaterOld.cpp
===================================================================
--- trunk/source/main/gfx/WaterOld.cpp  2012-02-03 03:52:47 UTC (rev 2438)
+++ trunk/source/main/gfx/WaterOld.cpp  2012-02-03 15:52:26 UTC (rev 2439)
@@ -93,18 +93,14 @@
        visible=true;
        haswaves=usewaves;
        free_wavetrain=0;
-       FILE *fd;
-       char line[1024];
-       fd=fopen((SSETTING("Config Root", "")+"wavefield.cfg").c_str(), "r");
+       char line[1024] = {};
+       FILE *fd = fopen((SSETTING("Config Root", "")+"wavefield.cfg").c_str(), 
"r");
        if (fd)
        {
                while (!feof(fd))
                {
                        int res = fscanf(fd," %[^\n\r]",line);
-                       if (line[0]==';')
-                       {
-                               continue;
-                       };
+                       if (line[0] == ';') continue;
                        float wl,amp,mx,dir;
                        res = sscanf(line,"%f, %f, %f, %f",&wl,&amp,&mx,&dir);
                        if(res < 4) continue;
@@ -116,10 +112,9 @@
                }
                fclose(fd);
        }
-       //        theCam=camera;
-       int i;
+       //theCam=camera;
        maxampl=0;
-       for (i=0; i<free_wavetrain; i++)
+       for (int i=0; i<free_wavetrain; i++)
        {
                wavetrains[i].wavespeed=1.25*sqrt(wavetrains[i].wavelength);
                maxampl+=wavetrains[i].maxheight;
@@ -136,11 +131,11 @@
        MeshPtr mprt;
        mReflectCam=0;
        mRefractCam=0;
-       //              wbuf=0;
-       //              ColourValue 
fade=camera->getViewport()->getBackgroundColour();
+       //wbuf=0;
+       //ColourValue fade=camera->getViewport()->getBackgroundColour();
        ColourValue fade=mSceneMgr->getFogColour();
 
-       if (mType==WATER_FULL_QUALITY || mType==WATER_FULL_SPEED || 
mType==WATER_REFLECT)
+       if (mType == WATER_FULL_QUALITY || mType == WATER_FULL_SPEED || mType 
== WATER_REFLECT)
        {
                // Check prerequisites first
                const RenderSystemCapabilities* caps = 
Root::getSingleton().getRenderSystem()->getCapabilities();
@@ -162,7 +157,7 @@
                                        "WaterOld effects");
                        }
                }
-               //okay
+               // Ok
                // Define a floor plane mesh
                reflectionPlane.normal = Vector3::UNIT_Y;
                reflectionPlane.d = -wheight+0.15;
@@ -171,7 +166,7 @@
                waterPlane.normal = Vector3::UNIT_Y;
                waterPlane.d = -wheight;
 
-               if (mType==WATER_FULL_QUALITY || mType==WATER_FULL_SPEED)
+               if (mType == WATER_FULL_QUALITY || mType == WATER_FULL_SPEED)
                {
                        TexturePtr rttTex1Ptr = 
TextureManager::getSingleton().createManual("Refraction", 
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 512, 512, 0, 
PF_R8G8B8, TU_RENDERTARGET, new ResourceBuffer());
                        rttTex1 = rttTex1Ptr->getBuffer()->getRenderTarget();

Modified: trunk/source/main/gfx/vidcam.cpp
===================================================================
--- trunk/source/main/gfx/vidcam.cpp    2012-02-03 03:52:47 UTC (rev 2438)
+++ trunk/source/main/gfx/vidcam.cpp    2012-02-03 15:52:26 UTC (rev 2439)
@@ -253,8 +253,8 @@
        {
                int nz=-1, ny=-1, nref=-1, ncam=-1, lookto=-1, texx=256, 
texy=256, crole=-1, cmode=-1;
                float fov=-1.0f, minclip=-1.0f, maxclip=-1.0f, offx=0.0f, 
offy=0.0f, offz=0.0f, rotx=0.0f, roty=0.0f, rotz=0.0f;
-               char materialname[256] = "";
-               char vidCamName[256] = "";
+               char materialname[256] = {};
+               char vidCamName[256] = {};
                
                Ogre::StringVector args;
                int n = truck->parse_args(c, args, 19);

Modified: trunk/source/main/gui/Console.cpp
===================================================================
--- trunk/source/main/gui/Console.cpp   2012-02-03 03:52:47 UTC (rev 2438)
+++ trunk/source/main/gui/Console.cpp   2012-02-03 15:52:26 UTC (rev 2439)
@@ -588,7 +588,7 @@
                } else if(msg == "/as")
                {
                        angelscriptMode = !angelscriptMode;
-                       putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_NOTICE, 
ChatSystem::commandColour + (_L("AngelScript Mode ") + angelscriptMode ? 
_L("enabled") : _L("disabled")), "information.png");
+                       putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_NOTICE, 
ChatSystem::commandColour + _L("AngelScript Mode ") + (angelscriptMode ? 
_L("enabled") : _L("disabled")), "information.png");
                        return;
 
                } else if(msg == "/log")
@@ -977,7 +977,7 @@
                Vector3 pos = 
RoRFrameListener::eflsingleton->person->getPosition();
                putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_REPLY, 
_L("Character position: ") + String("#dd0000") + TOSTRING(pos.x) +  
String("#000000, #00dd00") + TOSTRING(pos.y) + String("#000000, #0000dd") + 
TOSTRING(pos.z), "world.png");
        }
-       else
+       else if (b)
        {
                Vector3 pos = b->getPosition();
                putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_REPLY, 
_L("Vehicle position: ") + String("#dd0000") + TOSTRING(pos.x) +  
String("#000000, #00dd00") + TOSTRING(pos.y) + String("#000000, #0000dd") + 
TOSTRING(pos.z), "world.png");
@@ -994,7 +994,7 @@
        {
                pos = RoRFrameListener::eflsingleton->person->getPosition();
        }
-       else
+       else if (b)
        {
                pos = b->getPosition();
        }
@@ -1011,7 +1011,7 @@
                RoRFrameListener::eflsingleton->person->setPosition(pos);
                putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_REPLY, 
_L("Character position set to: ") + String("#dd0000") + TOSTRING(pos.x) +  
String("#000000, #00dd00") + TOSTRING(pos.y) + String("#000000, #0000dd") + 
TOSTRING(pos.z), "world.png");
        }
-       else
+       else if (b)
        {
                b->resetPosition(pos, false);
                putMessage(CONSOLE_MSGTYPE_INFO, CONSOLE_SYSTEM_REPLY, 
_L("Vehicle position set to: ") + String("#dd0000") + TOSTRING(pos.x) +  
String("#000000, #00dd00") + TOSTRING(pos.y) + String("#000000, #0000dd") + 
TOSTRING(pos.z), "world.png");

Modified: trunk/source/main/gui/TruckHUD.cpp
===================================================================
--- trunk/source/main/gui/TruckHUD.cpp  2012-02-03 03:52:47 UTC (rev 2438)
+++ trunk/source/main/gui/TruckHUD.cpp  2012-02-03 15:52:26 UTC (rev 2439)
@@ -333,7 +333,7 @@
        if(truck->driveable == TRUCK && truck->engine)
        {
                wchar_t rpmstring[256];
-               UTFString rpmsstr = _L("current RPM:");
+               rpmsstr = _L("current RPM:");
                swprintf(rpmstring, 256, L"%ls %.0f / %.0f", 
rpmsstr.asWStr_c_str(), truck->engine->getRPM(), 
truck->engine->getMaxRPM()*1.25);
                descl = 
OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CurrentRPM");
                descl->setCaption(UTFString(rpmstring));
@@ -423,7 +423,7 @@
                else if(truck->driveable == BOAT)
        {
                wchar_t velostring[256];
-               Vector3 
hdir=truck->nodes[truck->cameranodepos[0]].RelPosition-truck->nodes[truck->cameranodedir[0]].RelPosition;
+               
hdir=truck->nodes[truck->cameranodepos[0]].RelPosition-truck->nodes[truck->cameranodedir[0]].RelPosition;
                hdir.normalise();
                float 
velocity=hdir.dotProduct(truck->nodes[truck->cameranodepos[0]].Velocity)*1.9438;
 
@@ -458,7 +458,7 @@
                // update commands
 
                //clear them first
-               for(int i=1;i<=COMMANDS_VISIBLE;i++)
+               for(int i=1; i<=COMMANDS_VISIBLE; i++)
                {
                        char commandOverlayID[256];
                        sprintf(commandOverlayID, 
"tracks/TruckInfoBox/Command%d", i); // no wchar needed
@@ -467,7 +467,7 @@
                }
 
                int j = 0;
-               for(int i=1,j=0;i<MAX_COMMANDS && j<COMMANDS_VISIBLE;i+=2)
+               for(int i=1; i<MAX_COMMANDS && j<COMMANDS_VISIBLE; i+=2)
                {
                        if (truck->commandkey[i].description.size() == 0)
                                continue;

Modified: trunk/source/main/gui/gui_menu.cpp
===================================================================
--- trunk/source/main/gui/gui_menu.cpp  2012-02-03 03:52:47 UTC (rev 2438)
+++ trunk/source/main/gui/gui_menu.cpp  2012-02-03 15:52:26 UTC (rev 2439)
@@ -245,7 +245,7 @@
                {
                        if(!trucks[i]) continue;
 
-                       char tmp[255] = "";
+                       char tmp[255] = {};
                        sprintf(tmp, "[%d] %s", i, 
trucks[i]->realtruckname.c_str());
 
                        vehiclesMenu->addItem(String(tmp), 
MyGUI::MenuItemType::Normal, "TRUCK_"+TOSTRING(i));

Modified: trunk/source/main/network/IRC/dcc.c++
===================================================================
--- trunk/source/main/network/IRC/dcc.c++       2012-02-03 03:52:47 UTC (rev 
2438)
+++ trunk/source/main/network/IRC/dcc.c++       2012-02-03 15:52:26 UTC (rev 
2439)
@@ -802,8 +802,13 @@
        int err;
        long filesize;
 
-       if ( !session || !dccid || !filename || !callback )
+       if ( !session )
        {
+               return 1;
+       }
+
+       if ( !dccid || !filename || !callback )
+       {
                session->lasterror = LIBIRC_ERR_INVAL;
                return 1;
        }

Modified: trunk/source/main/network/IRC/libircclient.cpp
===================================================================
--- trunk/source/main/network/IRC/libircclient.cpp      2012-02-03 03:52:47 UTC 
(rev 2438)
+++ trunk/source/main/network/IRC/libircclient.cpp      2012-02-03 15:52:26 UTC 
(rev 2439)
@@ -522,7 +522,7 @@
        }
        else
        {
-               if ( !strcmp (command, "NICK") )
+               if ( command && !strcmp (command, "NICK") )
                {
                        /*
                         * If we're changed our nick, we should save it.
@@ -835,7 +835,7 @@
 
 int irc_send_raw (irc_session_t * session, const char * format, ...)
 {
-       char buf[1024];
+       char buf[1024] = {};
        va_list va_alist;
 
        if ( session->state != LIBIRC_STATE_CONNECTED )

Modified: trunk/source/main/network/IRCWrapper.cpp
===================================================================
--- trunk/source/main/network/IRCWrapper.cpp    2012-02-03 03:52:47 UTC (rev 
2438)
+++ trunk/source/main/network/IRCWrapper.cpp    2012-02-03 15:52:26 UTC (rev 
2439)
@@ -377,7 +377,7 @@
 
 void dump_event (irc_session_t * session, const char * event, const char * 
origin, const char ** params, unsigned int count)
 {
-       char buf[512];
+       char buf[512] = {};
        unsigned int cnt;
 
        buf[0] = '\0';

Modified: trunk/source/main/network/NetworkStreamManager.cpp
===================================================================
--- trunk/source/main/network/NetworkStreamManager.cpp  2012-02-03 03:52:47 UTC 
(rev 2438)
+++ trunk/source/main/network/NetworkStreamManager.cpp  2012-02-03 15:52:26 UTC 
(rev 2439)
@@ -89,39 +89,36 @@
 {
 #ifdef USE_SOCKETW
        int mysourceid = net->getUserID();
-       if(sourceid == -1)
+
+       if (sourceid == -1)
+       {
                sourceid = mysourceid;
+       }
 
        MUTEX_LOCK(&stream_mutex);
 
-       bool deleted=false;
-       std::map < int, std::map < unsigned int, Streamable *> >::iterator it;
-       for(it=streams.begin(); it!=streams.end(); it++)
+       std::map < int, std::map < unsigned int, Streamable *> >::iterator 
it_source = streams.find(sourceid);
+       std::map < unsigned int, Streamable *>::iterator it_stream;
+
+       if (it_source != streams.end() && !it_source->second.empty())
        {
-               if(it->second.empty()) continue;
-               std::map<unsigned int,Streamable *>::iterator it2;
-               for(it2=it->second.begin(); it2!=it->second.end(); it2++)
-               {
-                       if(it->first == sourceid && (int)it2->first == streamid)
-                       {
-                               streams[it->first].erase(it2);
-                               // iterator gets invalid!
-                               deleted=true;
-                               break;
-                       }
-               }
-               if(deleted) break;
+               it_stream = it_source->second.find(streamid);
+               if (it_stream != it_source->second.end())
+                       streams[sourceid].erase(it_stream);
        }
+
        if(sourceid != mysourceid)
        {
                // now iterate over all factories and remove their instances 
(only triggers)
-               for(std::vector < StreamableFactoryInterface * >::iterator 
it=factories.begin(); it!=factories.end(); it++)
+               std::vector < StreamableFactoryInterface * >::iterator it;
+               for(it=factories.begin(); it!=factories.end(); it++)
                {
                        (*it)->deleteRemote(sourceid, streamid);
                }
        }
+
        MUTEX_UNLOCK(&stream_mutex);
-#endif //USE_SOCKETW
+#endif // USE_SOCKETW
 }
 
 

Modified: trunk/source/main/physics/Beam.cpp
===================================================================
--- trunk/source/main/physics/Beam.cpp  2012-02-03 03:52:47 UTC (rev 2438)
+++ trunk/source/main/physics/Beam.cpp  2012-02-03 15:52:26 UTC (rev 2439)
@@ -324,7 +324,6 @@
 
        //truckScript = new TruckCommandScheduler();
        flaresMode = _flaresMode;
-       int i;
        airbrakeval=0;
        origin=Vector3::ZERO;
        cameranodeacc=Vector3::ZERO;
@@ -555,7 +554,7 @@
 
        //search first_wheel_node
        first_wheel_node=free_node;
-       for (i=0; i<free_node; i++)
+       for (int i=0; i<free_node; i++)
        {
                if (nodes[i].iswheel)
                {
@@ -605,14 +604,14 @@
        // start threads
        if (thread_mode > THREAD_SINGLE)
        {
-               for (i=0; i<thread_mode; i++)
+               for (int i=0; i<thread_mode; i++)
                        if (pthread_create(&threads[i], NULL, threadstart, 
(void*)(free_tb-1)))
                                LOG("BEAM: Can not start a thread");
 
        }
 
        // wait for the thread(s) to be ready
-       BeamWaitNoLock sync();
+       BEAMLOCK();
 
        // all finished? so start network stuff
        if (networked)
@@ -808,8 +807,9 @@
 
 beam_t *Beam::addBeam(int id1, int id2)
 {
-       int type=BEAM_NORMAL;
-       if (id1>=free_node || id2>=free_node)
+       int type = BEAM_NORMAL;
+
+       if (id1 >= free_node || id2 >= free_node)
        {
                LOG("Error: unknown node number in beams section ("
                        +TOSTRING(id1)+","+TOSTRING(id2)+")");
@@ -817,8 +817,8 @@
        }
        //skip if a beam already exists
        LOG(TOSTRING(nodes[id1].AbsPosition)+" -> 
"+TOSTRING(nodes[id2].AbsPosition));
-       int i;
-       for (i=0; i<free_beam; i++)
+
+       for (int i=0; i<free_beam; i++)
        {
                if ((beams[i].p1==&nodes[id1] && beams[i].p2==&nodes[id2]) || 
(beams[i].p1==&nodes[id2] && beams[i].p2==&nodes[id1]))
                {
@@ -983,7 +983,6 @@
        //we must update Nodes positions from available network informations
        //we must lock as long as we use oob1, oob2, netb1, netb2
        MUTEX_LOCK(&net_mutex);
-       int i;
        int tnow=nettimer->getMilliseconds();
        //adjust offset to match remote time
        int rnow=tnow+net_toffset;
@@ -1000,7 +999,7 @@
 
        Vector3 p1 = Vector3::ZERO;
        Vector3 p2 = Vector3::ZERO;
-       for (i = 0; i < first_wheel_node; i++)
+       for (int i = 0; i < first_wheel_node; i++)
        {
                //linear interpolation
                if (i == 0)
@@ -1040,7 +1039,7 @@
        position = apos / first_wheel_node;
 
        // take care of the wheels
-       for (i=0; i<free_wheel; i++)
+       for (int i=0; i<free_wheel; i++)
        {
                float rp=wheels[i].rp1+tratio*(wheels[i].rp2-wheels[i].rp1);
                //compute ideal positions
@@ -1601,11 +1600,10 @@
 {
        if(!hfinder)
                return;
-       int i;
-       //horizontal displacement
-       Vector3 offset=Vector3(px,0,pz)-nodes[0].AbsPosition;
+       // horizontal displacement
+       Vector3 offset = Vector3(px,0,pz)-nodes[0].AbsPosition;
        offset.y=-ipy;
-       for (i=0; i<free_node; i++)
+       for (int i=0; i<free_node; i++)
        {
                nodes[i].AbsPosition+=offset;
        }
@@ -1614,7 +1612,7 @@
        if (miny<-9000)
        {
                
minoffset=nodes[0].AbsPosition.y-hfinder->getHeightAt(nodes[0].AbsPosition.x, 
nodes[0].AbsPosition.z);
-               for (i=1; i<free_node; i++)
+               for (int i=1; i<free_node; i++)
                {
                        Vector3 
pos=Vector3(nodes[i].AbsPosition.x,hfinder->getHeightAt(nodes[i].AbsPosition.x, 
nodes[i].AbsPosition.z),nodes[i].AbsPosition.z);
                        //if (water && pos.y<water->getHeight()) 
pos.y=water->getHeight();
@@ -1626,7 +1624,7 @@
        else
        {
                minoffset=nodes[0].AbsPosition.y-miny;
-               for (i=1; i<free_node; i++)
+               for (int i=1; i<free_node; i++)
                {
                        float offset=nodes[i].AbsPosition.y-miny;
                        if (offset<minoffset) minoffset=offset;
@@ -1636,7 +1634,7 @@
 
        // calculate average position
        Vector3 apos=Vector3::ZERO;
-       for (i=0; i<free_node; i++)
+       for (int i=0; i<free_node; i++)
        {
                nodes[i].AbsPosition.y-=minoffset;
                if (setI) nodes[i].iPosition=nodes[i].AbsPosition;
@@ -1652,7 +1650,7 @@
        if(minCameraRadius<0.01)
        {
                // recalc
-               for (i=0; i<free_node; i++)
+               for (int i=0; i<free_node; i++)
                {
                        Real dist = nodes[i].AbsPosition.distance(position);
                        if(dist > minCameraRadius)
@@ -2100,7 +2098,7 @@
                {
                        //block until all threads are done
                        {
-                               BeamWaitNoLock sync();
+                               BEAMLOCK();
                                for (int t=0; t<numtrucks; t++)
                                {
                                        if (!trucks[t]) continue;
@@ -2161,7 +2159,7 @@
 
 void Beam::prepareShutdown()
 {
-       BeamWaitNoLock sync();
+       BEAMLOCK();
 }
 
 void Beam::sendStreamSetup()
@@ -2861,7 +2859,7 @@
        {
                if (difftoBeamL > beams[i].longbound*beams[i].L || difftoBeamL 
< -beams[i].shortbound*beams[i].L)
                {
-                       if (beams[i].shock && (beams[i].shock->flags & 
!SHOCK_FLAG_ISTRIGGER)) // this is NOT a trigger beam
+                       if (beams[i].shock && (beams[i].shock->flags & 
~SHOCK_FLAG_ISTRIGGER)) // this is NOT a trigger beam
                        {
                                // hard (normal) shock bump
                                k = beams[i].shock->sbd_spring;
@@ -3438,7 +3436,6 @@
        // no lights toggling in skeleton mode because of possible bug with 
emissive texture
        if(skeleton)
                return;
-       int i;
 
        Beam **trucks = BeamFactory::getSingleton().getTrucks();
        int trucksnum = BeamFactory::getSingleton().getTruckCount();
@@ -3446,8 +3443,7 @@
        //export light command
        if (trucks!=0 && state==ACTIVATED && forwardcommands)
        {
-               int i;
-               for (i=0; i<trucksnum; i++)
+               for (int i=0; i<trucksnum; i++)
                {
                        if(!trucks[i]) continue;
                        if (trucks[i]->state==DESACTIVATED && 
trucks[i]->importcommands) trucks[i]->lightsToggle();
@@ -3458,7 +3454,7 @@
                cablightNode->setVisible((lights!=0));
        if (!lights)
        {
-               for (i=0; i<free_flare; i++)
+               for (int i=0; i<free_flare; i++)
                {
                        if(flares[i].type == 'f')
                        {
@@ -3470,13 +3466,13 @@
                }
                if (hasEmissivePass)
                {
-                       char clomatname[256];
+                       char clomatname[256] = {};
                        sprintf(clomatname, "%s-noem", texname);
                        if(cabNode->numAttachedObjects())
                        {
                                Entity* 
ent=((Entity*)(cabNode->getAttachedObject(0)));
                                int numsubent=ent->getNumSubEntities();
-                               for (i=0; i<numsubent; i++)
+                               for (int i=0; i<numsubent; i++)
                                {
                                        SubEntity *subent=ent->getSubEntity(i);
                                        if 
(!strcmp((subent->getMaterialName()).c_str(), texname)) 
subent->setMaterialName(clomatname);
@@ -3487,7 +3483,7 @@
        }
        else
        {
-               for (i=0; i<free_flare; i++)
+               for (int i=0; i<free_flare; i++)
                {
                        if(flares[i].type == 'f')
                        {
@@ -3498,13 +3494,13 @@
                }
                if (hasEmissivePass)
                {
-                       char clomatname[256];
+                       char clomatname[256] = {};
                        sprintf(clomatname, "%s-noem", texname);
                        if(cabNode->numAttachedObjects())
                        {
                                Entity* 
ent=((Entity*)(cabNode->getAttachedObject(0)));
                                int numsubent=ent->getNumSubEntities();
-                               for (i=0; i<numsubent; i++)
+                               for (int i=0; i<numsubent; i++)
                                {
                                        SubEntity *subent=ent->getSubEntity(i);
                                        if 
(!strcmp((subent->getMaterialName()).c_str(), clomatname)) 
subent->setMaterialName(texname);
@@ -4888,12 +4884,23 @@
                {
                        for (int k=0; k<4; k++)
                        {
-                               
if(props[i].light[k])props[i].light[k]->setVisible(beacon && enableLight);
-                               
if(props[i].bbsnode[k])props[i].bbsnode[k]->setVisible(beacon);
-                               if(props[i].bbs[k] && beacon && 
!props[i].bbsnode[k]->numAttachedObjects())
-                                       
props[i].bbsnode[k]->attachObject(props[i].bbs[k]);
-                               else if(props[i].bbs[k] && !beacon)
-                                       props[i].bbsnode[k]->detachAllObjects();
+                               if (props[i].light[k])
+                               {
+                                       props[i].light[k]->setVisible(beacon && 
enableLight);
+                               }
+                               if (props[i].bbsnode[k])
+                               {
+                                       props[i].bbsnode[k]->setVisible(beacon);
+
+                                       if (props[i].bbs[k] && beacon && 
!props[i].bbsnode[k]->numAttachedObjects())
+                                       {
+                                               
props[i].bbsnode[k]->attachObject(props[i].bbs[k]);
+                                       }
+                                       else if (props[i].bbs[k] && !beacon)
+                                       {
+                                               
props[i].bbsnode[k]->detachAllObjects();
+                                       }
+                               }
                        }
                }
        }

Modified: trunk/source/main/physics/BeamFactory.cpp
===================================================================
--- trunk/source/main/physics/BeamFactory.cpp   2012-02-03 03:52:47 UTC (rev 
2438)
+++ trunk/source/main/physics/BeamFactory.cpp   2012-02-03 15:52:26 UTC (rev 
2439)
@@ -69,9 +69,10 @@
                trucks[t] = 0;
 
        String threadMode = SSETTING("Threads", "2 (Hyper-Threading or Dual 
core CPU)");
+
        if (threadMode == "1 (Single Core CPU)")
                thread_mode = THREAD_SINGLE;
-       if (threadMode == "2 (Hyper-Threading or Dual core CPU)")
+       else
                thread_mode = THREAD_MULTI;
 
        if (BSETTING("2DReplay", false))
@@ -157,7 +158,7 @@
 
        trucks[truck_num] = b;
 
-       // lock slidenodes after spawning the truck?
+       // lock slide nodes after spawning the truck?
        if (b->getSlideNodesLockInstant())
                b->toggleSlideNodeLock();
 
@@ -311,7 +312,7 @@
        std::map < int, std::map < unsigned int, Beam *> >::iterator it_source 
= streamables.find(source_id);
        std::map < unsigned int, Beam *>::iterator it_stream;
        
-       if (it_source != streamables.end())
+       if (it_source != streamables.end() && !it_source->second.empty())
        {
                it_stream = it_source->second.find(stream_id);
                if (it_stream != it_source->second.end() && it_stream->second)
@@ -328,7 +329,7 @@
        std::map < int, std::map < unsigned int, Beam *> >::iterator it_source 
= streamables.find(source_id);
        std::map < unsigned int, Beam *>::iterator it_stream;
 
-       if (it_source != streamables.end())
+       if (it_source != streamables.end() && !it_source->second.empty())
        {
                it_stream = it_source->second.find(stream_id);
                if (it_stream != it_source->second.end() && it_stream->second)
@@ -341,7 +342,7 @@
 bool BeamFactory::syncRemoteStreams()
 {
        // block until all threads done
-       BeamWaitNoLock sync();
+       BEAMLOCK();
 
        // we override this here, so we know if something changed and could 
update the player list
        // we delete and add trucks in there, so be sure that nothing runs as 
we delete them ...
@@ -725,12 +726,10 @@
        // already locked
        // lockStreams();
        std::map < int, std::map < unsigned int, Beam *> > &streamables = 
getStreams();
-       std::map < int, std::map < unsigned int, Beam *> >::iterator it_stream;
+       std::map < int, std::map < unsigned int, Beam *> >::iterator it_stream 
= streamables.find(del->sourceid);;
        std::map < unsigned int, Beam *>::iterator it_beam;
 
-       it_stream = streamables.find(del->sourceid);
-
-       if (it_stream == streamables.end())
+       if (it_stream == streamables.end() || it_stream->second.empty())
                // no stream for this source id
                return;
 

Modified: trunk/source/main/physics/air/turbojet.cpp
===================================================================
--- trunk/source/main/physics/air/turbojet.cpp  2012-02-03 03:52:47 UTC (rev 
2438)
+++ trunk/source/main/physics/air/turbojet.cpp  2012-02-03 15:52:26 UTC (rev 
2439)
@@ -75,7 +75,7 @@
        if (afterburnable)
        {
                sprintf(paname, "%s-abflame", propname);
-               Entity *te = manager->createEntity(paname, "abflame.mesh");
+               te = manager->createEntity(paname, "abflame.mesh");
                MaterialFunctionMapper::replaceSimpleMeshMaterials(te, 
ColourValue(1, 1, 0));
                if(mfm) mfm->replaceMeshMaterials(te);
                if(mr) mr->replaceMeshMaterials(te);

Modified: trunk/source/main/physics/collision/collisions.cpp
===================================================================
--- trunk/source/main/physics/collision/collisions.cpp  2012-02-03 03:52:47 UTC 
(rev 2438)
+++ trunk/source/main/physics/collision/collisions.cpp  2012-02-03 15:52:26 UTC 
(rev 2439)
@@ -1257,9 +1257,9 @@
                // check all nodes
 
                bool allInside = true;
-               for (int i=0; i < truck->free_node; i++)
+               for (int n=0; n < truck->free_node; n++)
                {
-                       if (!isInside(truck->nodes[i].AbsPosition, cb))
+                       if (!isInside(truck->nodes[n].AbsPosition, cb))
                        {
                                // node not in box, no need to check the rest
                                allInside=false;

Modified: trunk/source/main/scripting/GameScript.cpp
===================================================================
--- trunk/source/main/scripting/GameScript.cpp  2012-02-03 03:52:47 UTC (rev 
2438)
+++ trunk/source/main/scripting/GameScript.cpp  2012-02-03 15:52:26 UTC (rev 
2439)
@@ -690,6 +690,11 @@
 {
        // malloc this, so we are safe from this function scope
        OnlineAPIParams_t *params = (OnlineAPIParams_t 
*)malloc(sizeof(OnlineAPIParams_t));
+       if (!params)
+       {
+               free(params);
+               return 1;
+       }
        params->cls      = this;
        strncpy(params->apiquery, apiquery.c_str(), 2048);
 

Modified: trunk/source/main/utils/CollisionTools.cpp
===================================================================
--- trunk/source/main/utils/CollisionTools.cpp  2012-02-03 03:52:47 UTC (rev 
2438)
+++ trunk/source/main/utils/CollisionTools.cpp  2012-02-03 15:52:26 UTC (rev 
2439)
@@ -566,6 +566,7 @@
        }
 #endif //0
 
+       // TODO: What if theBucket == 0?
        Ogre::StaticGeometry::LODBucket::MaterialIterator 
mit(theBucket->getMaterialIterator());
 
        while (mit.hasMoreElements())
@@ -613,7 +614,6 @@
                }
        }
 
-
        overtex_count = vertices.size();
        overtices = 0;
        if (overtex_count > 0)

Modified: trunk/source/main/utils/InputEngine.cpp
===================================================================
--- trunk/source/main/utils/InputEngine.cpp     2012-02-03 03:52:47 UTC (rev 
2438)
+++ trunk/source/main/utils/InputEngine.cpp     2012-02-03 15:52:26 UTC (rev 
2439)
@@ -2471,18 +2471,23 @@
        {
        case ET_Keyboard:
                {
-                       char keycodes[256], *keycode=0;
+                       bool alt   = false;
+                       bool shift = false;
+                       bool ctrl  = false;
+                       bool expl  = false;
+
+                       char *keycode            = 0;
+                       char  keycodes[256]      = {};
+                       char  keycodes_work[256] = {};
+
                        OIS::KeyCode key = KC_UNASSIGNED;
+
                        sscanf(line, "%s %s %s", eventName, evtype, keycodes);
-                       // seperate all keys and construct the key combination
-                       //LOG("try to add key: " + String(keyname)+","+ 
String(evtype)+","+String(keycodes));
-                       bool alt=false;
-                       bool shift=false;
-                       bool ctrl=false;
-                       bool expl=false;
-                       char keycodes_work[256] = "";
+                       // separate all keys and construct the key combination
+                       //LOG("try to add key: " + String(eventName)+","+ 
String(evtype)+","+String(keycodes));
                        strncpy(keycodes_work, keycodes, 255);
                        char *token = strtok(keycodes_work, delimiters);
+
                        while (token != NULL)
                        {
                                if (strncmp(token, "SHIFT", 5) == 0)
@@ -2504,7 +2509,8 @@
                                LOG("unknown key: " + string(keycodes));
 #endif
                                key = KC_UNASSIGNED;
-                       } else {
+                       } else
+                       {
                                //LOG("found key: " + string(keycode) + " = " + 
TOSTRING((int)key));
                                key = allit->second;
                        }
@@ -2513,22 +2519,19 @@
                        event_trigger_t t_key = newEvent();
                        //memset(&t_key, 0, sizeof(event_trigger_t));
                        t_key.eventtype = ET_Keyboard;
-                       t_key.shift = shift;
-                       t_key.ctrl = ctrl;
-                       t_key.alt = alt;
+                       t_key.shift     = shift;
+                       t_key.ctrl      = ctrl;
+                       t_key.alt       = alt;
+                       t_key.keyCode   = key;
                        t_key.explicite = expl;
-                       t_key.keyCode = key;
+                       
                        strncpy(t_key.configline, keycodes, 128);
                        strncpy(t_key.group, getEventGroup(eventName).c_str(), 
128);
                        strncpy(t_key.tmp_eventname, eventName, 128);
 
                        strncpy(t_key.comments, cur_comment.c_str(), 1024);
-                       cur_comment = "";
                        addEvent(eventID, t_key);
 
-#ifndef NOOGRE
-                       //LOG("adding: " + String(eventName) + ": 
"+TOSTRING((int)key));
-#endif
                        return true;
                }
        case ET_JoystickButton:
@@ -2563,25 +2566,25 @@
        case ET_JoystickAxisRel:
        case ET_JoystickAxisAbs:
                {
-                       int axisNo=0;
-                       char options[250];
+                       int axisNo = 0;
+                       char options[250] = {};
                        memset(options, 0, 250);
                        sscanf(line, "%s %s %d %d %s", eventName, evtype, 
&joyNo, &axisNo, options);
                        int eventID = resolveEventName(String(eventName));
                        if(eventID == -1) return false;
 
-                       bool half=false;
-                       bool reverse=false;
-                       bool linear=false;
-                       bool relative=false;
-                       bool usedigital=false;
-                       float deadzone=defaultDeadzone;
-                       float linearity=defaultLinearity;
-                       int jAxisRegion=0;
-                       // 0 = all
+                       bool half       = false;
+                       bool reverse    = false;
+                       bool linear     = false;
+                       bool relative   = false;
+                       bool usedigital = false;
+                       float deadzone  = defaultDeadzone;
+                       float linearity = defaultLinearity;
+                       int jAxisRegion = 0;
+                       //  0 = all
                        // -1 = lower
-                       // 1 = upper
-                       char tmp[250] = "";
+                       //  1 = upper
+                       char tmp[250] = {};
                        strncpy(tmp, options, 250);
                        char *token = strtok(tmp, delimiters);
                        while (token != NULL)
@@ -2602,14 +2605,14 @@
                                        usedigital=true;
                                else if (strncmp(token, "DEADZONE", 8) == 0 && 
strnlen(token, 250) > 9)
                                {
-                                       char tmp2[256];
+                                       char tmp2[256] = {};
                                        strcpy(tmp2,token+9);
                                        deadzone = atof(tmp2);
                                        //LOG("got deadzone: " + 
TOSTRING(deadzone)+", "+String(tmp2));
                                }
                                else if (strncmp(token, "LINEARITY", 9) == 0 && 
strnlen(token, 250) > 10)
                                {
-                                       char tmp2[256];
+                                       char tmp2[256] = {};
                                        strcpy(tmp2,token+10);
                                        linearity = atof(tmp2);
                                }
@@ -2858,7 +2861,7 @@
 Ogre::String InputEngine::getEventGroup(Ogre::String eventName)
 {
        const char delimiters[] = "_";
-       char tmp[250] = "";
+       char tmp[250] = {};
        strncpy(tmp, eventName.c_str(), 250);
        char *token = strtok(tmp, delimiters);
        while (token != NULL)

Modified: trunk/source/main/utils/InputEngine.h
===================================================================
--- trunk/source/main/utils/InputEngine.h       2012-02-03 03:52:47 UTC (rev 
2438)
+++ trunk/source/main/utils/InputEngine.h       2012-02-03 15:52:26 UTC (rev 
2439)
@@ -404,7 +404,7 @@
        int joystickSliderRegion;
 
        //others
-       char configline[128];
+       char configline[256];
        char group[128];
        char tmp_eventname[128];
        char comments[1024];

Modified: trunk/source/main/utils/MeshObject.cpp
===================================================================
--- trunk/source/main/utils/MeshObject.cpp      2012-02-03 03:52:47 UTC (rev 
2438)
+++ trunk/source/main/utils/MeshObject.cpp      2012-02-03 15:52:26 UTC (rev 
2439)
@@ -203,7 +203,7 @@
        if(mfm)
                mfm->replaceMeshMaterials(ent);
 
-       if(!materialName.empty())
+       if(ent && !materialName.empty())
                ent->setMaterialName(materialName);
 
        // only set it if different from default (true)

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Rigsofrods-devel mailing list
Rigsofrods-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to