Merge branch 'tobbi-cppcheck'

This commit is contained in:
hiker 2014-11-25 14:15:37 +11:00
commit 8ef2c63857
6 changed files with 71 additions and 29 deletions

View File

@ -128,10 +128,23 @@ void generateLifetimeSizeDirection(scene::IParticleEmitter *emitter, float &life
void ParticleSystemProxy::generateParticlesFromPointEmitter(scene::IParticlePointEmitter *emitter)
{
ParticleParams = (ParticleData *) realloc(ParticleParams, sizeof(ParticleData) * count);
InitialValues = (ParticleData *)realloc(InitialValues, sizeof(ParticleData)* count);
ParticleData* ParticleParamsTmp = (ParticleData *) realloc(ParticleParams, sizeof(ParticleData) * m_count);
ParticleData* InitialValuesTmp = (ParticleData *)realloc(InitialValues, sizeof(ParticleData)* m_count);
for (unsigned i = 0; i < count; i++)
if(ParticleParamsTmp != NULL) // In case memory allocation succeeded
{
Log::error("GPUParticles", "Not enough memory for %d from point particles.", m_count);
ParticleParams = ParticleParamsTmp;
m_count = m_previous_count;
}
if(InitialValuesTmp != NULL)
{
Log::fatal("GPUParticles", "Not enough memory for %d from point particles.", m_count);
InitialValues = InitialValuesTmp;
m_count = m_previous_count;
}
for (unsigned i = 0; i < m_count; i++)
{
ParticleParams[i].PositionX = 0;
ParticleParams[i].PositionY = 0;
@ -150,12 +163,25 @@ void ParticleSystemProxy::generateParticlesFromPointEmitter(scene::IParticlePoin
void ParticleSystemProxy::generateParticlesFromBoxEmitter(scene::IParticleBoxEmitter *emitter)
{
ParticleParams = (ParticleData *)realloc(ParticleParams, sizeof(ParticleData)* count);
InitialValues = (ParticleData *)realloc(InitialValues, sizeof(ParticleData)* count);
ParticleData* ParticleParamsTmp = (ParticleData *) realloc(ParticleParams, sizeof(ParticleData) * m_count);
ParticleData* InitialValuesTmp = (ParticleData *)realloc(InitialValues, sizeof(ParticleData)* m_count);
if(ParticleParamsTmp != NULL) // In case memory allocation succeeded
{
Log::error("GPUParticles", "Not enough memory for %d from box particles.", m_count);
ParticleParams = ParticleParamsTmp;
m_count = m_previous_count;
}
if(InitialValuesTmp != NULL)
{
Log::error("GPUParticles", "Not enough memory for %d from box particles.", m_count);
InitialValues = InitialValuesTmp;
m_count = m_previous_count;
}
const core::vector3df& extent = emitter->getBox().getExtent();
for (unsigned i = 0; i < count; i++)
for (unsigned i = 0; i < m_count; i++)
{
ParticleParams[i].PositionX = emitter->getBox().MinEdge.X + os::Randomizer::frand() * extent.X;
ParticleParams[i].PositionY = emitter->getBox().MinEdge.Y + os::Randomizer::frand() * extent.Y;
@ -177,10 +203,15 @@ void ParticleSystemProxy::generateParticlesFromBoxEmitter(scene::IParticleBoxEmi
void ParticleSystemProxy::generateParticlesFromSphereEmitter(scene::IParticleSphereEmitter *emitter)
{
ParticleParams = (ParticleData *)realloc(ParticleParams, sizeof(ParticleData)* count);
InitialValues = (ParticleData *)realloc(InitialValues, sizeof(ParticleData)* count);
ParticleData* ParticleParamsTmp = (ParticleData *) realloc(ParticleParams, sizeof(ParticleData) * m_count);
ParticleData* InitialValuesTmp = (ParticleData *)realloc(InitialValues, sizeof(ParticleData)* m_count);
for (unsigned i = 0; i < count; i++) {
if(ParticleParamsTmp != NULL) // In case memory allocation succeeded
ParticleParams = ParticleParamsTmp;
if(InitialValuesTmp != NULL)
InitialValues = InitialValuesTmp;
for (unsigned i = 0; i < m_count; i++) {
// Random distance from center
const f32 distance = os::Randomizer::frand() * emitter->getRadius();
@ -227,7 +258,8 @@ void ParticleSystemProxy::setEmitter(scene::IParticleEmitter* emitter)
flip = false;
m_first_execution = true;
count = emitter->getMaxParticlesPerSecond() * emitter->getMaxLifeTime() / 1000;
m_previous_count = m_count; // save to handle out of memory errors
m_count = emitter->getMaxParticlesPerSecond() * emitter->getMaxLifeTime() / 1000;
switch (emitter->getType())
{
case scene::EPET_POINT:
@ -340,7 +372,7 @@ void ParticleSystemProxy::simulate()
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfb_buffers[1]);
glBeginTransformFeedback(GL_POINTS);
glDrawArrays(GL_POINTS, 0, count);
glDrawArrays(GL_POINTS, 0, m_count);
glEndTransformFeedback();
glBindVertexArray(0);
@ -359,7 +391,7 @@ void ParticleSystemProxy::drawFlip()
ParticleShader::FlipParticleRender::getInstance()->setUniforms();
glBindVertexArray(current_rendering_vao);
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, count);
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, m_count);
}
void ParticleSystemProxy::drawNotFlip()
@ -377,7 +409,7 @@ void ParticleSystemProxy::drawNotFlip()
ParticleShader::SimpleParticleRender::getInstance()->setUniforms(ColorFrom, ColorTo);
glBindVertexArray(current_rendering_vao);
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, count);
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, m_count);
}
void ParticleSystemProxy::draw()
@ -393,12 +425,12 @@ void ParticleSystemProxy::generateVAOs()
glBindVertexArray(0);
glGenBuffers(1, &initial_values_buffer);
glBindBuffer(GL_ARRAY_BUFFER, initial_values_buffer);
glBufferData(GL_ARRAY_BUFFER, count * sizeof(ParticleData), ParticleParams, GL_STREAM_COPY);
glBufferData(GL_ARRAY_BUFFER, m_count * sizeof(ParticleData), ParticleParams, GL_STREAM_COPY);
glGenBuffers(2, tfb_buffers);
glBindBuffer(GL_ARRAY_BUFFER, tfb_buffers[0]);
glBufferData(GL_ARRAY_BUFFER, count * sizeof(ParticleData), InitialValues, GL_STREAM_COPY);
glBufferData(GL_ARRAY_BUFFER, m_count * sizeof(ParticleData), InitialValues, GL_STREAM_COPY);
glBindBuffer(GL_ARRAY_BUFFER, tfb_buffers[1]);
glBufferData(GL_ARRAY_BUFFER, count * sizeof(ParticleData), 0, GL_STREAM_COPY);
glBufferData(GL_ARRAY_BUFFER, m_count * sizeof(ParticleData), 0, GL_STREAM_COPY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenVertexArrays(1, &current_rendering_vao);
@ -415,8 +447,8 @@ void ParticleSystemProxy::generateVAOs()
glBindVertexArray(0);
if (flip)
{
float *quaternions = new float[4 * count];
for (unsigned i = 0; i < count; i++)
float *quaternions = new float[4 * m_count];
for (unsigned i = 0; i < m_count; i++)
{
core::vector3df rotationdir(0., 1., 0.);
@ -427,7 +459,7 @@ void ParticleSystemProxy::generateVAOs()
}
glGenBuffers(1, &quaternionsbuffer);
glBindBuffer(GL_ARRAY_BUFFER, quaternionsbuffer);
glBufferData(GL_ARRAY_BUFFER, 4 * count * sizeof(float), quaternions, GL_STREAM_COPY);
glBufferData(GL_ARRAY_BUFFER, 4 * m_count * sizeof(float), quaternions, GL_STREAM_COPY);
delete[] quaternions;
}
@ -454,4 +486,4 @@ void ParticleSystemProxy::render() {
m_first_execution = false;
simulate();
draw();
}
}

View File

@ -21,7 +21,12 @@ protected:
bool m_randomize_initial_y;
GLuint texture;
unsigned count;
/** Current count of particles. */
unsigned m_count;
/** Previous count - for error handling only. */
unsigned m_previous_count;
static void CommonRenderingVAO(GLuint PositionBuffer);
static void AppendQuaternionRenderingVAO(GLuint QuaternionBuffer);
static void CommonSimulationVAO(GLuint position_vbo, GLuint initialValues_vbo);

View File

@ -164,7 +164,7 @@ void WiimoteManager::launchDetection(int timeout)
device_manager->getConfigForGamepad(WIIMOTE_START_IRR_ID, "Wiimote",
&gamepad_config);
int num_buttons = (int)( log((float)WIIMOTE_BUTTON_ALL) / log(2.0f))+1;
int num_buttons = (int)( log((float)WIIMOTE_BUTTON_ALL) / log((float)2.0f))+1;
gamepad_config->setNumberOfButtons(num_buttons);
gamepad_config->setNumberOfAxis(1);
@ -213,7 +213,7 @@ void WiimoteManager::launchDetection(int timeout)
*/
int getButton(int n)
{
return (int)(log((float)n)/log(2.0f));
return (int)(log((float)n)/log((float)2.0f));
} // getButton
// ----------------------------------------------------------------------------

View File

@ -1284,7 +1284,12 @@ bool FileManager::copyFile(const std::string &source, const std::string &dest)
const int BUFFER_SIZE=32768;
char *buffer = new char[BUFFER_SIZE];
if(!buffer) return false;
if(!buffer)
{
fclose(f_source);
fclose(f_dest);
return false;
}
size_t n;
while((n=fread(buffer, 1, BUFFER_SIZE, f_source))>0)
{

View File

@ -253,7 +253,7 @@ void History::Load()
Log::fatal("History", "Could not read history.dat.");
unsigned int num_karts;
if(sscanf(s, "numkarts: %d",&num_karts)!=1)
if(sscanf(s, "numkarts: %u", &num_karts)!=1)
Log::fatal("History", "No number of karts found in history file.");
race_manager->setNumKarts(num_karts);

View File

@ -100,7 +100,7 @@ void ReplayPlay::Load()
Log::fatal("Replay", "Could not read '%s'.", getReplayFilename().c_str());
unsigned int version;
if (sscanf(s,"Version: %d", &version) != 1)
if (sscanf(s,"Version: %u", &version) != 1)
Log::fatal("Replay", "No Version information found in replay file (bogus replay file).");
if (version != getReplayVersion())
@ -130,7 +130,7 @@ void ReplayPlay::Load()
unsigned int num_laps;
fgets(s, 1023, fd);
if(sscanf(s, "Laps: %d", &num_laps) != 1)
if(sscanf(s, "Laps: %u", &num_laps) != 1)
Log::fatal("Replay", "No number of laps found in replay file.");
race_manager->setNumLaps(num_laps);
@ -164,7 +164,7 @@ void ReplayPlay::readKartData(FILE *fd, char *next_line)
fgets(s, 1023, fd);
unsigned int size;
if(sscanf(s,"size: %d",&size)!=1)
if(sscanf(s,"size: %u",&size)!=1)
Log::fatal("Replay", "Number of records not found in replay file "
"for kart %d.",
m_ghost_karts.size()-1);
@ -198,7 +198,7 @@ void ReplayPlay::readKartData(FILE *fd, char *next_line)
} // for i
fgets(s, 1023, fd);
unsigned int num_events;
if(sscanf(s,"events: %d",&num_events)!=1)
if(sscanf(s,"events: %u",&num_events)!=1)
Log::warn("Replay", "Number of events not found in replay file "
"for kart %d.", m_ghost_karts.size()-1);