vgAppendPathData and float pointers

So I’ve got OpenVG (via ShivaVG) rendering the SVG tiger IF I use the float[] arrays it defines. However, I wrote a simple SVG loader (loads in only paths and only move to and cubic curves) and if I pass my float pointer (float *blah = new[dataCount]:wink: , it just hangs the application in vgAppendPathData.

(Edit: I’ve verified that my data is valid several times, including putting it into a compile time array. Additionally, the vgGetError() function returns VG_NO_ERROR after creating and appending the path)

The reference also uses a compile time array, so it’s no help. I was planning on cleaning up my load function and releasing what I have (at the very least as a working example of getting ShivaVG set up with SDL, not that that was terribly difficult), but this issue has me stuck. So whoever helps me will be the first to see the code :slight_smile:

Needless to say, it should work… Whether ShivaVG can do it or not, I don’t know… I don’t use it (I’ve had some bad experiences with it).

Try checking the following:

  • vgCreatePath() is called and includes the capability to appendpathdata (why this is even an option I don’t know…)
  • make sure that vgCreatePath() is created with floating point number format.
  • make sure your pointer is word aligned ((int)pointer & 3).
  • make sure that your stream of VG commands is valid and matches your data.
  • make sure you’re not doing something silly like passing a pointer to a pointer (instead of a pointer) or something similar.
  • double check that your scale value is valid [not 0 or #INF] (in vgCreatePath()).

If all that fails, post the exact the exact code snippet and I’ll see if I spot anything else. Good Luck.

I’ve checked most of those items. I checked the word alignment of the pointer (I’m assuming you mean that (int)point & 3 will return 0 or 1 being not word aligned and word aligned, respectively) and it is apparently not word aligned. I guess I’m just a noob in this area, but I’m having trouble finding anything regarding this. Do you think you could elaborate? I’m guessing this is probably my issue.

Edit: Well I’ve searched some and uncovered some mildly helpful documents. I’m still unsure how to fix it in a way that isn’t a ridiculous hack, however.

It will actually return 0,1,2,or 3 - only 0 is good - the rest are bad. Since you’re using the new operator though on a float, I highly doubt that it’s an alignment issue (the compiler should do that for you).
Post the snippet.

If I had to guess, and you’re causing a crash, I’d guess you’re doing something like:

  • allocating some array (let’s call it ‘data’) of floats
    the doing something like
    vgAppendPathData(path, num_cmds, &cmds, &data);
    but arrays in C/C++ are auto-magically passed as pointers, so the line should read:
    vgAppendPathData(path, num_cmds, cmds, data);
    [the extra & operator would give a address of where the pointer to the data is stored, instead of a pointer to the data itself]

Again - I have no way of knowing what you’re doing wrong without seeing the relevant bits of code.

Ah, then that’s not the issue. It doesn’t actually crash, for one thing. It returns success status codes after the vgAppendPathData call, then just hangs when I try to draw the path.

I’ll post snippets later tonight when I’m off work.

I know I’m definitely not passing it as a ** (pointer pointer), my call looks like vgAppendPathData( path, commandCount, cmds, data ). (cmds is a byte pointer in this case, and data is a float pointer).

Well, I found the issue. It was my bug. However, I’m getting some output I don’t really understand. Whenever I have a stroke on a path, it essentially just fills the inside of the path with the color for that stroke. If the stroke width is set to 0, the background color shows through correctly (it’s drawing both, the fill then the stroke, but the stroke is covering the same exact area as the fill, but with its own color).

My setup for the stroke/fill paint is essentially stock, I set them before drawing in the regular manner…

Glad you found the bug. What was it if you don’t mind me asking?

About your new issue - I’m guessing your stroke width is too large - IIRC by default is 4. So, for example, you draw your path in some normalized coordinates space like [0…1], then your stroke width will be so huge it’ll look like a fill. Just set the stroke width smaller (“width / scale_factor” type of thing [or try like 0.01 to test the theory]).

Well I had a bug in my parsing code. When parsing each pair of values, I wasn’t incrementing the index to put the data at by 2 instead of 1, so it was filling only half the array and leaving the rest of the points at essentially float_max, so when it was hanging, I assume it was attempting to rasterize all the way to those positions.

I’m really not sure what range OpenVG uses. The value from Inkscape in SVG is something like 1.7. Thing is, I would expect to see a very large stroke color on the outside of the path? Currently it only covers the area
of the fill, it doesn’t extend outside it, which if it was just the width being too great I would expect to see.

Edit: Also, where is the 0,0 point of the coordinates in OpenVG? That is, which corner is it? It’s hard to get my objects centered without knowing more explicitly than I do at the moment.

I greatly appreciate your help Ivo!

Edit: I’ve done some testing after getting home today. Even with a stroke width of 0.17, the stroke covers exactly the area that the fill does. It isn’t even straddling the path in the right fashion, since even if it covered all of the fill area, it would still be a larger rect.

Upon further testing, it appears that no matter what path I put in, it ends up outputting a square or a quad of roughly the same dimensions. It happens regardless of whether or not the actual path is open or closed, fill or no fill. It doesn’t happen if the amount of segments/commands is only 2 (i.e., a moveto and a lineto work). I’ve attached a screenshot with the input path and the output render.

Fixed! I had commented out where I was setting the stencil buffer up for SDL.

Edit: Blah. New problem: it only renders the last path, despite the fact that I only clear once per render (at the start) and do a loop of vgDrawPaths after. :confused: Yikes.

Also, not sure why, but the rendering quality on my paths is terrible. Not like the reference app at all (appears to be no antialiasing at all). I’ve tried setting the rendering quality without result.

VG’s coordinate system has (0,0) in the bottom left corner.

As for your new problem… you are creating a separate path for each path your are trying to render, right? Ah well - nothing you wont fix with a little debugging I’m sure.

As for rendering quality… I have not used ShivaVG much - the little I did use it, left me rather unimpressed. For anti-aliasing you may have to make sure multi-sampling is turned on when you create the window (if Shiva supports it at all) [also might not hurt to make sure you vgSeti() your VG_RENDERING_QUALITY is set to faster(default?) or better]. If you’re running windows, I recommend you trying to find Hybrid’s old Rasteroid software renderer or using AmanithVG for now to do your developing on. If it is a problem with ShivaVG, hopefully someone will fix it by the time you’re ready for release.

Enabling multisampling in SDL did the trick for quality. The issue with it only actually drawing the last path has me stumped…

I’d love to use AmanithVG (it was my first choice early on due to speed and quality of the lib) but AFAIK one can’t get a hold of it? Any word on how much licenses are?

I found the AVG GLE evaluation. I managed to quickly switch my app over to use it (switch the lib, copy the new includes over, change the init context function) and I get the same exact results as with Shiva. The quality appears to be the same now that I’ve enabled multisampling in SDL.

It’s got to be my bug causing it to only render one path, given it happens between both libraries.

@Ivo, no insight about what could possibly be causing it to only render a single path?

Edit: Fixed :slight_smile: I had a bug in the way I was allocating the VGPaths array I’m using.

Edit edit: Celebratory screenshot of input and output. It’s taken 2 years of procrastination on my part after failed attempts with Cairo (too slow!), but I’ve finally got rudimentary SVG loading and rendering that’s fast enough to actually make a game feasible.