vanderlin / ofxBox2d

Openframework wrapper for box2d

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Variable length arrays in Visual Studio

MatillaMartin opened this issue · comments

In Visual Studio it does not compile due to the use of variable length arrays.

Problematic code (one of many):
https://github.com/vanderlin/ofxBox2d/blob/stable/src/ofxBox2dPolygonUtils.h#L115

If you are using GCC to compile, add the -pedantic during compilation.
http://stackoverflow.com/a/20011090/1890362

This is overcome with dynamic allocation in many places throughout the codebase. Not sure how it slipped through here.

I saw it changed in the master branch. What is the reason for using malloc instead of std::vector?

Imho, it should all be using vector. I'm in the process of cleaning up ofxBox2d for a class in teaching. If you're interested in making the fixes, I'd say go for it (I'm going to PR my updates again soon)

Hi, did in the meantime someone fix this problem? As I see the issue is still open and I'm having the same problem :s

Here I found a solution:
https://forum.openframeworks.cc/t/ofxbox2d-not-compiling/27004/4

"fix the code of file "of_v0.9.8_vs_release\addons\ofxbox2d\src\ofxBox2dPolygonUtils.h"
line 115
int mk[n];
to
int* mk = new int[n];
then it will work"

Doesn't this leak memory? I think you would need a delete [] mk at the end of that function as well (or use std::unique_ptr).

not sure if this is still an issue