question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

desktop: hangs on a difference of a union of a union…?

See original GitHub issue

I have a design where I struck an issue with just adding to a negative volume by using union. The boolean ops are nested quite a lot, but I haven’t struck issues with that previously.

I’m using the desktop app from master. Sorry to post so much detail, but I think the code will make easier sense with some background. This is what I have design:

image

There are small slits where “legs” of a speaker grill is supposed to go in and are to be bent inwards. Therefore I need to remove some pieces of the ring there. The nature of the whole thing is therefore a somewhat deeply nested structure of unions and differences.

First the whole plate, then some cutouts, but then I need to re-add material (the circle) after the cutouts and then also subtract again after that add…

So it’s like

difference(
   union(
      difference(
          union(positives…)
          negatives
       )
       postPositives…
    )
    postNegatives…
)

Actual code:

const panelThickness = 2.3

const { widthOfHp, eurorackPanel, PJ301, AlphaPot, ThreeMmLed, PowerSwitch } = require('../eurorack-lib/eurorack-lib')({
  panelThickness,
})

const jscad = require('jscad-tree-experiment')
const { difference, union } = jscad.api.booleanOps
const { translate, rotate, mirror } = jscad.api.transformations
const { cube, cylinder } = jscad.api.primitives3d
const { color } = jscad.api.color

const panelHp = 14
const width = widthOfHp(panelHp)

const middle = width / 2

// No margin
const grillY = 61 + 2
const grillX = 56 + 2

const speakerOuterDiam = 57
const speakerHoleDiam = 50

const grillMounts = () => {
  const grillXMount = 56
  const grillYMount = 41
  const grillMountLength = 7 // with margin

  let slit = union(
    cube({ size: [1, grillMountLength, 20], center: true }),
    translate([9, 9, 9], cube({ size: [1, grillMountLength, 20], center: true }))
  )

  slit = cube({ size: [1, grillMountLength, 20], center: true }) // COMMENT OUT FOR ISSUE

  return union(
    translate([-grillXMount / 2, -grillYMount / 2, 0], slit),
    translate([+grillXMount / 2, -grillYMount / 2, 0], slit),
    translate([-grillXMount / 2, +grillYMount / 2, 0], slit),
    translate([+grillXMount / 2, +grillYMount / 2, 0], slit)
  )
}

const speakerMountCircle = () => {
  return difference(
    cylinder({ d: speakerOuterDiam + 5, h: 5, $fn: 40 }),
    cylinder({ d: speakerOuterDiam, h: 5, $fn: 40 })
  )
}

const speakerHole = () => {
  return translate([0, 0, -0.01], cylinder({ d: speakerHoleDiam, h: 20, $fn: 40 }))
}

const speakerY = 45

function negatives() {
  return union(
    translate([middle, speakerY, 0], speakerHole()),
    translate(
      [middle, speakerY, 0],
      translate([0, 0, panelThickness], cube({ size: [grillX, grillY, 1], center: true }))
    ),
    translate([middle, speakerY, 0], translate([0, 0, -0.1], cube({ size: [grillX, grillY, 1], center: true }))),
    translate([middle, 90, 0], AlphaPot()),
    translate([middle - 20, 110, 0], PJ301()),
    translate([middle + 10, 110, 0], ThreeMmLed()),
    translate([middle + 20, 110, 0], PowerSwitch())
  )
}

function main() {
  return difference(
    union(
      difference(union(eurorackPanel(panelHp, { mountHoles: 4, slots: false })), negatives()),
      translate([middle, speakerY, 0], speakerMountCircle())
    ),
    translate([middle, speakerY, 0], grillMounts())
  )
}

module.exports = { main, getParameterDefinitions: () => [] }

Expected Behavior

If I use the definition of slit be a union - I get lots of fan spin and no render. If I use the simple slit everything’s fine.

Actual Behavior

desktop app loops for quite some time and then I get this gc log - I guess addPolygonTreeNodes might be the only interesting info:

> @jscad/desktop@0.7.1 dev /Users/viktor/dev/projects/OpenJSCAD.org/packages/desktop
> node node_modules/.bin/electron .


<--- Last few GCs --->

[17229:0x7fc098877800]    58356 ms: Mark-sweep 2051.2 (2117.5) -> 2051.2 (2093.0) MB, 2379.8 / 0.1 ms  (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 2380 ms) last resort
[17229:0x7fc098877800]    60641 ms: Mark-sweep 2051.2 (2093.0) -> 2051.2 (2093.0) MB, 2284.2 / 0.2 ms  last resort


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x1f823fb14c9 <DedicatedWorkerGlobalScope map = 0x33c5c60d411>
    1: new Node [/Users/viktor/dev/projects/OpenJSCAD.org/packages/desktop/node_modules/@jscad/csg/src/core/trees.js:~381] [pc=0x258070c0c84c](this=0x12be0364879 <Node map = 0x33c5c6100c1>,parent=0x12be03647a1 <Node map = 0x33c5c609479>)
    3: addPolygonTreeNodes [/Users/viktor/dev/projects/OpenJSCAD.org/packages/desktop/node_modules/@jscad/csg/src/core/tree...

Specifications

  • Version: 231d3c6393e6d84569d8c00cf32dfe83b85d3163 (master)
  • Platform: OSX
  • Environment: electron desktop app

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
z3devcommented, Aug 29, 2019

@hedefalk Thanks.

I don’t thing this design is complex, and would expect the application to render, etc. without issues. I’ll try it out later next week.

I make fairly complex designs some times, with lots of small pieces and holes. Here’s one that I created a few years back…

http://www.z3d.jp/lab/view.php?design=lab-000000050

Not sure that it will help, but sharing designs is always a learning experience. 😃

0reactions
hedefalkcommented, Sep 4, 2019

@kaosat-dev Thx! I was gonna try you suggestion now after working with something else for a bit, but for some reason it seems to be working fine now… Can’t even reproduce it seems. I guess I might have translated it a bit and at this point I’m really happy it works so I can print this thing now so I might dodge from putting too much effort in a repo case. I have also gone between master and V2 a few times and cleared caches and stuff…

Your tip might be useful if I struck something similar again though and I’ll let you know if so.

I’ll close for now, thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spark Hangs When Using Union With Persisted Hadoop RDD
Spark hangs when materializing a persisted RDD that was built from a Hadoop sequence file and then union-ed with a similar RDD.
Read more >
Difference between Structure and Union in C - GeeksforGeeks
Union in C is a special data type available in C that allows storing different data types in the same memory location.
Read more >
Distrust of unions, and GM, hangs over South Korean efforts to ...
Distrust of unions, and GM, hangs over South Korean efforts to stem job losses | Reuters.
Read more >
Deep Freeze Enterprise - Faronics
Deep Freeze Enterprise is a comprehensive system restore software that protects multiple hard drives and partitions, prevents configuration drifts and helps ...
Read more >
Windows-based computer freeze troubleshooting
Learn how to troubleshoot computer freeze issues on Windows-based ... Try to access the computer through a remote desktop connection.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found