gurkenlabs / litiengine

LITIENGINE 🕹 The pure 2D java game engine.
https://litiengine.com/
MIT License
731 stars 94 forks source link

Adding and removing blueprints can cause exceptions when trying to add one again. #416

Closed nightm4re94 closed 1 year ago

nightm4re94 commented 3 years ago

Describe the bug I've saved an emitter as a blueprint, then deleted it again. Then I couldn't add another one due to the following error.

Stack Trace

Sat Aug 21 16:27:02 CEST 2021 AWT-EventQueue-0 threw an exception:
java.lang.NullPointerException
    at de.gurkenlabs.utiliti.components.MapComponent.defineBlueprint(MapComponent.java:564)
    at de.gurkenlabs.utiliti.swing.menus.CanvasPopupMenu.lambda$new$4(CanvasPopupMenu.java:38)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
    at com.github.weisj.darklaf.ui.menu.DarkMenuItemUIBase.doClick(DarkMenuItemUIBase.java:155)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:886)
    at java.awt.Component.processMouseEvent(Component.java:6539)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6304)
    at java.awt.Container.processEvent(Container.java:2239)
    at java.awt.Component.dispatchEventImpl(Component.java:4889)
    at java.awt.Container.dispatchEventImpl(Container.java:2297)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
    at java.awt.Container.dispatchEventImpl(Container.java:2283)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
    at java.awt.EventQueue$4.run(EventQueue.java:733)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

This is what the emitter MapObject looks like in xml:

<object id="10" name="clickFeedback" type="EMITTER" x="112" y="31" width="16" height="16">
     <properties>
      <property name="collisionType" value="NONE"/>
      <property name="emitterAlphaVariance" type="float" value="0.0"/>
      <property name="emitterColorVariance" type="float" value="0.0"/>
      <property name="emitterColors" value="#f33442"/>
      <property name="emitterDuration" value="800"/>
      <property name="emitterMaxParticles" value="1"/>
      <property name="emitterOriginAlign" value="CENTER"/>
      <property name="emitterOriginValign" value="MIDDLE"/>
      <property name="emitterParticleType" value="ELLIPSE"/>
      <property name="emitterSpawnAmount" value="1"/>
      <property name="emitterSpawnRate" type="int" value="100"/>
      <property name="emitterUpdateDelay" type="int" value="40"/>
      <property name="particleAnimateSprite" type="bool" value="true"/>
      <property name="particleAntiAliasing" type="bool" value="true"/>
      <property name="particleFade" type="bool" value="true"/>
      <property name="particleFadeOnCollision" type="bool" value="false"/>
      <property name="particleLoopSprite" type="bool" value="true"/>
      <property name="particleMaxAccelerationX" value="0.0"/>
      <property name="particleMaxAccelerationY" value="0.0"/>
      <property name="particleMaxAngle" value="0.0"/>
      <property name="particleMaxDeltaAngle" value="0.0"/>
      <property name="particleMaxDeltaHeight" value="0.5"/>
      <property name="particleMaxDeltaWidth" value="0.5"/>
      <property name="particleMaxOffsetX" value="0.0"/>
      <property name="particleMaxOffsetY" value="0.0"/>
      <property name="particleMaxStartHeight" value="2.0"/>
      <property name="particleMaxStartWidth" value="2.0"/>
      <property name="particleMaxTTL" value="800.0"/>
      <property name="particleMaxVelocityX" value="0.0"/>
      <property name="particleMaxVelocityY" value="0.0"/>
      <property name="particleMinAccelerationX" value="0.0"/>
      <property name="particleMinAccelerationY" value="-0.0"/>
      <property name="particleMinAngle" type="float" value="0.0"/>
      <property name="particleMinDeltaAngle" value="0.0"/>
      <property name="particleMinDeltaHeight" value="0.5"/>
      <property name="particleMinDeltaWidth" value="0.5"/>
      <property name="particleMinOffsetX" value="0.0"/>
      <property name="particleMinOffsetY" value="0.0"/>
      <property name="particleMinStartHeight" type="float" value="2.0"/>
      <property name="particleMinStartWidth" type="float" value="2.0"/>
      <property name="particleMinTTL" value="800.0"/>
      <property name="particleMinVelocityX" value="0.0"/>
      <property name="particleMinVelocityY" value="0.0"/>
      <property name="particleOutlineOnly" type="bool" value="true"/>
      <property name="particleTexts" value="LITI"/>
      <property name="requiredQuality" value="VERYLOW"/>
     </properties>
</object>

To Reproduce Steps to reproduce the behavior:

  1. Add emitter in utiLITI
  2. Define blueprint
  3. Delete Blueprint and emitter resource
  4. See error

Expected behavior Removing blueprints shouldn't prevent you from adding new ones later on.

Screenshots If applicable, add screenshots to help explain your problem.

Your System: Operating System: Windows 10 Architecture: amd64 Version: 10.0 Memory: Max heap size: 455.5 MiB Current heap size: 455.5 MiB Heap used: 122.9 MiB Free heap: 332.6 MiB Java Version: OpenJDK Runtime Environment 1.8.0_242-b08 Vendor: Uptime: PT27.052S Screens: 2 Screen 0: 1920x1080@60hz Screen 1: 1920x1080@60hz

nightm4re94 commented 3 years ago

This might have something to do with the duration not being set to 0. Once I reset the duration, I can save, delete, and re-add the emitter.

steffen-wilke commented 1 year ago

Unable to reproduce. I think this has been fixed with 9038afdc5dd672dfddc620e03835e9499d7aab08