# A caught exception occured on thread

**URL:** <https://discourse.processing.org/t/a-caught-exception-occured-on-thread/31713>\
**Category:** Beginners\
**Created:** [August 13, 2021, 1:35pm UTC](https://discourse.processing.org/t/a-caught-exception-occured-on-thread/31713 "2021-08-13T13:35:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LuckSmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lucksmith/32/5805_2.png) [@LuckSmith](https://discourse.processing.org/u/LuckSmith)\
**Post date:** [August 13, 2021, 1:35pm UTC](https://discourse.processing.org/t/a-caught-exception-occured-on-thread/31713/1 "2021-08-13T13:35:54Z")

</div>

Hi guys,  
I got the following error message running my sketch. Tried both 4.01 and 3.5.4 versions.  
What is wrong?

```auto
RunnableTask.run(): A caught exception occured on thread main-Display-.windows_nil-1-EDT-1: RunnableTask[enqueued true[executed false, flushed false], tTotal 0 ms, tExec 0 ms, tQueue 0 ms, attachment null, throwable java.lang.RuntimeException: Waited 5000ms for: <77af58bf, 377e5081>[count 2, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-Display-.windows_nil-1-EDT-1>]
java.lang.RuntimeException: Waited 5000ms for: <77af58bf, 377e5081>[count 2, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-Display-.windows_nil-1-EDT-1>
	at jogamp.common.util.locks.RecursiveLockImpl01Unfairish.lock(RecursiveLockImpl01Unfairish.java:198)
	at jogamp.newt.WindowImpl$ResizableAction.run(WindowImpl.java:2118)
	at jogamp.newt.DisplayImpl.runOnEDTIfAvail(DisplayImpl.java:450)
	at jogamp.newt.WindowImpl.runOnEDTIfAvail(WindowImpl.java:2782)
	at jogamp.newt.WindowImpl.setResizable(WindowImpl.java:2154)
	at com.jogamp.newt.opengl.GLWindow.setResizable(GLWindow.java:370)
	at processing.opengl.PSurfaceJOGL$5.run(PSurfaceJOGL.java:452)
	at com.jogamp.common.util.RunnableTask.run(RunnableTask.java:127)
	at jogamp.newt.DefaultEDTUtil$NEDT.run(DefaultEDTUtil.java:375)
DefaultEDT.run(): Caught exception occured on thread main-Display-.windows_nil-1-EDT-1: RunnableTask[enqueued false[executed true, flushed false], tTotal 5002 ms, tExec 5002 ms, tQueue 0 ms, attachment null, throwable java.lang.RuntimeException: Waited 5000ms for: <77af58bf, 377e5081>[count 2, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-Display-.windows_nil-1-EDT-1>]
java.lang.RuntimeException: Waited 5000ms for: <77af58bf, 377e5081>[count 2, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-Display-.windows_nil-1-EDT-1>
	at jogamp.common.util.locks.RecursiveLockImpl01Unfairish.lock(RecursiveLockImpl01Unfairish.java:198)
	at jogamp.newt.WindowImpl$ResizableAction.run(WindowImpl.java:2118)
	at jogamp.newt.DisplayImpl.runOnEDTIfAvail(DisplayImpl.java:450)
	at jogamp.newt.WindowImpl.runOnEDTIfAvail(WindowImpl.java:2782)
	at jogamp.newt.WindowImpl.setResizable(WindowImpl.java:2154)
	at com.jogamp.newt.opengl.GLWindow.setResizable(GLWindow.java:370)
	at processing.opengl.PSurfaceJOGL$5.run(PSurfaceJOGL.java:452)
	at com.jogamp.common.util.RunnableTask.run(RunnableTask.java:127)
	at jogamp.newt.DefaultEDTUtil$NEDT.run(DefaultEDTUtil.java:375)

```

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 13, 2021, 7:25pm UTC](https://discourse.processing.org/t/a-caught-exception-occured-on-thread/31713/2 "2021-08-13T19:25:21Z")

</div>

hi

post your code …

---

<div class="post-metadata">

**Author:** ![LuckSmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lucksmith/32/5805_2.png) [@LuckSmith](https://discourse.processing.org/u/LuckSmith)\
**Post date:** [August 14, 2021, 9:03pm UTC](https://discourse.processing.org/t/a-caught-exception-occured-on-thread/31713/3 "2021-08-14T21:03:58Z")

</div>

hi,  
the code is too big to post it here, but I think it gets stuck somewhere over here

```auto
  void calculateFlow() {
    for (int i=0; i<basin.size(); i++) {
      Triangle t = basin.get(i);
      while (t.flowto!=null) {
        t.water++;
        t = t.flowto;
      }
    }
  }

```

I’m not sure this would be any helpful either.  
but, is it even legal to reassign variables like that within a loop?

and to get an idea of what is going on there, please read [Blobs in Games: Mapgen4: river representation](https://simblob.blogspot.com/2018/10/mapgen4-river-representation.html) (if you haven’t already), I’m kinda trying to do something similar.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 15, 2021, 7:41am UTC](https://discourse.processing.org/t/a-caught-exception-occured-on-thread/31713/5 "2021-08-15T07:41:44Z")

</div>

> **[Reference](https://processing.org/reference/ArrayList.html)**
>
> An ArrayList stores a variable number of objects. This is similar to making an array of objects, but with an ArrayList, items can be easily added and removed from the ArrayList and it is…

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [August 15, 2021, 11:49am UTC](https://discourse.processing.org/t/a-caught-exception-occured-on-thread/31713/6 "2021-08-15T11:49:40Z")

</div>

As jafal says (and as stated in the guideline) please post the code that reproduces the issue 🙂

But I think I have seen this issue before, and it’s hard to spot exactly which part of the code causes this error. In my case, this happens when the draw call is blocked for a certain amount of time, and I don’t know how to fix (there may be a way to tell Processing to wait a bit longer). Isn’t the setup too long to load - are you loading a huge file, or running calculation that takes too long to process? What happens if you reduce the complexity of the simulation model - would that make the code run?
