wxScintilla Problem: LexAccessor.h

BlitzMax Forums/Brucey's Modules/wxScintilla Problem: LexAccessor.h

MOBii(Posted 2016) [#1]
I download wx.mod 2 days ago (so the code is new)

I don't know how to debug this code: (can I DebugLog/send a message to BlitzMax from this code?)
// C:\BlitzMax\mod\wx.mod\wxscintilla.mod\src\scintilla\lexlib\LexAccessor.h

	void ColourTo(unsigned int pos, int chAttr) {
		// Only perform styling if non empty range
		if (pos != startSeg - 1) {
			assert(pos >= startSeg);
			if (pos < startSeg) {
				return;
			}

			if (validLen + (pos - startSeg + 1) >= bufferSize)
				Flush();
			if (validLen + (pos - startSeg + 1) >= bufferSize) {
				// Too big for buffer so send directly
				pAccess->SetStyleFor(pos - startSeg + 1, static_cast<char>(chAttr));
			} else {
				if (chAttr != chWhile)
					chFlags = 0;
				chAttr = static_cast<char>(chAttr | chFlags);
				for (unsigned int i = startSeg; i <= pos; i++) {
					assert((startPosStyling + validLen) < Length());
					styleBuf[validLen++] = static_cast<char>(chAttr);
				}
			}
		}
		startSeg = pos+1;
	}
I call:
SetLexer(15)
from my program
and get this:

After pressing Ignore about 100 times I get into the wxScintilla document and then it got the lexer ok,
exept the part me pressing the Ignore button 100 times!


MOBii(Posted 2016) [#2]
Just some try and Error:
	void ColourTo(unsigned int pos, int chAttr) {
		// Only perform styling if non empty range
		if (pos != startSeg - 1) {
//			assert(pos >= startSeg);
			if (pos < startSeg) {
				return;
			}

			if (validLen + (pos - startSeg + 1) >= bufferSize)
				Flush();
			if (validLen + (pos - startSeg + 1) >= bufferSize) {
				// Too big for buffer so send directly
				pAccess->SetStyleFor(pos - startSeg + 1, static_cast<char>(chAttr));
			} else {
				if (chAttr != chWhile)
					chFlags = 0;
				chAttr = static_cast<char>(chAttr | chFlags);
				for (unsigned int i = startSeg; i <= pos; i++) {
					assert((startPosStyling + validLen) < Length());
					styleBuf[validLen++] = static_cast<char>(chAttr);
				}
			}
		}
		startSeg = pos+1;
	}
If I Rem this out: assert(pos >= startSeg);
The MinGW Runtime Assertion stop Sending Assertion failed Messages to me!
I dunno what assert do or where it's declared (Ignorance is Bliss)
I can't see any wrong with the Lexer!


grable(Posted 2016) [#3]
Assert displays an error if the expression within it returns False.
Essentially doing doing the same thing as the If below it, the only difference is that Asserts are usually only enabled in debug mode.
Asserts are primarily used to trap things that should never happen, so that it fires that many times is a bad sign ;)

You can print stuff to the debuglog by printing to stdout or stderr.
printf( "hello %d\n", 1);

Try to check who calls ColourTo() since it gets called so many times with invalid positions.

Also, where you call SetLexer() might have something to do with it as well.


MOBii(Posted 2016) [#4]
Thank thee!
I try figure out what call SetLexer(_Lexer) from my .bmx
SetLexer(_Lexer) is called when the document is Created
When I change document I Set Lexer again but that was not necessary because it's already set when created!
So I turn off Set Lexer when I switch document so it NEVER pass the SetLexer(_Lexer) again, but I still get the popup Error message!


Thank the for learning me, that I can write back to BlizMax!
printf("LexAccessor.h :: %d, %d\n", pos, startSeg);
			assert(pos >= startSeg);
			if (pos < startSeg) return;
output from the printf:
LexAccessor.h :: 3060, 1689518080
LexAccessor.h :: 3070, 1689518080
LexAccessor.h :: 3073, 1689518080
LexAccessor.h :: 3079, 1689518080
LexAccessor.h :: 3096, 1689518080
LexAccessor.h :: 3119, 1689518080
LexAccessor.h :: 3123, 1689518080
LexAccessor.h :: 3126, 1689518080
LexAccessor.h :: 3130, 1689518080
LexAccessor.h :: 3133, 1689518080
LexAccessor.h :: 52, 23527424			// New document
LexAccessor.h :: 60, 23527424
LexAccessor.h :: 63, 23527424
LexAccessor.h :: 137, 23527424
LexAccessor.h :: 176, 23527424
LexAccessor.h :: 216, 23527424
When assert(false); he return;
pos suppose to be bigger than startSeg and somehow pos is millions below the startSeg!
I continue Rem this out for now:
// assert(pos >= startSeg);


I drop it!!!
This fix whatever I do wrong in the .bmx code:
if (pos < startSeg) return;
My thinking is when I switch the document,
the pos is still on the old document and startSeg is the new document, but it's only my guessing!