U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Strange issue with text in Painter
Re: Strange issue with text in Painter [message #50920 is a reply to message #50919] Mon, 14 January 2019 11:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Tom1 wrote on Mon, 14 January 2019 11:52
This shows the problem:
BR, Tom


Now that is crazy, is not it? Smile

Must be some overlooked undefined behaviour somewhere.
Re: Strange issue with text in Painter [message #50921 is a reply to message #50916] Mon, 14 January 2019 11:57 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Mon, 14 January 2019 12:41
Thinking about it, I have suspiction that maybe RawPickToValue might have to do something with all that...

What about this:

struct sMakeGlyph : LRUCache<String, GlyphKey>::Maker {
	GlyphKey gk;

	GlyphKey Key() const     { return gk; }
	int      Make(String& v) const {
		GlyphPainter gp;
		gp.move = gp.pos = Null;
		gp.tolerance = gk.tolerance;
		PaintCharacter(gp, Pointf(0, 0), gk.chr, gk.fnt);
		int sz = gp.glyph.GetCount() * 4;
		v.Set((char *)gp.glyph.begin(), sizeof(float) * gp.glyph.GetCount());
		return sz;
	}
};

void ApproximateChar(LinearPathConsumer& t, Pointf at, int ch, Font fnt, double tolerance)
{
	PAINTER_TIMING("ApproximateChar");
	String v;
	INTERLOCKED {
		PAINTER_TIMING("ApproximateChar::Fetch");
		static LRUCache<String, GlyphKey> cache;
		cache.Shrink(500000);
		sMakeGlyph h;
		h.gk.fnt = fnt;
		h.gk.chr = ch;
		h.gk.tolerance = tolerance;
		v = cache.Get(h);
	}
	int i = 0;
	int count = v.GetCount() / sizeof(float);
	const float *g = (const float *)~v;
	while(i < count) {
		Pointf p;
		p.x = g[i++];
		if(p.x > 1e30) {
			p.x = g[i++];
			p.y = g[i++];
			t.Move(p + at);
		}
		else {
			PAINTER_TIMING("ApproximateChar::Line");
			p.y = g[i++];
			t.Line(p + at);
		}
	}
}


The problem is still there with the above code.

BR, Tom
Re: Strange issue with text in Painter [message #50922 is a reply to message #50921] Mon, 14 January 2019 12:03 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Are you 100% sure that there is no other thread running using Painter (perhaps painting something entirely different) or maybe even Draw or Font? No background threads?

Mirek
Re: Strange issue with text in Painter [message #50924 is a reply to message #50922] Mon, 14 January 2019 12:14 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Have you tried this on another computer? (Blaming HW is the last thing I usually do, but this is way too weird...)

Mirek
Re: Strange issue with text in Painter [message #50925 is a reply to message #50924] Mon, 14 January 2019 12:16 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
As the difference IMO amounts to some waste CPU cycles only, maybe we could try to insert some small delay instead of RenderCharacterSys2....
Re: Strange issue with text in Painter [message #50926 is a reply to message #50922] Mon, 14 January 2019 12:21 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
According to Windows Task Manager, there are 30 threads running on this process. But my GUI is simply running on main thread. There should be nothing graphical going on in any of my background threads.

Here's an interesting part: I said previously that ST/MT in Painter did not make any difference. Well, it did not when I had started the program originally with Painter MT enabled and then switched 'live' to ST to test for the error effect. BUT: Now I started with Painter fixed in ST and: Error is gone... Sounds like in my original MT/ST test the font caching in Painter had already happened in MT before I switched it to ST.

I need to dig deeper on this.

BR, Tom

Re: Strange issue with text in Painter [message #50927 is a reply to message #50924] Mon, 14 January 2019 12:22 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Mon, 14 January 2019 13:14
Have you tried this on another computer? (Blaming HW is the last thing I usually do, but this is way too weird...)

Mirek


Need to try that too.
Re: Strange issue with text in Painter [message #50928 is a reply to message #50926] Mon, 14 January 2019 12:30 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Tom1 wrote on Mon, 14 January 2019 12:21
According to Windows Task Manager, there are 30 threads running on this process. But my GUI is simply running on main thread. There should be nothing graphical going on in any of my background threads.

Here's an interesting part: I said previously that ST/MT in Painter did not make any difference. Well, it did not when I had started the program originally with Painter MT enabled and then switched 'live' to ST to test for the error effect. BUT: Now I started with Painter fixed in ST and: Error is gone... Sounds like in my original MT/ST test the font caching in Painter had already happened in MT before I switched it to ST.

I need to dig deeper on this.

BR, Tom



Well, that makes better sense - as the only possible difference there seem to be the delay, this would point to some sort of race condition. Probably the wrong glyph was cached BEFORE ST was activated....

Maybe there is a problem with INTERLOCKED. Can you try to replace it with explicit mutex?

Mirek
Re: Strange issue with text in Painter [message #50929 is a reply to message #50928] Mon, 14 January 2019 12:41 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
Replaced INTERLOCKED with StaticMutex, but no change... I Will continue testing.

BR, Tom
Re: Strange issue with text in Painter [message #50930 is a reply to message #50929] Mon, 14 January 2019 13:23 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Try this pls:

Buffer<ClippingLine> BufferPainter::RenderPath(double width, Event<One<SpanSource>&> ss, const RGBA& color)
{
	PAINTER_TIMING("RenderPath");
	Buffer<ClippingLine> newclip;

	if(width == FILL)
		Close();

	current = Null;

	if(width == 0 || !ss && color.a == 0 && width >= FILL)
		return newclip;
	
	if(pathattr.mtx_serial != preclip_mtx_serial) {
		if(dopreclip) {
			Pointf tl, br, a;
			Xform2D imx = Inverse(pathattr.mtx);
			tl = br = imx.Transform(0, 0);
			a = imx.Transform(size.cx, 0);
			tl = min(a, tl);
			br = max(a, br);
			a = imx.Transform(0, size.cy);
			tl = min(a, tl);
			br = max(a, br);
			a = imx.Transform(size.cx, size.cy);
			tl = min(a, tl);
			br = max(a, br);
			preclip = Rectf(tl, br);
		}
		else
			preclip = Null;
		regular = pathattr.mtx.IsRegular();
		preclip_mtx_serial = pathattr.mtx_serial;
	}

	if(co) {
		if(width >= FILL && !ss && !alt && findarg(mode, MODE_ANTIALIASED, MODE_SUBPIXEL) >= 0 && !path_info->ischar) {


(The difference is && !path_info->ischar in the last line).

Also, is there a difference DEBUG vs RELEASE?
Re: Strange issue with text in Painter [message #50931 is a reply to message #50924] Mon, 14 January 2019 13:26 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Mon, 14 January 2019 13:14
Have you tried this on another computer? (Blaming HW is the last thing I usually do, but this is way too weird...)

Mirek


Tried with my old reliable notebook, but it's the same.

BR, Tom
Re: Strange issue with text in Painter [message #50932 is a reply to message #50930] Mon, 14 January 2019 13:53 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Mon, 14 January 2019 14:23
Try this pls:

Buffer<ClippingLine> BufferPainter::RenderPath(double width, Event<One<SpanSource>&> ss, const RGBA& color)
{
	PAINTER_TIMING("RenderPath");
	Buffer<ClippingLine> newclip;

	if(width == FILL)
		Close();

	current = Null;

	if(width == 0 || !ss && color.a == 0 && width >= FILL)
		return newclip;
	
	if(pathattr.mtx_serial != preclip_mtx_serial) {
		if(dopreclip) {
			Pointf tl, br, a;
			Xform2D imx = Inverse(pathattr.mtx);
			tl = br = imx.Transform(0, 0);
			a = imx.Transform(size.cx, 0);
			tl = min(a, tl);
			br = max(a, br);
			a = imx.Transform(0, size.cy);
			tl = min(a, tl);
			br = max(a, br);
			a = imx.Transform(size.cx, size.cy);
			tl = min(a, tl);
			br = max(a, br);
			preclip = Rectf(tl, br);
		}
		else
			preclip = Null;
		regular = pathattr.mtx.IsRegular();
		preclip_mtx_serial = pathattr.mtx_serial;
	}

	if(co) {
		if(width >= FILL && !ss && !alt && findarg(mode, MODE_ANTIALIASED, MODE_SUBPIXEL) >= 0 && !path_info->ischar) {


(The difference is && !path_info->ischar in the last line).

Also, is there a difference DEBUG vs RELEASE?


In RELEASE mode I could not find a single bad letter in 15 minutes. I think this is it!

Will try now with DEBUG...

BR, Tom
Re: Strange issue with text in Painter [message #50933 is a reply to message #50932] Mon, 14 January 2019 14:11 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
Not a single false character in DEBUG mode either. Smile

I should have found something already if the problem still existed.

So, is this the fix or means for problem isolation?

Best regards,

Tom
Re: Strange issue with text in Painter [message #50934 is a reply to message #50933] Mon, 14 January 2019 15:03 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Tom1 wrote on Mon, 14 January 2019 14:11
Not a single false character in DEBUG mode either. Smile

I should have found something already if the problem still existed.

So, is this the fix or means for problem isolation?

Best regards,

Tom


This basically disables MT for character rendering...

So for now, please revert it and try two separate things for me:

void Painter::TextOp(const Pointf& p, const wchar *text, Font fnt, int n, const double *dx)
{
	if(n == 0) {
		Move(0, 0);
		return;
	}
	FontInfo fi = fnt.Info();
	double x = p.x;
	while(n) {
		int ch = *text++;
		Character(x, p.y, ch, fnt);
//		Div();
		if(dx)
			x += *dx++;
		else
			x += fi[ch];
		n--;
	}
	if(fnt.IsUnderline() || fnt.IsStrikeout()) {
		double a = fnt.GetAscent();
		double cy = max(a / 16, 1.0);
		double cx = x - p.x;
		if(fnt.IsUnderline())
			Rectangle(p.x, p.y + a + cy, cx, cy);
		if(fnt.IsStrikeout())
			Rectangle(p.x, p.y + 2 * a / 3, cx, cy);
	}
}


(This might lead to some new artifacts where characters overlap, that is expected, look for the original problem (wrong characters).

void BufferPainter::RenderPathSegments(LinearPathConsumer *g, const Vector<byte>& path,
                                       const SimpleAttr *attr, double tolerance)
{
	Pointf pos = Pointf(0, 0);
	const byte *data = path.begin();
	const byte *end = path.end();
	while(data < end) {
		const LinearData *d = (LinearData *)data;
		switch(d->type) {
		case MOVE: {
			g->Move(pos = attr ? attr->mtx.Transform(d->p) : d->p);
			data += sizeof(LinearData);
			break;
		}
		case LINE: {
			PAINTER_TIMING("LINE");
			g->Line(pos = attr ? attr->mtx.Transform(d->p) : d->p);
			data += sizeof(LinearData);
			break;
		}
		case QUADRATIC: {
			PAINTER_TIMING("QUADRATIC");
			const QuadraticData *d = (QuadraticData *)data;
			if(attr) {
				Pointf p = attr->mtx.Transform(d->p);
				ApproximateQuadratic(*g, pos, attr->mtx.Transform(d->p1), p, tolerance);
				pos = p;
			}
			else {
				ApproximateQuadratic(*g, pos, d->p1, d->p, tolerance);
				pos = d->p;
			}
			data += sizeof(QuadraticData);
			break;
		}
		case CUBIC: {
			PAINTER_TIMING("CUBIC");
			const CubicData *d = (CubicData *)data;
			if(attr) {
				Pointf p = attr->mtx.Transform(d->p);
				ApproximateCubic(*g, pos, attr->mtx.Transform(d->p1),
				                 attr->mtx.Transform(d->p2), p, tolerance);
				pos = p;
			}
			else {
				ApproximateCubic(*g, pos, d->p1, d->p2, d->p, tolerance);
				pos = d->p;
			}
			data += sizeof(CubicData);
			break;
		}
		case CHAR: {
			const CharData *ch = (CharData *)data;
			INTERLOCKED ApproximateChar(*g, ch->p, ch->ch, ch->fnt, tolerance);
			data += sizeof(CharData);
			break;
		}
		default:
			NEVER();
			g->End();
			return;
		}
	}
	g->End();
}


(Additional mutex in for CHAR).

Thanks,

Mirek

[Updated on: Mon, 14 January 2019 15:13]

Report message to a moderator

Re: Strange issue with text in Painter [message #50935 is a reply to message #50934] Mon, 14 January 2019 15:18 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
Neither of the above help... false letters can still be found.

BR, Tom

Update: I see you updated something in posting. I need to re-test.

[Updated on: Mon, 14 January 2019 15:19]

Report message to a moderator

Re: Strange issue with text in Painter [message #50936 is a reply to message #50935] Mon, 14 January 2019 15:34 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
OK, now it looks like "void Painter::TextOp(const Pointf& p, const wchar *text, Font fnt, int n, const double *dx)" -fix would correct the issue.

The other does not have any effect.

BR, Tom

[Updated on: Mon, 14 January 2019 15:35]

Report message to a moderator

Re: Strange issue with text in Painter [message #50937 is a reply to message #50936] Mon, 14 January 2019 15:38 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
No, false positive. The problem is still there even after the "void Painter::TextOp(const Pointf& p, const wchar *text, Font fnt, int n, const double *dx)" -fix.

BR, Tom
Re: Strange issue with text in Painter [message #50938 is a reply to message #50937] Mon, 14 January 2019 16:08 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Tom1 wrote on Mon, 14 January 2019 15:38
No, false positive. The problem is still there even after the "void Painter::TextOp(const Pointf& p, const wchar *text, Font fnt, int n, const double *dx)" -fix.

BR, Tom


Well, for today I am out of ideas.... Will continue tomorrow, OK?

Perhaps one last question: This probably must have started recently, probably after the last round of optimizations. Is that correct?

Mirek
Re: Strange issue with text in Painter [message #50939 is a reply to message #50938] Mon, 14 January 2019 17:21 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
Hi,

Yes, I'm also out of time for today. Tomorrow I will have time until about 14:00 EET.

The first time I noticed this was just last week when I reported it. I had not updated from SVN in a while before that though, so I may need to go back a bit further in time to find that.

One potential reason for finding this issue is that I had just recently reached a point in my own code where I started to rotate the texts according to the original scale and rotation, both of which change constantly over the projection surface for maps where a change from one map projection to another has been carried out.

In effect this has caused an overwhelming increase in cached fonts here in my application. I think the reason is that when tolerance changes even by the smallest fraction of a double, it necessitates a new cache entry. In my case there will be a huge amount of cache entries. Actually, if the tolerance parameter were made more discrete, e.g. through classing to slots for caching, the problem might not show up at all or at least do it extremely rarely. Then again, I think, the potential issue with caching should be corrected first, if real, and only thereafter should the optimization through classing be implemented.

I might have it all wrong here, but this is just a thought.

Anyway, Mirek, thanks for your efforts today on the task!

Best regards,

Tom
Re: Strange issue with text in Painter [message #50940 is a reply to message #50939] Mon, 14 January 2019 17:45 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Tom1 wrote on Mon, 14 January 2019 17:21
One potential reason for finding this issue is that I had just recently reached a point in my own code where I started to rotate the texts according to the original scale and rotation, both of which change constantly over the projection surface for maps where a change from one map projection to another has been carried out.

In effect this has caused an overwhelming increase in cached fonts here in my application.


Rotated texts in Painter are rotated by Painter matrix, they are cached in zero angle position...

Anyway, good info, I will think about this all...

Mirek
Re: Strange issue with text in Painter [message #50941 is a reply to message #50940] Mon, 14 January 2019 18:31 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Mon, 14 January 2019 18:45
Tom1 wrote on Mon, 14 January 2019 17:21
One potential reason for finding this issue is that I had just recently reached a point in my own code where I started to rotate the texts according to the original scale and rotation, both of which change constantly over the projection surface for maps where a change from one map projection to another has been carried out.

In effect this has caused an overwhelming increase in cached fonts here in my application.


Rotated texts in Painter are rotated by Painter matrix, they are cached in zero angle position...

Anyway, good info, I will think about this all...

Mirek


Well, yes, they are indeed cached in zero angle position. I should have expressed myself more clearly to make the point: Both fine scaling and fine rotation changes ultimately have an effect on double tolerance value solved using the Painter matrix scale and stored as caching key. This is also why rotating the image sometimes corrected the problem. Please see my early screenshots in this thread. (The changes would have been just at a magnitude of rounding errors i.e. just some LSBs.)

BR, Tom

[Updated on: Mon, 14 January 2019 18:37]

Report message to a moderator

Re: Strange issue with text in Painter [message #50942 is a reply to message #50941] Mon, 14 January 2019 18:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Tom1 wrote on Mon, 14 January 2019 18:31
mirek wrote on Mon, 14 January 2019 18:45
Tom1 wrote on Mon, 14 January 2019 17:21
One potential reason for finding this issue is that I had just recently reached a point in my own code where I started to rotate the texts according to the original scale and rotation, both of which change constantly over the projection surface for maps where a change from one map projection to another has been carried out.

In effect this has caused an overwhelming increase in cached fonts here in my application.


Rotated texts in Painter are rotated by Painter matrix, they are cached in zero angle position...

Anyway, good info, I will think about this all...

Mirek


Well, yes, they are indeed cached in zero angle position. I should have expressed myself more clearly to make the point: Both fine scaling and fine rotation changes ultimately have an effect on double tolerance value solved using the Painter matrix scale and stored as caching key. This is also why rotating the image sometimes corrected the problem. Please see my early screenshots in this thread. (The changes would have been just at a magnitude of rounding errors i.e. just some LSBs.)

BR, Tom


Well, yes, thats something I have missed so far. This is true and actually something to fix (probably round tolerance to like 10%).
Re: Strange issue with text in Painter [message #50944 is a reply to message #50942] Mon, 14 January 2019 19:53 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
EDIT: Perhaps check the possible fix first - the last post "OK, now I see possible bug, hard to say it is related, but please test:" and do testing only if it fails.

To test:

void BufferPainter::FinishPathJob()
{
	if(jobcount == 0)
		return;
/*	CoWork co;
	co * [&] {
		for(;;) {
			int i = co.Next();
			if(i >= jobcount)
				break;
			CoJob& b = cojob[i];
			b.rasterizer.Reset();
			PathJob j(b.rasterizer, b.width, b.path_info, b.attr, b.preclip, b.regular);
			if(!j.preclipped) {
				b.evenodd = j.evenodd;
				BufferPainter::RenderPathSegments(j.g, b.path_info->path[b.subpath], j.regular ? &b.attr : NULL, j.tolerance);
			}
		}
	};*/
	for(int i = 0; i < jobcount; i++) {
		CoJob& b = cojob[i];
		b.rasterizer.Reset();
		PathJob j(b.rasterizer, b.width, b.path_info, b.attr, b.preclip, b.regular);
		if(!j.preclipped) {
			b.evenodd = j.evenodd;
			BufferPainter::RenderPathSegments(j.g, b.path_info->path[b.subpath], j.regular ? &b.attr : NULL, j.tolerance);
		}
	}

	FinishFillJob();
	
	fillcount = jobcount;
	Swap(cofill, cojob); // Swap to keep allocated rasters (instead of pick)


(Changing the path rendering to run in ST)

[Updated on: Mon, 14 January 2019 22:57]

Report message to a moderator

Re: Strange issue with text in Painter [message #50945 is a reply to message #50944] Mon, 14 January 2019 20:51 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Worth testing how much tolerance has to do with it:

BufferPainter::PathJob::PathJob(Rasterizer& rasterizer, double width, const PathInfo *path_info,
                                const SimpleAttr& attr, const Rectf& preclip, bool isregular)
:	trans(attr.mtx)
{
	evenodd = attr.evenodd;
	regular = isregular && width < 0 && !path_info->ischar;

	g = &rasterizer;

	if(!IsNull(preclip.left) && !path_info->ischar) {
		double ex = max(width, 0.0) * (1 + attr.miter_limit);
		if(path_info->path_max.y + ex < preclip.top || path_info->path_min.y - ex > preclip.bottom ||
		   path_info->path_max.x + ex < preclip.left || path_info->path_min.x - ex > preclip.right) {
			preclipped = true;
			return;
		}
	}

	preclipped = false;

	if(regular)
		tolerance = 0.3;
	else {
		trans.target = g;
		g = &trans;
		tolerance = 0.3 / attr.mtx.GetScale();
	}

        tolerance = 0.3; // add this...
Re: Strange issue with text in Painter [message #50946 is a reply to message #50945] Mon, 14 January 2019 20:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
OK, now I see possible bug, hard to say it is related, but please test:

void BufferPainter::FinishPathJob()
{
	if(jobcount == 0)
		return;
	{
		CoWork co;
		co * [&] {
			for(;;) {
				int i = co.Next();
				if(i >= jobcount)
					break;
				CoJob& b = cojob[i];
				b.rasterizer.Reset();
				PathJob j(b.rasterizer, b.width, b.path_info, b.attr, b.preclip, b.regular);
				if(!j.preclipped) {
					b.evenodd = j.evenodd;
					BufferPainter::RenderPathSegments(j.g, b.path_info->path[b.subpath], j.regular ? &b.attr : NULL, j.tolerance);
				}
			}
		};
	}

	FinishFillJob();


(The difference is that CoWork is now inside block).
Re: Strange issue with text in Painter [message #50950 is a reply to message #50946] Tue, 15 January 2019 08:42 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Mon, 14 January 2019 21:56
OK, now I see possible bug, hard to say it is related, but please test:

void BufferPainter::FinishPathJob()
{
	if(jobcount == 0)
		return;
	{
		CoWork co;
		co * [&] {
			for(;;) {
				int i = co.Next();
				if(i >= jobcount)
					break;
				CoJob& b = cojob[i];
				b.rasterizer.Reset();
				PathJob j(b.rasterizer, b.width, b.path_info, b.attr, b.preclip, b.regular);
				if(!j.preclipped) {
					b.evenodd = j.evenodd;
					BufferPainter::RenderPathSegments(j.g, b.path_info->path[b.subpath], j.regular ? &b.attr : NULL, j.tolerance);
				}
			}
		};
	}

	FinishFillJob();


(The difference is that CoWork is now inside block).


Good morning,

This does not help. The problem is still there.

BR, Tom
Re: Strange issue with text in Painter [message #50951 is a reply to message #50944] Tue, 15 January 2019 08:53 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Mon, 14 January 2019 20:53
EDIT: Perhaps check the possible fix first - the last post "OK, now I see possible bug, hard to say it is related, but please test:" and do testing only if it fails.

To test:

void BufferPainter::FinishPathJob()
{
	if(jobcount == 0)
		return;
/*	CoWork co;
	co * [&] {
		for(;;) {
			int i = co.Next();
			if(i >= jobcount)
				break;
			CoJob& b = cojob[i];
			b.rasterizer.Reset();
			PathJob j(b.rasterizer, b.width, b.path_info, b.attr, b.preclip, b.regular);
			if(!j.preclipped) {
				b.evenodd = j.evenodd;
				BufferPainter::RenderPathSegments(j.g, b.path_info->path[b.subpath], j.regular ? &b.attr : NULL, j.tolerance);
			}
		}
	};*/
	for(int i = 0; i < jobcount; i++) {
		CoJob& b = cojob[i];
		b.rasterizer.Reset();
		PathJob j(b.rasterizer, b.width, b.path_info, b.attr, b.preclip, b.regular);
		if(!j.preclipped) {
			b.evenodd = j.evenodd;
			BufferPainter::RenderPathSegments(j.g, b.path_info->path[b.subpath], j.regular ? &b.attr : NULL, j.tolerance);
		}
	}

	FinishFillJob();
	
	fillcount = jobcount;
	Swap(cofill, cojob); // Swap to keep allocated rasters (instead of pick)


(Changing the path rendering to run in ST)


This fixes the issue.

I do not know if this has anything to do with it, but I have noticed that I cannot pass reference variables as parameters to CoWork::Do() -called functions. Compiler does not complain, but the code simply does not work correctly. I have had to switch to using pointers as parameters instead of reference variables in such functions.

BR, Tom
Re: Strange issue with text in Painter [message #50953 is a reply to message #50945] Tue, 15 January 2019 09:11 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
Hi,

As for forcing "tolerance = 0.3;" likely decreases the number of cache entries to a fraction of the original in this case, the likelihood to see any issues drops equally. And so it seems: I cannot see a single erroneous character.

Then again, I can check about 1000 names in a reasonable time on screen and if the problem is there, I will see just a few errors. I think that it becomes just a few errors in a million now, so I'm not 'lucky enough' to find them.

BR, Tom
Re: Strange issue with text in Painter [message #50954 is a reply to message #50951] Tue, 15 January 2019 09:15 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Tom1 wrote on Tue, 15 January 2019 08:53

I do not know if this has anything to do with it, but I have noticed that I cannot pass reference variables as parameters to CoWork::Do() -called functions. Compiler does not complain, but the code simply does not work correctly. I have had to switch to using pointers as parameters instead of reference variables in such functions.


That should not be issue here. Now all depends on details, but you always have to be careful that referenced variable exists until CoWork Finish or destructor... If you think that you have non-working example of different nature, please start a new thread a post it...

Mirek
Re: Strange issue with text in Painter [message #50955 is a reply to message #50953] Tue, 15 January 2019 09:17 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
Tom1 wrote on Tue, 15 January 2019 09:11
Hi,

As for forcing "tolerance = 0.3;" likely decreases the number of cache entries to a fraction of the original in this case, the likelihood to see any issues drops equally. And so it seems: I cannot see a single erroneous character.

Then again, I can check about 1000 names in a reasonable time on screen and if the problem is there, I will see just a few errors. I think that it becomes just a few errors in a million now, so I'm not 'lucky enough' to find them.

BR, Tom


Understood, I mainly just wanted to know if the hypothesis is correct... (Revert the change, later I will introduce a nice simple fix to round tolerance, but we need to find the bug first).

Mirek
Re: Strange issue with text in Painter [message #50956 is a reply to message #50852] Tue, 15 January 2019 09:21 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
I am also trying to reproduce the issue here; anyway the paintings I have here only has a couple o texts in it.

Now I am not sure you have any level-of-detail systeme there, but if not, would it be possible to send me extremely zoomed out painting file so that it has more texts in it?

(That said, when testing, do you start with such zoomed-out situation?)
Re: Strange issue with text in Painter [message #50957 is a reply to message #50956] Tue, 15 January 2019 09:23 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
void BufferPainter::FinishPathJob()
{
	if(jobcount == 0)
		return;

	CoWork co;
	co * [&] {
		for(;;) {
			int i = co.Next();
			if(i >= jobcount)
				break;
			INTERLOCKED {
			CoJob& b = cojob[i];
			b.rasterizer.Reset();
			PathJob j(b.rasterizer, b.width, b.path_info, b.attr, b.preclip, b.regular);
			if(!j.preclipped) {
				b.evenodd = j.evenodd;
				BufferPainter::RenderPathSegments(j.g, b.path_info->path[b.subpath], j.regular ? &b.attr : NULL, j.tolerance);
			}
			}
		}
	};


If problem disappears, try to move INTERLOCKED down line by line (until if) to see when/if it reappears.
Re: Strange issue with text in Painter [message #50958 is a reply to message #50954] Tue, 15 January 2019 09:30 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Tue, 15 January 2019 10:15
Tom1 wrote on Tue, 15 January 2019 08:53

I do not know if this has anything to do with it, but I have noticed that I cannot pass reference variables as parameters to CoWork::Do() -called functions. Compiler does not complain, but the code simply does not work correctly. I have had to switch to using pointers as parameters instead of reference variables in such functions.


That should not be issue here. Now all depends on details, but you always have to be careful that referenced variable exists until CoWork Finish or destructor... If you think that you have non-working example of different nature, please start a new thread a post it...

Mirek


OK, will do when I have some time and can recall the accurate details of my problem with it to create a testcase.

BR, Tom
Re: Strange issue with text in Painter [message #50959 is a reply to message #50957] Tue, 15 January 2019 09:34 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Tue, 15 January 2019 10:23
void BufferPainter::FinishPathJob()
{
	if(jobcount == 0)
		return;

	CoWork co;
	co * [&] {
		for(;;) {
			int i = co.Next();
			if(i >= jobcount)
				break;
			INTERLOCKED {
			CoJob& b = cojob[i];
			b.rasterizer.Reset();
			PathJob j(b.rasterizer, b.width, b.path_info, b.attr, b.preclip, b.regular);
			if(!j.preclipped) {
				b.evenodd = j.evenodd;
				BufferPainter::RenderPathSegments(j.g, b.path_info->path[b.subpath], j.regular ? &b.attr : NULL, j.tolerance);
			}
			}
		}
	};


If problem disappears, try to move INTERLOCKED down line by line (until if) to see when/if it reappears.


This does not help.

BR, Tom
Re: Strange issue with text in Painter [message #50960 is a reply to message #50959] Tue, 15 January 2019 09:38 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
What about locking the whole lambda body?

Also to test in the same loop:

PathJob j(b.rasterizer, b.width, b.path_info, b.attr, b.preclip, false);

(change the last parameter to 'false')
Re: Strange issue with text in Painter [message #50961 is a reply to message #50956] Tue, 15 January 2019 09:42 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Tue, 15 January 2019 10:21
I am also trying to reproduce the issue here; anyway the paintings I have here only has a couple o texts in it.

Now I am not sure you have any level-of-detail systeme there, but if not, would it be possible to send me extremely zoomed out painting file so that it has more texts in it?

(That said, when testing, do you start with such zoomed-out situation?)


I do have a sort of level-of-detail system here, but I can squeeze quite a bunch of details on one UHD view still using smaller than readable fonts. You can then scale the painting to a readable level. Anyway, can you PM me your e-mail address, so that I can send you the painting. (It's still over 7MB when compressed with 7-zip at ultra level.)

BR, Tom
Re: Strange issue with text in Painter [message #50962 is a reply to message #50960] Tue, 15 January 2019 09:51 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Tue, 15 January 2019 10:38
What about locking the whole lambda body?

Also to test in the same loop:

PathJob j(b.rasterizer, b.width, b.path_info, b.attr, b.preclip, false);

(change the last parameter to 'false')


void BufferPainter::FinishPathJob()
{
	if(jobcount == 0)
		return;

	CoWork co;
	co * [&] {
		INTERLOCKED {
		for(;;) {
			int i = co.Next();
			if(i >= jobcount)
				break;
			CoJob& b = cojob[i];
			b.rasterizer.Reset();
			PathJob j(b.rasterizer, b.width, b.path_info, b.attr, b.preclip, b.regular);
			if(!j.preclipped) {
				b.evenodd = j.evenodd;
				BufferPainter::RenderPathSegments(j.g, b.path_info->path[b.subpath], j.regular ? &b.attr : NULL, j.tolerance);
			}
		}
		}
	};


This works OK. I will now test with 'false' instead of 'b.regular'.

BR, Tom
Re: Strange issue with text in Painter [message #50963 is a reply to message #50962] Tue, 15 January 2019 09:53 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
BTW, here is my testing code where I am trying to reproduce the issue:

#include <CtrlLib/CtrlLib.h>
#include <Painter/Painter.h>

using namespace Upp;

class PainterText : public TopWindow {
public:
	Painting p;
	FileSel fs;
	BufferPainter bpainter;
	double scale = 0.4;
	int    rotation = 0;
	Pointf translate = Pointf(0, 0);
	Pointf start;
	
	void Open(){
		if(fs.ExecuteOpen("Select a painting to view")) {
			p.Clear();
			p.Serialize(FileIn(fs.Get()));
		}
	}
	
	virtual void LeftDown(Point p, dword)
	{
		start = (Pointf)p * scale;
		SetCapture();
	}

	virtual void MouseMove(Point p, dword keyflags)
	{
		if(HasCapture()) {
			Pointf pos = (Pointf)p * scale;
			translate += (pos - start);
			start = pos;
			Refresh();
		}
	}

	virtual void MouseWheel(Point p, int zdelta, dword keyflags)
	{
		if(keyflags & K_CTRL)
			rotation += sgn(zdelta);
		else {
			if(zdelta < 0)
				scale *= 0.9;
			else
				scale /= 0.9;
		}
		Refresh();
	}


	virtual bool Key(dword key, int count){
		Refresh();
		switch(key){
			case K_CTRL_O:
				Open();
				return true;
		}
		return false;
	}
	
	typedef PainterText CLASSNAME;

	PainterText(){
		Sizeable();

		p.Serialize(FileIn("C:/xxx/PainteTest/T5.painting"));
	}
		
	virtual void Paint(Draw &draw){
		ImageBuffer ib(GetSize());
		{
			bpainter.Create(ib);
			bpainter.Co(true);
			bpainter.PreClipDashed();
			bpainter.Clear(White());
			bpainter.EvenOdd();
			
			bpainter.Scale(scale);
			bpainter.Rotate(rotation * .1);
			bpainter.Translate(translate);
			
			bpainter.Paint(p);

			bpainter.Finish();
		}
		
		SetSurface(draw,Rect(ib.GetSize()),ib,ib.GetSize(),Point(0,0));
	}
};

GUI_APP_MAIN
{
	PainterText().Run();
}


Perhaps you could try with the painting file you have produced - this is to ensure that I am doing the same thing...
Re: Strange issue with text in Painter [message #50964 is a reply to message #50960] Tue, 15 January 2019 09:53 Go to previous messageGo to next message
Tom1
Messages: 1319
Registered: March 2007
Ultimate Contributor
mirek wrote on Tue, 15 January 2019 10:38
What about locking the whole lambda body?

Also to test in the same loop:

PathJob j(b.rasterizer, b.width, b.path_info, b.attr, b.preclip, false);

(change the last parameter to 'false')


Changing the last parameter to 'false' does not work.

BR, Tom
Re: Strange issue with text in Painter [message #50965 is a reply to message #50964] Tue, 15 January 2019 10:06 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
CharEntry fc_cache[512];

GlyphInfo GetGlyphInfo(Font font, int chr)
{
	INTERLOCKED {
		font.RealizeStd();
		unsigned hash = GlyphHash(font, chr);
		CharEntry& e = fc_cache[hash & 511];
		if(e.font != font.AsInt64() || e.chr != chr)
			e = GetGlyphEntry(font, chr, hash);
		return e.info;
	}
}

(removal of thread__ for fc_cache)

[Updated on: Tue, 15 January 2019 10:06]

Report message to a moderator

Previous Topic: MT + Subpixel appear incompatible in Painter
Next Topic: Painter: Excessive memory usage in PainterExamples moving window to edges of screen.
Goto Forum:
  


Current Time: Fri May 01 02:02:43 GMT+2 2026

Total time taken to generate the page: 0.01616 seconds