Strange crash with SpanIndicator when HasFontChange=true

SyntaxEditor for Windows Forms Forum

Posted 12 years ago by Jason Sobell
Version: 4.0.0257
Platform: .NET 2.0
Environment: Windows Vista (32-bit)
Avatar
I'm getting an internal index error from the SyntaxEditor when I delete text with more than one a custom SpanIndicator in it.
I've included sample code to reproduce it, so just run the following then try deleting all of the text.
Setting HasFontChanged to return false prevents the crash, but removing the override on ApplyHighlightingStyleFont doesn't, suggesting that it's internal to the editor.
I also tried replacing my custom SpanIndicator with the CustomSpanIndicator one from your demo, but get the same crash.

Also, as a side note, I notice that OverlapsWith does not work unless the selection is normalised, so I'm not sure if this is intentional, but if so then it's probably best to state so in the doco.

Cheers,
Jason

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ActiproSoftware.SyntaxEditor;

namespace WindowsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            editor.Document.Text = "012345678901234567890123456789012345678901234567890123456789";
            editor.Document.SpanIndicatorLayers.Add(new ActiproSoftware.SyntaxEditor.SpanIndicatorLayer("A", 1));

            editor.Document.SpanIndicatorLayers["A"].Add(new QMLSpanIndicator2("B"), new TextRange(10, 20));
            editor.Document.SpanIndicatorLayers["A"].Add(new QMLSpanIndicator2("B"), new TextRange(30, 40));
        }
    }

    public class QMLSpanIndicator2 : SpanIndicator
    {
        public QMLSpanIndicator2(string name)
            : base(name)
        {
        }

        protected override void ApplyHighlightingStyleAdornments(HighlightingStyleResolver resolver)
        {
            if (Name == "S")
            {
                HighlightingStyle hs = new HighlightingStyle("S", "S", Color.Red, Color.Transparent, ActiproSoftware.ComponentModel.DefaultableBoolean.Default, ActiproSoftware.ComponentModel.DefaultableBoolean.Default, HighlightingStyleLineStyle.None);
                hs.StrikeOutStyle = HighlightingStyleLineStyle.Solid;
                resolver.ApplyHighlightingStyleAdornments(hs);
            }
            else if (Name == "U")
                resolver.ApplyHighlightingStyleAdornments(
                    new HighlightingStyle("U", "U", Color.Green, Color.Transparent, ActiproSoftware.ComponentModel.DefaultableBoolean.Default, ActiproSoftware.ComponentModel.DefaultableBoolean.Default, HighlightingStyleLineStyle.Solid)
                );

            base.ApplyHighlightingStyleAdornments(resolver);
        }

        protected override void ApplyHighlightingStyleColors(HighlightingStyleResolver resolver)
        {
            if (Name == "H") resolver.SetBackColor(Color.Yellow);
            base.ApplyHighlightingStyleColors(resolver);
        }

        protected override void ApplyHighlightingStyleFont(HighlightingStyleResolver resolver)
        {
            if (Name == "B") 
                resolver.SetBold(true);
            else if (Name == "I") 
                resolver.SetItalic(true);
            base.ApplyHighlightingStyleFont(resolver);
        }

        public override bool HasFontChange
        {
            get { return true; }
        }

    }
}
Crash stack trace is:

System.ArgumentOutOfRangeException was unhandled
  Message="Specified argument was out of the range of valid values.\r\nParameter name: index"
  Source="ActiproSoftware.SyntaxEditor.Net20"
  ParamName="index"
  StackTrace:
       at ActiproSoftware.SyntaxEditor.DocumentLineCollection.get_Item(Int32 index)
       at bl.a(Document A_0, Int32 A_1, TextRange A_2)
       at bl.a(TextRange A_0)
       at ActiproSoftware.SyntaxEditor.SyntaxEditor.b(Object A_0, IndicatorEventArgs A_1)
       at ActiproSoftware.SyntaxEditor.Document.OnIndicatorRemoved(IndicatorEventArgs e)
       at ActiproSoftware.SyntaxEditor.SpanIndicatorLayer.NotifyDocumentTextChanged(DocumentModificationEventArgs e)
       at ActiproSoftware.SyntaxEditor.Document.a(DocumentModification A_0, Boolean A_1)
       at ActiproSoftware.SyntaxEditor.Document.b(DocumentModificationType A_0, Int32 A_1, Int32 A_2, String A_3, DocumentModificationOptions A_4, WeakReference A_5)
       at ActiproSoftware.SyntaxEditor.Document.a(DocumentModificationType A_0, Int32 A_1, Int32 A_2, String A_3, DocumentModificationOptions A_4, WeakReference A_5)
       at ActiproSoftware.SyntaxEditor.EditorView.a(DocumentModificationType A_0, String A_1, DocumentModificationOptions A_2)
       at ActiproSoftware.SyntaxEditor.EditorView.DeleteSelectedText(DocumentModificationType type, DocumentModificationOptions options)
       at ActiproSoftware.SyntaxEditor.Commands.DeleteCommand.Execute(EditCommandContext context)
       at ActiproSoftware.SyntaxEditor.MacroRecording.a(EditCommand A_0, EditCommandContext A_1)
       at ActiproSoftware.SyntaxEditor.EditorView.a(EditCommand A_0, Boolean A_1)
       at ActiproSoftware.SyntaxEditor.SyntaxEditor.a(EditorView A_0, Keys A_1, Char A_2, Boolean A_3)
       at ActiproSoftware.SyntaxEditor.SyntaxEditor.OnKeyDown(KeyEventArgs e)
       at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
       at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
       at System.Windows.Forms.Control.WmKeyChar(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at ActiproSoftware.SyntaxEditor.SyntaxEditor.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at WindowsApplication1.Program.Main() in D:\Dev\New QuestML Editor\WindowsApplication1\Program.cs:line 17
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

Comments (7)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Jason,

Can you just email over a ZIPped simple project that has this code in it so we can run it? Thanks!


Actipro Software Support

Posted 12 years ago by Jason Sobell
Avatar
Hi guys,

Well, the entire code is in the message above, or run your own sample project (it's installed with the product), add two CustomIndicators in the "QuickStart: Indicators" demo, then delete the text. Voila, crash.

Cheers,
Jason
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Sorry I'm trying it in the latest build 257 but cannot get it to occur. Are you sure you have the latest maintenance release? If so, please email us a ZIP that has a project that shows it occurring. Thanks!


Actipro Software Support

Posted 12 years ago by Jason Sobell
Avatar
OK, emailed.
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks for the sample, this is now fixed for the next maintenance release.


Actipro Software Support

Posted 12 years ago by Jason Sobell
Avatar
Excellent!
When is this due for release? This bug is a show-stopper for us, so either a quick release or an emailed interim version would be greatly appreciated.

Cheers,
Jason
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
In the next week or two however if you need a preview build then you can email us and we can put one together for you.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 9 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.