nikolausrauch / 2d-viewer Goto Github PK
View Code? Open in Web Editor NEWA 2D Viewer/Interface Library (OpenGL2) for drawing primitives / ui / plots
License: MIT License
A 2D Viewer/Interface Library (OpenGL2) for drawing primitives / ui / plots
License: MIT License
In your demo, there's a code passage at
Lines 71 to 77 in 9bb5068
When executed on a MacBook (with an M1 processor), it leads to the following error:
demo(55959,0x1dc8fd000) malloc: Incorrect checksum for freed object 0x14a608310: probably modified after being freed.
Corrupt value: 0x343bbd2e3f800000
demo(55959,0x1dc8fd000) malloc: *** set a breakpoint in malloc_error_break to debug
[1] 55959 abort ./bin/demo
It appears that the initialization of the new vector (vertices
) in this function is broken on MacOS. Specifically, referring to
Lines 50 to 58 in 9bb5068
There could be two (or more) ways (for now) to fix this:
You could do something like:
#ifndef __APPLE__
std::vector<glm::vec2> vertices(mRender.circleVertices);
for (unsigned int i = 0; i <= mRender.circleVertices; i++) {
vertices[i] = {
radius * glm::cos(2.0 * glm::pi<float>() * static_cast<float>(i) / mRender.circleVertices),
radius * glm::sin(2.0 * glm::pi<float>() * static_cast<float>(i) / mRender.circleVertices)};
}
#endif
...
for (unsigned int i = 0; i <= mRender.circleVertices; i++) {
#ifdef __APPLE__
glVertex2f(position.x + radius * radius * glm::cos(2.0 * glm::pi<float>() * static_cast<float>(i) / mRender.circleVertices),
position.y + radius * radius * glm::sin(2.0 * glm::pi<float>() * static_cast<float>(i) / mRender.circleVertices));
#else
glVertex2f(position.x + radius * vertices[i].x,
position.y + radius * vertices[i].y);
#endif
}
Or, without the #ifdef
:
...
for (unsigned int i = 0; i <= mRender.circleVertices; i++) {
const float angle = 2.0 * glm::pi<float>() * static_cast<float>(i) / mRender.circleVertices; // For readability purposes
glVertex2f(position.x + radius * radius * glm::cos(angle),
position.y + radius * radius * glm::sin(angle));
}
As you mentioned, you're not exactly sure why this happens, but with these changes, it wouldn't occur anymore. Additionally, you questioned why the vertices
array is used in the first place, since, from your understanding, these vertices are only used once.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.