Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    struct properties are disposed while they still have a reference

    Bug Reporting (FUZE 4 Nintendo Switch)
    4
    10
    588
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • PB____
      PB____ last edited by PB____

      During my second ever stream on Twitch I tried creating a linked list using the ref keyword, and I discovered a new bug in FUZE 2.15.0:

      I created the elements in my linked list with this function:

      function createNode()
      return [
          .value = [],
          .hasValue = false,
          .next = [],
          .hasNext = false
      ]
      

      and also tried this variant:

      function createNode()
      return ([
          .value = [],
          .hasValue = false,
          .next = [],
          .hasNext = false
      ])
      

      Both would return the struct, but all the values would be undefined. So doing the following would throw an error:

      var linkedList = createNode()
      var ok = linkedList.hasValue
      var notOk = !linkedList.hasValue //throws error, because you cannot use ! operator on undefined value.
      

      I fixed this by refactoring the createNode value to the following implementation:

      function createNode()
          var result = [
              .value = [],
              .hasValue = false,
              .next = [],
              .hasNext = false
          ]
      return result
      

      by doing this, I could do !linkedList.hasValue as described in the earlier code.

      Unfortunately I suspect that this bug has been introduced in FUZE 2.15.0.

      1 Reply Last reply Reply Quote 1
      • pianofire
        pianofire Fuze Team last edited by

        Thanks @PB____ I will investigate tomorrow

        1 Reply Last reply Reply Quote 1
        • pianofire
          pianofire Fuze Team last edited by

          @PB____ I have tried this in 2.14 and I get the same effect so maybe this has always been a problem?

          1 Reply Last reply Reply Quote 1
          • PickleCatStars
            PickleCatStars F last edited by

            I literally don’t understand what’s going on in this thread. Is there something wrong with structs? Should I not use them?

            pianofire 1 Reply Last reply Reply Quote 0
            • pianofire
              pianofire Fuze Team @PickleCatStars last edited by

              @toxibunny No this is a specific problem with initializing a struct using a function. If you do it anonymously it doesn't seem to persist the values. As long as you assign it to a variable before returning it it works fine

              1 Reply Last reply Reply Quote 0
              • PB____
                PB____ last edited by

                Thank you @pianofire for testing this on 2.14, obviously I'm not able to do that myself. It's a relieve to know that this bug isn't new with the release!
                I've removed the 2.15 tag from the post :)

                1 Reply Last reply Reply Quote 1
                • spikey
                  spikey F last edited by spikey

                  This is an interesting way of making initializations more compact. Is this memory-save? I feel like it creates an integer and assignes a struct to it that takes more memory than an integer and has been defined in another scope.

                  1 Reply Last reply Reply Quote 0
                  • PB____
                    PB____ last edited by

                    @spikey I'm not sure what you mean by your question.

                    However in general in FUZE, I should probably have done something like this:

                    struct list_linkedNode
                    	var value
                    	int hasValue = false
                    	list_linkedNode next = [] // to prevent infinite node creation you need to either assign a value here, or use the var type in stead
                    	int hasNext = false
                    endstruct
                    
                    function list_createNode()
                    	list_linkedNode result
                    return result
                    

                    And then the function 'list_createNode' wouldn't even be necessary, unless the values for result are not always the same and not stored in a global variable.

                    spikey 1 Reply Last reply Reply Quote 0
                    • spikey
                      spikey F @PB____ last edited by spikey

                      @PB____ but does this work? I struggled with using the struct command, because I always ended up with 2 steps: defining the struct type and filling in values instead of just filling in the values, what automatically defined a struct.
                      To my question: do you use this already in projects? I think of doing it too. But I am cautious with changing my struct handling ;)

                      1 Reply Last reply Reply Quote 0
                      • PB____
                        PB____ last edited by

                        @spikey I've checked to be sure, but yes, I'm using this type of constructor pattern to create new structures based on values provided to the function.

                        For example in my template code I have a function called command_input to create a struct that keeps track of the buttons you've pressed.
                        However, I get a new version of that struct every frame, so I have not tested if structures created with this pattern survive if they exist for a long time. But if that's not the case, then that's a bug :)

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post