Giter Club home page Giter Club logo

Comments (7)

Dolu1990 avatar Dolu1990 commented on June 2, 2024 1

Ahh fixed, you were triggering another clone case escaping the init :D

from spinalhdl.

andreasWallner avatar andreasWallner commented on June 2, 2024 1

Btw. as a small note: in usual case we'd recommend to use case class instead of class for Bundles and Components which will auto-generate a correct clone routine.

Just as a note for those that stumble over this question here ;-)

from spinalhdl.

Dolu1990 avatar Dolu1990 commented on June 2, 2024

Hi,
That's a bug i just fixed now.
You normaly need to implement clone only for Bundle which aren't case class and have parameters (either explicit or from the scala execution stack)

from spinalhdl.

KireinaHoro avatar KireinaHoro commented on June 2, 2024

The commit doesn't fix the NPE given by the example, when clone is not overriden... For Union we call newElement in the constructor (not in postInitCallback)

from spinalhdl.

Dolu1990 avatar Dolu1990 commented on June 2, 2024

I tested with :

 class Toplevel extends Component{

    case class TestUnion() extends Union {
      val a = newElement(UInt(4 bits))
      val b = newElement(Bits(4 bits))
    }

    val a = TestUnion()
    val b = a.clone.asInstanceOf[TestUnion]

    b.a := U(15) 
  }

Which went well on my side, can you provide a fully self contained case for me to reproduce ?

from spinalhdl.

KireinaHoro avatar KireinaHoro commented on June 2, 2024

So the example I have is:

import spinal.core._

case class TestUnion() extends Union {
  val a = newElement(UInt(4 bits))
  val b = newElement(Bits(4 bits))
}

object TestStreamUnion extends App {
  SpinalVerilog(new Component {
    val a = TestUnion()
    val b = a.clone.asInstanceOf[TestUnion]
    b.a := U(3)
  })
}

Exception:

[Runtime] SpinalHDL dev    git head : 5e40a78aa6a4b5cf8be503eed1f5b084101bbaab
[Runtime] JVM max memory : 16012.0MiB
[Runtime] Current date : 2024.03.04 13:44:47
[Progress] at 0.000 : Elaborate components

ERROR !
A null pointer access has been detected in the JVM.
This could happen when in your SpinalHDL description, you access an signal which is only defined further.
For instance :
  val result = Bool()
  result := a ^ b  //a and b can't be accessed there because they are only defined one line below (Software rule of execution order)
  val a,b = Bool()

Exception in thread "main" java.lang.NullPointerException
        at spinal.core.UnionElement.$anonfun$get$1(Union.scala:12)
        at scala.collection.mutable.HashMap.getOrElseUpdate(HashMap.scala:469)
        at spinal.core.signalCache$.apply(Misc.scala:169)
        at spinal.core.signalCache$.apply(Misc.scala:172)
        at spinal.core.UnionElement.get(Union.scala:12)
        at spinal.core.UnionElement$.wrapped(Union.scala:8)
        at pionic.TestStreamUnion$$anon$1.<init>(TestStreamUnion.scala:14)
        at pionic.TestStreamUnion$.$anonfun$new$1(TestStreamUnion.scala:11)
        at spinal.core.internals.PhaseCreateComponent.$anonfun$impl$273(Phase.scala:2556)
        at spinal.core.fiber.Engine$.$anonfun$create$1(AsyncCtrl.scala:147)
        at spinal.core.fiber.AsyncThread.$anonfun$jvmThread$1(AsyncThread.scala:59)
        at spinal.core.fiber.EngineContext.$anonfun$newJvmThread$1(AsyncCtrl.scala:39)
        at spinal.sim.JvmThread.run(SimManager.scala:51)

from spinalhdl.

KireinaHoro avatar KireinaHoro commented on June 2, 2024

I have no idea what that commit ID is; my local branch definitely includes bb24b25 .

from spinalhdl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.