RUN-TIME crash in reteutil (GetLeftMemory)

  • lna

    lna - 2010-11-02


    I'm currently trying to create a runtime application using clips 6.3 under Windows 7. I've succeeded in compiling the projet with visual xpress 2008, creating the construct-to-c files, creating and compiling my runtime project.
    First, when I launch my program with the clips console (not in runtime), everything works perfectly. Second, when I launch my program in runtime with the clips 6.24 version, everything works fine as well.
    However, when I launch the exectuable in runtime, my program fails in the second rule. It seems to exit in reteutil.c, in the globle struct partialMatch *GetLeftBetaMemory, betaLocation = hashValue % theJoin->leftMemory->size;
    I have already updated the globle void AddBetaMemoriesToJoin in  my ruledef.c file as per another message in this forum but that hasn't changed anything.
    With my settings, I have been able to create, compile and launch a very simple project with a couple of rules in two different modules. However, when I try to launch my project (actually quite huge), it quits in the second rule.
    To give you an idea, I have a MAIN module in a main.clp file from which I did an EXPORT ?ALL. I then have a TREATMENT module, in a main_rent.clp file in which I import MAIN ?ALL. This module contains the first rule to be executed, which on the lhs contains a good number of (not (my_fact ?)). I then have a lecture.clp file in which is contained the second rule to be executed, in which I assert some of those facts (i.e. (assert (my_fact ?value)). The program always exits on the same (assert (my_fact ?value)).
    Now, this "my_fact" is used in many other rules in my project both in rhs and lhs.
    I really don't know where to look in order to solve that problem and any help would be greatly appreciated. I'm also aware that I may not be very clear in my explanations so if any extra information is needed, please let me know.

    Thanks for any help ;)

  • Gary Riley

    Gary Riley - 2010-11-03

    If you can get the program to a small enough size that you can post it, I can try to reproduce the problem you're seeing.

  • lna

    lna - 2010-11-04

    Hi Gary,

    First of all, let me thank you for the high saliency in the answer to my question ;)

    I have prepared a very light version of the code. The error does not occur in the assertion of the fact which I had mentionned. However, it happens in a make-instance instruction (same error in GetLeftBetaMemory).

    Since the code is very much simplified compared to the complete version, you will see that the "detecte_vv_s" rule has a very bizarre lhs (with an (or(and)). It is during the match of this very same rule that the error occurs. It seems as though  the (or (and)) instruction is not appreciated in the lhs. However, it is important to note that it works fine when run in the console.

    Following is the content of the two .clp files I have used. Please let me know if I should equally send you the modifications in the clips code (such as my setup.h or added files).

    X_main.clp :

    (defmodule DATA_GLOB (export ?ALL))

    (defmodule MAIN (export ?ALL)
                    (import DATA_GLOB ?ALL))

    (defclass FAMILLE_SUR (is-a USER)
    (role concrete)
    (pattern-match reactive) )

    (defclass FAMILLE_IF (is-a USER)
    (role concrete)
    (pattern-match reactive)
    (multislot ifs (visibility public)(create-accessor read-write))
    (slot ddeter (type INTEGER)(create-accessor read-write)) ; date déterminante pour les calculs
    (multislot remarques (visibility public)(create-accessor read-write)) )

    (defclass BASES_CALCUL (is-a USER)
    (role concrete)
    (pattern-match reactive))

    (defclass PRESTATION (is-a USER)
    (role abstract)
    (slot autocalcule (type SYMBOL)(allowed-symbols TRUE FALSE)(default TRUE)(visibility public)(create-accessor read-write)) ;si TRUE -> ACOR calcule les montants par les démons et méthodes (init etc..); FALSE utilisé pour les rentes en entrée (qu'on ne recalcule pas) et les rentes issues de duplicate-instance (p. ex archives)
    (slot beneficiaire (type INSTANCE-NAME)(visibility public)(create-accessor read-write))
    (multislot remarques (visibility public)(create-accessor read-write)) )

    (defclass INDEMNITE_F (is-a PRESTATION)
    (role concrete)
    (pattern-match reactive)
    (multislot remarques (visibility public)(create-accessor read-write)) )


    (defmodule TRAITEMENT (import MAIN ?ALL))

    (defrule MAIN::demarrage_general
    (not (type_demande ?))
    (assert (an_augm 1998))

    (defmodule LECTURE (import MAIN ?ALL))                  

    (defrule init_lecture
    (an_augm ?date)
    (not (an_augm ?d&:(< ?d ?date)))
    (assert (phase_lecture))
    (assert (type_demande v))
    (make-instance  of FAMILLE_SUR)
    (make-instance  of FAMILLE_IF)
    (make-instance  of BASES_CALCUL (fam_sur )(fam_if )) )
    (defrule TRAITEMENT::detecte_vv_s
    (declare (salience -6))
    (type_demande ~r)
    (test_veu_rsimple ?mut ?date)
    ?rente <- (object (is-a ?rp)
        (beneficiaire ?veu)
        (remarques $?rem&:(not (member$ rempl_if_possible ?rem))))
    (or (test_dem i)
         (and (object (is-a INDEMNITE_F)(beneficiaire ?veu)(name ?if0) (remarques if_v_preserv))
            (object (is-a FAMILLE_IF)(ifs  $?if&:(member$ ?if0 ?if)))))
    (assert (ok)) )

    Thanks for any help…

  • Gary Riley

    Gary Riley - 2010-11-08

    Posted a fix into the subversion repository: ruledef.c

  • lna

    lna - 2010-11-30

    Hi Gary,

    Thank you so much for your help. I updated the file and finally got my projet to compile and run in runtime (under Windows XP).
    However, I am still encoutering some problems.
    As I previously mentionned, the whole projet code is quiet huge. We actually develop an application which is used to compute pension benefits in Switzerland. In order to check the good functionning of our code, we have a number of test cases.
    After having compiled and run the program in runtime, I have launched those test cases. Many of them are computed without problem. However, some of them generate an error at the simple assertion of a fact.
    The error is in factrete.c, in globle intBool FactJNGetVar3, line 574.
    Unhandled exception at 0x0042ad3b in CLIPSX.10.exe: 0xC0000005: Access violation reading location 0xfdfdfdfd (I don't know if that means anything to you !!!).

    It is really difficult for me to make a simplified version of the code since the problem is not systematic, so I'm really hoping, given the previous problem I had, that you have an idea of where this could come from and how it can be settled.

    Thanks for any help.


  • Gary Riley

    Gary Riley - 2010-12-02

    Can you determine the values of EngineData(theEnv)->GlobalLHSBinds and hack->whichPattern when the exception occurs?

  • lna

    lna - 2010-12-13

    Hi Gary,

    Yes, the values are :
    0x00d33b30 for EngineData(theEnv)->GlobalLHSBinds with betaMemory = 1, busy = 1 and bcount = 3 (tell me if you need other values)
    3 for hack->whichPattern

  • Gary Riley

    Gary Riley - 2011-01-01

    It's going to be difficult to determine the source of the problem for this one without stepping through the debugger. The key thing to determine is difference in the data structures between the run-time version and the non-run-time version.

  • Gary Riley

    Gary Riley - 2011-02-15

    I fixed two bugs which might be the source of this problem and checked them in the svn repository. One is to the file drive.c and the other is for the file factmngr.c

  • lna

    lna - 2011-02-15

    Hi Gary,

    Thanks for the info. I'll check into this and forward it to my colleagues (I'm away from work for a couple of months).
    Whenever my colleagues or I get to check things out, we'll keep you posted.


  • lna

    lna - 2011-10-20

    Hi Gary,

    Thanks for the bug fix… this actually solved the remaining problems I had. Everything works perfectly fine now ;)

    I do however have 3 issues to check out with you :

    1) It seems as though when I use an "exists" as condition on the LHS of a rule, all other conditions following the "exists" are not tested (at least in some of the rules). Do you have any idea where that could come from ?

    2) When are you considering making a full 6.3 release (instead of a Beta) ?

    3) We would like to make a donation to thank you for your great work. Could you please tell me how to proceed and exactly to whom that donation would go (to you personally ? To a group of developers ? other ?).



  • Gary Riley

    Gary Riley - 2011-10-21

    1. If the exists conditional element is not satisfied, then some conditions following will likely not be tested (it depends upon whether the conditions reference variables from other patterns). It's hard to say without looking at a specific rule and the data matching it.
    2. I've been working on bundling up the existing code and making an official release, but my progress is admittedly glacial. It's out of beta as far as I'm concerned, but there's still a bit of work to do in preparing it for release.
    3. If you go to the project main page,, there's a donate link near the upper right side.

  • lna

    lna - 2011-10-24

    Hi Gary ,

    My problem with the "exists" is illustrated in the following rule.
    If I leave it in the this configuration, the rule triggers while it should not because the "test" part is not satisfied.
    However, if I put the "exists" after the "test", the rule does not trigger (which is correct).
    Do you have any idea where that could come from ?

    (defrule TRAITEMENT::detecte_augmentation
      (an_augm ?an)
      (type_demande v|i|s)
      (mutation ? ?date_niv_mut)
      (not (prep_mut augmentation ?))
      (exists (object (is-a RENTE)
         (name ?rente)
         (mutable TRUE)              ;mutable
         (debut_droit ?dd&:(< ?dd (+ (* ?an 10000) 101)))
         (fin_droit ?fd&:(> ?fd (+ (* ?an 10000) 101)))
         (an_mont ?an_m&:(< (- ?an 3) ?an_m ?an))))
      (test (and (or (and (eq ?*param_mrapp* 1)
            (or (and (eq 0 ?*date_trait2*)
                                (<= (+ (* ?an 10000) 101) (plus1mois ?*date_traitement*))) 
                           (and (> ?*date_trait2* 0)
                                 (<= (+ (* ?an 10000) 101) (plus1mois ?*date_trait2*)))))
         (and (eq ?*param_mrapp* 0)
            (or (and (eq 0 ?*date_trait2*)
                                (<= (+ (* ?an 10000) 101) ?*date_traitement*)) 
                           (and (> ?*date_trait2* 0)
                                 (<= (+ (* ?an 10000) 101) ?*date_trait2*)))))
                 (>= (+ (* ?an 10000) 101) ?date_niv_mut)))
    (assert (detecte augmentation (+ (* ?an 10000) 101))) )

  • Gary Riley

    Gary Riley - 2011-10-24

    If the values of your global variables are not constants and are being changed as your rules execute, that is likely the cause of the problem. Global variables do not trigger pattern matching, so you can get odd behavior from rules of you are expecting them to do so. There's a section in the basic programming guide under defglobals that discusses this issue.

  • lna

    lna - 2011-11-24

    Hi Gary,

    I checked that out and made sur that my global variables did not change as my rule executes. So that doesn't seem to be the source of my problem. However, I do realize that it can be really difficult to pinpoint the source of the problem without having the whole source code at hand. If, however, you have another idea, thanks for posting it.

    Regarding the donation I asked about earlier on, my boss would like to know weather it will go to the project, to the developers, to you or to sourceforge (the information is required for us to be allowed to proceed with the donation).

    Thanks and best regards,


  • Gary Riley

    Gary Riley - 2011-11-27

    Donations go to me.  The source forge donation system is set up to place it in my paypal account.


Log in to post a comment.