DeepNestPort icon indicating copy to clipboard operation
DeepNestPort copied to clipboard

trouble .cache allready has such key

Open artemishenkov opened this issue 1 year ago • 2 comments

Hello, I was playing with your DeepnestPort and catch this weird exception. It happens in Background.cs when I run 2 different instances of NestingContext in 2 different thread(files are different). I would appreciate any clarification.

image

Thank you

artemishenkov avatar Oct 10 '24 16:10 artemishenkov

Hi, it seems you're trying to use this code in your own specific way.
Can you explain what you want to get? Please provide your code (whole project would be preferable) in order I can debug it and give you a hint

fel88 avatar Oct 27 '24 21:10 fel88

I have the same issue. When I change the flowing code to Parallel: //// try all possible rotations until it fits //// (only do this for the first part of each sheet, to ensure that all parts that can be placed are, even if we have to to open a lot of sheets) //for (j = 0; j <= maxAttempts; j++) //{ // sheetNfp = getInnerNfp(sheet, part, 0, config);

                //    if (sheetNfp != null && sheetNfp.Length> 0)
                //    {
                //        if (sheetNfp[0].length == 0)
                //        {
                //            throw new ArgumentException();
                //        }
                //        else
                //        {
                //            break;
                //        }
                //    }

                //    var r = rotatePolygon(part, angleIncrement);
                //    r.rotation = part.rotation + angleIncrement;
                //    r.source = part.source;
                //    r.id = part.id;
                //    r.Name = part.Name;

                //    // rotation is not in-place
                //    part = r;
                //    parts[i] = r;

                //    if (part.rotation > 360f)
                //    {
                //        part.rotation = part.rotation % 360f;
                //    }
                //}

My changed code is: ` Tuple<int, NFP[]> bestNfp = null; Parallel.For(0, maxAttempts, (index, state) => {// 检查是否已请求停止 if (state.IsStopped) { return; } NFP[] sheetNfpBest = getInnerNfp(sheet, part, 0, config); // 检查是否已请求停止 if (state.IsStopped) { return; } if (sheetNfp != null && sheetNfp.Length > 0) { bestNfp = new Tuple<int, NFP[]>(index, sheetNfpBest); state.Stop(); return; } }); if(bestNfp != null) { var r = rotatePolygon(part, angleIncrement); r.rotation = part.rotation + angleIncrement; r.source = part.source; r.id = part.id; r.Name = part.Name;

                    // rotation is not in-place
                    part = r;
                    parts[i] = r;

                    if (part.rotation > 360f)
                    {
                        part.rotation = part.rotation % 360f;
                    }
                    sheetNfp = bestNfp.Item2;
                }`

gchling avatar Mar 05 '25 10:03 gchling