Skip to content

Commit 1b34dcf

Browse files
committed
warnings removal and avoid access runtime errors on empty vectors
1 parent fa96827 commit 1b34dcf

28 files changed

+215
-113
lines changed

src/objects/communications/ArduinoSerial.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ void ArduinoSerial::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
9999

100100
//--------------------------------------------------------------
101101
void ArduinoSerial::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
102+
unusedArgs(patchObjects);
102103

103104
if(deviceNameList.size() > 0){
104105
if(ofGetElapsedTimeMillis()-resetTime > 40){
105106
resetTime = ofGetElapsedTimeMillis();
106107

107-
// SENDING DATA
108-
if(this->inletsConnected[0]){
108+
// SENDING DATA TO ARDUINO
109+
if(this->inletsConnected[0] && !static_cast<vector<float> *>(_inletParams[0])->empty()){
109110
temp = "";
110111
if(static_cast<int>(static_cast<vector<float> *>(_inletParams[0])->size()) <= MAX_ARDUINO_SENDING_VECTOR_LENGTH){
111112
temp += ofToString(static_cast<int>(static_cast<vector<float> *>(_inletParams[0])->size()));
@@ -124,7 +125,7 @@ void ArduinoSerial::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchO
124125
}
125126

126127

127-
// RECEIVING DATA
128+
// RECEIVING DATA FROM ARDUINO
128129
if(serial.available() > 0){
129130
memset(bytesReturned, 0, MAX_ARDUINO_RECEIVING_VECTOR_LENGTH);
130131
memset(bytesReadString, 0, MAX_ARDUINO_RECEIVING_VECTOR_LENGTH+1);
@@ -169,6 +170,8 @@ void ArduinoSerial::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchO
169170

170171
//--------------------------------------------------------------
171172
void ArduinoSerial::drawObjectContent(ofTrueTypeFont *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
173+
unusedArgs(font,glRenderer);
174+
172175
ofSetColor(255);
173176
// draw node texture preview with OF
174177
if(scaledObjW*canvasZoom > 90.0f){
@@ -219,7 +222,7 @@ void ArduinoSerial::drawObjectNodeConfig(){
219222

220223
ImGui::Spacing();
221224
if(ImGui::BeginCombo("Device", deviceNameList.at(serialDeviceID).c_str() )){
222-
for(int i=0; i < deviceNameList.size(); ++i){
225+
for(int i=0; i < static_cast<int>(deviceNameList.size()); ++i){
223226
bool is_selected = (serialDeviceID == i );
224227
if (ImGui::Selectable(deviceNameList.at(i).c_str(), is_selected)){
225228
resetSERIALSettings(i,baudRateID);
@@ -231,7 +234,7 @@ void ArduinoSerial::drawObjectNodeConfig(){
231234

232235
ImGui::Spacing();
233236
if(ImGui::BeginCombo("Baudrate", baudrateList.at(baudRateID).c_str() )){
234-
for(int i=0; i < baudrateList.size(); ++i){
237+
for(int i=0; i < static_cast<int>(baudrateList.size()); ++i){
235238
bool is_selected = (baudRateID == i );
236239
if (ImGui::Selectable(baudrateList.at(i).c_str(), is_selected)){
237240
resetSERIALSettings(serialDeviceID,i);
@@ -248,6 +251,8 @@ void ArduinoSerial::drawObjectNodeConfig(){
248251

249252
//--------------------------------------------------------------
250253
void ArduinoSerial::removeObjectContent(bool removeFileFromData){
254+
unusedArgs(removeFileFromData);
255+
251256
if(serial.isInitialized() && deviceNameList.size() > 0){
252257
serial.close();
253258
}

src/objects/communications/OscSender.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ void OscSender::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjec
8686
m.addStringArg(*static_cast<string *>(_inletParams[i]));
8787
messageOK = true;
8888
}else if(this->getInletType(i) == VP_LINK_ARRAY){
89-
for(size_t s=0;s<static_cast<size_t>(static_cast<vector<float> *>(_inletParams[i])->size());s++){
90-
m.addFloatArg(static_cast<vector<float> *>(_inletParams[i])->at(s));
89+
if(!static_cast<vector<float> *>(_inletParams[i])->empty()){
90+
for(size_t s=0;s<static_cast<size_t>(static_cast<vector<float> *>(_inletParams[i])->size());s++){
91+
m.addFloatArg(static_cast<vector<float> *>(_inletParams[i])->at(s));
92+
}
93+
messageOK = true;
9194
}
92-
messageOK = true;
9395
}else if(this->getInletType(i) == VP_LINK_TEXTURE && static_cast<ofTexture *>(_inletParams[i])->isAllocated()){
9496
// note: the size of the image depends greatly on your network buffer sizes,
9597
// if an image is too big the message won't come through

src/objects/data/DataToFile.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void DataToFile::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
7777

7878
//--------------------------------------------------------------
7979
void DataToFile::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
80+
unusedArgs(patchObjects);
8081

8182
if(this->inletsConnected[1]){
8283
if(*(float *)&_inletParams[1] < 1.0){
@@ -95,9 +96,9 @@ void DataToFile::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObje
9596
ofLog(OF_LOG_NOTICE,"FINISHED EXPORTING DATA");
9697
}
9798

98-
if(this->inletsConnected[0] && recordData){
99+
if(this->inletsConnected[0] && !static_cast<vector<float> *>(_inletParams[0])->empty() && recordData){
99100
string temp = "";
100-
for(int i=0;i<static_cast<vector<float> *>(_inletParams[0])->size();i++){
101+
for(size_t i=0;i<static_cast<vector<float> *>(_inletParams[0])->size();i++){
101102
temp += ofToString(static_cast<vector<float> *>(_inletParams[0])->at(i));
102103
if(i<static_cast<vector<float> *>(_inletParams[0])->size()-1){
103104
temp += ",";
@@ -110,6 +111,8 @@ void DataToFile::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObje
110111

111112
//--------------------------------------------------------------
112113
void DataToFile::drawObjectContent(ofTrueTypeFont *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
114+
unusedArgs(font,glRenderer);
115+
113116
ofSetColor(255);
114117
}
115118

@@ -229,7 +232,7 @@ void DataToFile::drawObjectNodeConfig(){
229232

230233
//--------------------------------------------------------------
231234
void DataToFile::removeObjectContent(bool removeFileFromData){
232-
235+
unusedArgs(removeFileFromData);
233236
}
234237

235238
//--------------------------------------------------------------

src/objects/data/DataToTexture.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,39 +87,40 @@ void DataToTexture::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
8787

8888
//--------------------------------------------------------------
8989
void DataToTexture::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
90+
unusedArgs(patchObjects);
9091

9192
if(needReset){
9293
needReset = false;
9394
resetResolution();
9495
}
9596

9697
if(static_cast<ofTexture *>(_outletParams[0])->isAllocated()){
97-
if(this->inletsConnected[0] || this->inletsConnected[1] || this->inletsConnected[2]){
98-
for(int s=0;s<pix->size();s++){
98+
if((this->inletsConnected[0] || this->inletsConnected[1] || this->inletsConnected[2]) && (!static_cast<vector<float> *>(_inletParams[0])->empty() || !static_cast<vector<float> *>(_inletParams[1])->empty() || !static_cast<vector<float> *>(_inletParams[2])->empty())){
99+
for(size_t s=0;s<pix->size();s++){
99100
int posR = 0;
100101
int sampleR = 0;
101102
int posG = 0;
102103
int sampleG = 0;
103104
int posB = 0;
104105
int sampleB = 0;
105106
// RED
106-
if(this->inletsConnected[0] && static_cast<int>(static_cast<vector<float> *>(_inletParams[0])->size()) > 0){
107+
if(this->inletsConnected[0] && !static_cast<vector<float> *>(_inletParams[0])->empty()){
107108
posR = static_cast<int>(floor(ofMap(s,0,pix->size(),0,static_cast<int>(static_cast<vector<float> *>(_inletParams[0])->size()))));
108109
sampleR = static_cast<int>(floor(ofMap(static_cast<vector<float> *>(_inletParams[0])->at(posR), -0.5f, 0.5f, 0, 255)));
109110
}
110111
// GREEN
111-
if(this->inletsConnected[1] && static_cast<int>(static_cast<vector<float> *>(_inletParams[1])->size()) > 0){
112+
if(this->inletsConnected[1] && !static_cast<vector<float> *>(_inletParams[1])->empty()){
112113
posG = static_cast<int>(floor(ofMap(s,0,pix->size(),0,static_cast<int>(static_cast<vector<float> *>(_inletParams[1])->size()))));
113114
sampleG = static_cast<int>(floor(ofMap(static_cast<vector<float> *>(_inletParams[1])->at(posG), -0.5f, 0.5f, 0, 255)));
114115
}
115116
// BLUE
116-
if(this->inletsConnected[2] && static_cast<int>(static_cast<vector<float> *>(_inletParams[2])->size()) > 0){
117+
if(this->inletsConnected[2] && !static_cast<vector<float> *>(_inletParams[2])->empty()){
117118
posB = static_cast<int>(floor(ofMap(s,0,pix->size(),0,static_cast<int>(static_cast<vector<float> *>(_inletParams[2])->size()))));
118119
sampleB = static_cast<int>(floor(ofMap(static_cast<vector<float> *>(_inletParams[2])->at(posB), -0.5f, 0.5f, 0, 255)));
119120
}
120121
ofColor c(sampleR,sampleG,sampleB);
121-
int x = s % pix->getWidth();
122-
int y = static_cast<int>(ceil(s / pix->getWidth()));
122+
size_t x = s % pix->getWidth();
123+
size_t y = static_cast<size_t>(ceil(s / pix->getWidth()));
123124
if(x >= 0 && x <= pix->getWidth() && y >= 0 && y <= pix->getHeight()){
124125
pix->setColor(x,y,c);
125126
}
@@ -146,7 +147,9 @@ void DataToTexture::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchO
146147

147148
//--------------------------------------------------------------
148149
void DataToTexture::drawObjectContent(ofTrueTypeFont *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
149-
if(this->inletsConnected[0] || this->inletsConnected[1] || this->inletsConnected[2]){
150+
unusedArgs(font,glRenderer);
151+
152+
if((this->inletsConnected[0] || this->inletsConnected[1] || this->inletsConnected[2]) && (!static_cast<vector<float> *>(_inletParams[0])->empty() || !static_cast<vector<float> *>(_inletParams[1])->empty() || !static_cast<vector<float> *>(_inletParams[2])->empty())){
150153
// draw node texture preview with OF
151154
if(scaledObjW*canvasZoom > 90.0f){
152155
drawNodeOFTexture(*static_cast<ofTexture *>(_outletParams[0]), posX, posY, drawW, drawH, objOriginX, objOriginY, scaledObjW, scaledObjH, canvasZoom, this->scaleFactor);

src/objects/data/Receiver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,10 @@ void vpReceiver::audioOutObject(ofSoundBuffer &outBuffer){
259259
unusedArgs(outBuffer);
260260

261261
if(receiveTypeIndex == VP_LINK_AUDIO){
262-
if(this->inletsConnected[0] && isReceivingON){
262+
if(this->inletsConnected[0] && isReceivingON && !static_cast<ofSoundBuffer *>(_inletParams[0])->getBuffer().empty()){
263263
*static_cast<ofSoundBuffer *>(_outletParams[0]) = *static_cast<ofSoundBuffer *>(_inletParams[0]);
264264
}else{
265-
*static_cast<ofSoundBuffer *>(_outletParams[0]) *= 0.0f;
265+
static_cast<ofSoundBuffer *>(_outletParams[0])->set(0.0f);
266266
}
267267
}
268268

src/objects/data/Sender.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void vpSender::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObject
106106
*static_cast<string *>(_outletParams[0]) = "";
107107
}
108108
}else if(sendTypeIndex == VP_LINK_ARRAY){
109-
if(this->inletsConnected[0] && isSendingON){
109+
if(this->inletsConnected[0] && !static_cast<vector<float> *>(_inletParams[0])->empty() && isSendingON){
110110
*static_cast<vector<float> *>(_outletParams[0]) = *static_cast<vector<float> *>(_inletParams[0]);
111111
}else{
112112
*static_cast<vector<float> *>(_outletParams[0]) = *emptyVector;
@@ -265,10 +265,10 @@ void vpSender::audioOutObject(ofSoundBuffer &outBuffer){
265265
unusedArgs(outBuffer);
266266

267267
if(sendTypeIndex == VP_LINK_AUDIO){
268-
if(this->inletsConnected[0] && isSendingON){
268+
if(this->inletsConnected[0] && isSendingON && !static_cast<ofSoundBuffer *>(_inletParams[0])->getBuffer().empty()){
269269
*static_cast<ofSoundBuffer *>(_outletParams[0]) = *static_cast<ofSoundBuffer *>(_inletParams[0]);
270270
}else{
271-
*static_cast<ofSoundBuffer *>(_outletParams[0]) *= 0.0f;
271+
static_cast<ofSoundBuffer *>(_outletParams[0])->set(0.0f);
272272
}
273273
}
274274

src/objects/data/VectorAt.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void VectorAt::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
7373

7474
//--------------------------------------------------------------
7575
void VectorAt::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
76+
unusedArgs(patchObjects);
7677

7778
if(!loaded){
7879
loaded = true;
@@ -84,8 +85,8 @@ void VectorAt::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObject
8485
}
8586

8687
if(this->inletsConnected[0] && _inletParams[0]){
87-
if(static_cast<vector<float> *>(_inletParams[0])->size() > 0){
88-
if(vectorAt < static_cast<vector<float> *>(_inletParams[0])->size() && vectorAt >= 0){
88+
if(!static_cast<vector<float> *>(_inletParams[0])->empty()){
89+
if(vectorAt < static_cast<int>(static_cast<vector<float> *>(_inletParams[0])->size()) && vectorAt >= 0){
8990
*(float *)&_outletParams[0] = static_cast<vector<float> *>(_inletParams[0])->at(vectorAt);
9091
}else{
9192
*(float *)&_outletParams[0] = 0.0f;
@@ -102,6 +103,8 @@ void VectorAt::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObject
102103

103104
//--------------------------------------------------------------
104105
void VectorAt::drawObjectContent(ofTrueTypeFont *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
106+
unusedArgs(font,glRenderer);
107+
105108
ofSetColor(255);
106109

107110
}
@@ -156,7 +159,7 @@ void VectorAt::drawObjectNodeConfig(){
156159

157160
//--------------------------------------------------------------
158161
void VectorAt::removeObjectContent(bool removeFileFromData){
159-
162+
unusedArgs(removeFileFromData);
160163
}
161164

162165

src/objects/data/VectorConcat.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ void VectorConcat::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
8989

9090
//--------------------------------------------------------------
9191
void VectorConcat::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
92+
unusedArgs(patchObjects);
93+
9294
static_cast<vector<float> *>(_outletParams[0])->clear();
9395
for(int i=0;i<this->numInlets;i++){
94-
if(this->inletsConnected[i]){
96+
if(this->inletsConnected[i] && !static_cast<vector<float> *>(_inletParams[i])->empty()){
9597
for(size_t s=0;s<static_cast<size_t>(static_cast<vector<float> *>(_inletParams[i])->size());s++){
9698
static_cast<vector<float> *>(_outletParams[0])->push_back(static_cast<vector<float> *>(_inletParams[i])->at(s));
9799
}
@@ -115,6 +117,8 @@ void VectorConcat::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchOb
115117

116118
//--------------------------------------------------------------
117119
void VectorConcat::drawObjectContent(ofTrueTypeFont *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
120+
unusedArgs(font,glRenderer);
121+
118122
ofSetColor(255);
119123

120124
}
@@ -200,7 +204,7 @@ void VectorConcat::drawObjectNodeConfig(){
200204

201205
//--------------------------------------------------------------
202206
void VectorConcat::removeObjectContent(bool removeFileFromData){
203-
207+
unusedArgs(removeFileFromData);
204208
}
205209

206210
//--------------------------------------------------------------

src/objects/data/VectorExtract.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ void VectorExtract::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
7878

7979
//--------------------------------------------------------------
8080
void VectorExtract::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
81+
unusedArgs(patchObjects);
82+
8183
static_cast<vector<float> *>(_outletParams[0])->clear();
8284

83-
if(this->inletsConnected[0] && start < end){
84-
for(size_t s=start;s<end;s++){
85+
if(this->inletsConnected[0] && !static_cast<vector<float> *>(_inletParams[0])->empty() && start < end){
86+
for(int s=start;s<end;s++){
8587
static_cast<vector<float> *>(_outletParams[0])->push_back(static_cast<vector<float> *>(_inletParams[0])->at(s));
8688
}
8789
}
@@ -102,6 +104,8 @@ void VectorExtract::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchO
102104

103105
//--------------------------------------------------------------
104106
void VectorExtract::drawObjectContent(ofTrueTypeFont *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
107+
unusedArgs(font,glRenderer);
108+
105109
ofSetColor(255);
106110

107111
}
@@ -150,15 +154,15 @@ void VectorExtract::drawObjectNodeConfig(){
150154
if(start < 0){
151155
start = 0;
152156
}
153-
if(start > static_cast<vector<float> *>(_inletParams[0])->size()-2){
157+
if(start > static_cast<int>(static_cast<vector<float> *>(_inletParams[0])->size())-2){
154158
start = static_cast<vector<float> *>(_inletParams[0])->size()-2;
155159
}
156160
this->setCustomVar(static_cast<float>(start),"START");
157161
}
158162
ImGui::Spacing();
159163
int prevEnd = end;
160164
if(ImGui::InputInt("End",&end)){
161-
if(end > start && end <= static_cast<vector<float> *>(_inletParams[0])->size()-1){
165+
if(end > start && end <= static_cast<int>(static_cast<vector<float> *>(_inletParams[0])->size())-1){
162166
this->setCustomVar(static_cast<float>(end),"END");
163167
}else{
164168
end = prevEnd;
@@ -173,7 +177,7 @@ void VectorExtract::drawObjectNodeConfig(){
173177

174178
//--------------------------------------------------------------
175179
void VectorExtract::removeObjectContent(bool removeFileFromData){
176-
180+
unusedArgs(removeFileFromData);
177181
}
178182

179183

src/objects/data/VectorGate.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ void VectorGate::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
9595

9696
//--------------------------------------------------------------
9797
void VectorGate::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
98+
unusedArgs(patchObjects);
99+
98100
static_cast<vector<float> *>(_outletParams[0])->clear();
99101

100102
if(this->inletsConnected[0]){
101103
openInlet = static_cast<int>(floor(*(float *)&_inletParams[0]));
102104
}
103105

104-
if(openInlet >= 1 && openInlet < this->numInlets && this->inletsConnected[openInlet]){
106+
if(openInlet >= 1 && openInlet < this->numInlets && this->inletsConnected[openInlet] && !static_cast<vector<float> *>(_inletParams[openInlet])->empty()){
105107
for(size_t s=0;s<static_cast<size_t>(static_cast<vector<float> *>(_inletParams[openInlet])->size());s++){
106108
static_cast<vector<float> *>(_outletParams[0])->push_back(static_cast<vector<float> *>(_inletParams[openInlet])->at(s));
107109
}
@@ -126,6 +128,8 @@ void VectorGate::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObje
126128

127129
//--------------------------------------------------------------
128130
void VectorGate::drawObjectContent(ofTrueTypeFont *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
131+
unusedArgs(font,glRenderer);
132+
129133
ofSetColor(255);
130134

131135
}
@@ -210,7 +214,7 @@ void VectorGate::drawObjectNodeConfig(){
210214

211215
//--------------------------------------------------------------
212216
void VectorGate::removeObjectContent(bool removeFileFromData){
213-
217+
unusedArgs(removeFileFromData);
214218
}
215219

216220
//--------------------------------------------------------------

0 commit comments

Comments
 (0)