Comments (9)
Excellent catch! Sorry for the trouble finding it. I changed all allocators to follow same pattern in the hopes that copy-pastering will not catch a bad habit in the future. Just to be sure, can you please review the changes and let me know if there is something silly with it.
from nanovg.
Just thinking out loud for a bit, I was wondering if the use of realloc
might cause some issues?
The glnvg__alloc*
s all use it like this:
gl->paths = (struct GLNVGpath*)realloc(gl->paths, sizeof(struct GLNVGpath) * gl->cpaths);
... which if realloc
fails all the old data is leaked and you're probably looking at a segfault in the near future?
Similar issues in nvg_add*
and nvg__appendCommands
where you do check for NULL
but still leak the old data -- and by not clearing e.g. ncommands
/ccommands
I guess the code is likely to try to dereference the NULL
later though I haven't looked at it closely.
I guess realloc
is pretty unlikely to fail on modern system, at least for what its used for here, but still might be something to consider. :)
from nanovg.
You're right. So pattern like would be better:
struct GLNVGpath* paths;
paths = (struct GLNVGpath*)realloc(gl->paths, sizeof(struct GLNVGpath) * gl->cpaths);
if (paths == NULL) fail;
gl->paths = paths;
I think the code should try to fail as close to the problem as possible, even if it is a segfault. So that code definitely needs a little improvements.
from nanovg.
Yeah. What you could maybe do is (at least for the gl-backend) change glnvg__alloc*
to somehow indicate allocation-failure, and then handle this in glnvg__render*
by allocating everything up front (with glnvg__allocCall
last) and either silently dropping the draw or reporting it through an error-callback or something. Not sure how complex you want to make this though: :)
from nanovg.
Take a look at 7f55dec I hope caught all cases.
from nanovg.
The only thing that jumps out at me is that you probably shouldn't update the capacity before you know the realloc
succeeds. Will run into problems the second time the function is called. :) Looks good otherwise!
from nanovg.
One more time... 02ca24a
Remote pair programming ftw! :)
from nanovg.
Indeed. :) Seems, compiles, and runs fine for me.
from nanovg.
Realloc changes look ok. And running without problems now.
from nanovg.
Related Issues (20)
- Manually loading images / Generating custom MipMaps for images HOT 3
- Disable blend for certain paths HOT 3
- FONS_GLYPH_BITMAP_OPTIONAL doesn't inhibit FT_LOAD in fons__tt_buildGlyphBitmap
- Fundamental text layout problem in nanovg
- Layer based drawing HOT 3
- outlines donβt draw properly HOT 2
- Edges of the curve are drawn at an angle HOT 9
- Draw an Arc with a Hole HOT 2
- Multiple scissors HOT 3
- Draw fill problems for complex polygons HOT 2
- Fix for MinGW: Replace -lGLEW with -lglew32
- support android ARGB format HOT 1
- Memory leak with freetype fonts [fix] HOT 4
- nvgArc does some ugly overdraw HOT 2
- [nvgTextBounds] string ending with space does not return expected bounds HOT 2
- `nvgArc` and `nvgArcTo` parameters correspondence and conversion
- building into a shared library HOT 6
- Transformation from Screen Space to World Space? HOT 1
- Arab, Hebrew and Persian
- ANSI Color Escape Sequences HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nanovg.