Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

memory violation exception when Calling FB method from another FB method

2018-10-11
2018-10-19
  • penngolliwog - 2018-10-11

    I have the Compile and Insert_Input methods of a function block, and they both take as input a VAR_IN_OUT of type UDT_DIs:

    Both methods work fine by themselves, but after adding a line to Insert_Input to call Compile, there is a program exception as shown.

    I've read through the documentation on methods.
    I've tried to use THIS^.xxxx
    I've tried to assign Data to a temporary local variable and passing this to the Compile method.
    What am I doing wrong?

    IMG: Compile method.PNG

    IMG: insert_input method

    IMG: errors.PNG

     
  • Anonymous - 2018-10-11

    Originally created by: rickj

    I think the problem is with your Data/IN_OUT parameter. Under the hood, IN_OUT parameters are essentially pointers so you must declare an instance of UDT_DIs somewhere and then pass that instance to your methods.

    If you define Data in the main body of your function block, it will be defined in and accessible from all methods.

     
  • penngolliwog - 2018-10-12

    Hi rickj,
    Thankyou for your reply. Yes you're right - one must take care with IN_OUT. Unfortunately this is not my particular problem:
    I have exported the FB and imported it into a blank project, and it works fine, even with apparently all external conditions the same. Maybe it's project corruption, but I have already done clean all/rebuild. Might need to rebuild the project from scratch using export/import.

     
  • penngolliwog - 2018-10-12

    So it turned out to be an issue with the UDT_DIs that was being passed to the Insert_Input method (even though the test program was doing the same thing.....). I worked around the problem by copying the UDT_DIs structure to a temporary UDT_DIs, passing this, then copying the temporary UDT_DIs back to the original (with Codesys.... sometimes you need to tell yourself it was a bad dream and move on....)

    Just to reiterate, you can do the method call I showed in the original post; I don't believe there is any fundamental issue with it.

     
  • aliazzz

    aliazzz - 2018-10-12

    Hi, just a small question off topic question out of sheer curiosity, what flavour of IDE are you using? (....e Automation Platform)

     
  • josepmariarams - 2018-10-12

    Have you try to change the name of compile?

    Sent from my Moto G (5S) Plus using Tapatalk

     
  • penngolliwog - 2018-10-15

    Hi Aliazzz, I'm using Codesys V3.5 SP13 Patch 1. "Machine automation platform" is the name of the project.

     
  • aliazzz

    aliazzz - 2018-10-15

    LOL (slaps his own head)

     
  • dFx

    dFx - 2018-10-19

    Did you tried to just clean and rebuild all ? Pointers can be corrupted with online/partial edit

     

Log in to post a comment.