Cannot draw temp graphics: "Collection was modified; enumeration operation may not execute"
DanS
✭✭
I've written an add-in that renders arrows (thousands of arrows) in an effort to find a way around this issue, but I can't seem to find any. When running the below code the application will crash hard with a non-recoverable exception (also below). It seems a little better in RS6.04, but will still occur. I'm currently running RS 6.07.01 and RS API 6.07.01 Any help would be much appreciated.
The code looks something like this:
The code looks something like this:
private static void SendArrowsToRS()
{
int xLimit = 1000;
int yLimit = 10;
float xStep = 0.005f;
float yStep = 0.005f;
float nextX = 0;
for (int x = 0; x < xLimit; x++)
{
float nextY = 0;
for (int y = 0; y < yLimit; y++)
{
var tail = new Vector3(nextX, nextY, 0f);
var tip = new Vector3(nextX, nextY, 0.1f);
nextY += yStep;
Thread.Sleep(20);
Station.ActiveStation.TemporaryGraphics.DrawArrow(tip, tail, 0.01, 3, Color.Black);
}
nextX += xStep;
}
}
The exception is below. None of my code shows up in the stacktrace, this seems to be an internal exception as a result of the above code rendering arrows.
The exception is below. None of my code shows up in the stacktrace, this seems to be an internal exception as a result of the above code rendering arrows.
System.InvalidOperationException
HResult=0x80131509
Message=Collection was modified; enumeration operation may not execute.
Source=mscorlib
StackTrace:
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at RobotStudio.Services.Graphics.GfxTempModel.Update(Boolean force)
at RobotStudio.Services.Graphics.GfxUpdater.UpdateGraphics(IEnumerable`1 gfxModels, Boolean forceRefresh, Boolean& needRedraw)
at RobotStudio.Services.Graphics.GfxService.UpdateGraphics(IEnumerable`1 models, Boolean force)
at RobotStudio.Services.Graphics.GfxUpdater.Application_Idle(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr 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 ABBInternal.StudioAppFramework.StudioAppFrameworkHost.Run()
at RobotStudio.Program.Main(String[] args)
0
Comments
-
I've learned that this problem is very intermittent. The higher the number of temp graphics will increase the likely hood of this occurring. I can also force the exception if I interact with the graphics view at any time (clicking or pan/zoom). Please help!0
-
This ended up being a threading issue...I was on a different thread.0
Categories
- All Categories
- 5.5K RobotStudio
- 395 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 310 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 785 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 4 Job listings