Silverfrost Forums

Welcome to our forums

ClearWin+/.NET callback crash

5 Feb 2009 3:20 #4296

Hello,

trying to combine a ClearWin+ application, which uses a callback on a Quit button, with some interface to a .NET library. Both things are unrelated at the moment, that is the call to a .NET routine is separate from the ClearWin+ code.

In general it works fine, the .NET subroutine is called, and the ClearWin+ window is created. If the .NET subroutine contains more complex memory operations, or, which is relevant, a plain call to the garbage collector, the ClearWin+ callback ceases to work. The errormessage translates to something like 'CallbackOnCollectDelegate was found' which seems to indicate that the garbage collector removed (?) the callback function, and ftn95lib.mdl!Salford.Fortran.RTLibrary+clearwin_callback::Invoke fails.

Some steps to reproduce this:

Create new Project, FTN95 Application Add another project: File, Add, New Project Choose C# Class Library for example In the project settings assure that the FortranApplication is the start project. Also make the ClassLibrary project a dependency of the FortranApplication

Add the ClassLibrary to the References of the FortranApplication.

Code for the fortran part:

INTEGER FUNCTION cb_quit()
    IMPLICIT NONE
    cb_quit = 0
END FUNCTION

PROGRAM Main
    IMPLICIT NONE
    EXTERNAL cb_quit
    INTEGER cb_quit, iw

    ASSEMBLY_EXTERNAL(NAME='ClassLibrary1.Class1.class_test_routine')      &
                      class_test_routine
    OBJECT('ClassLibrary1.Class1') CLASS1
    CLASS1 = NEW@('ClassLibrary1.Class1')
    CALL class_test_routine(CLASS1)
    iw = winio@('%^bt[&Quit]', cb_quit)
END

Code for the c# part:

using System;
using System.Collections.Generic;
using System.Text;

namespace ClassLibrary1
{
    public class Class1
    {
        public void class_test_routine()
        {
//            GC.Collect();
            const int max_lp = 100;

            int[][] test = new int[max_lp][];
            for (int ct = 0; ct < max_lp; ct++)
            {
                test[ct] = new int[65536];
            }
        }

    }
}

The error might or might not occur with the int[] allocation as above, it seems to depend on the garbage collector's properties (memory size?), but forcing the collector to run via GC.Collect() always results in the bug.

I've already tried quite a lot of things, like encapsulating the ClearWin+ code in a module, but couldn't get it working. Any help or hints appreciated.

Thanks.

5 Feb 2009 4:19 #4297

Have you read the KBase article in this Forum called 'Using ClearWin+ under .NET'?

6 Feb 2009 7:20 #4298

Have you read the KBase article in this Forum called 'Using ClearWin+ under .NET'?

Yes I'm aware of that article yet fail to see how it'd be helpful in this case.

Besides that, when using the code posted in the article, along with a reference to another project ( /REF to a C# class library for example) the compilation fails with an internal linker error (or with an exception violation in 0048ea78: collect_fortran_symbols(<ptr>struct scope) [+0231] if there's code that creates an object). Both issues vanish if the include <windows.ins> is not specified.

Thanks.

6 Feb 2009 7:46 #4301

The main point is that we are only beginning to provide some support for ClearWin+ under .NET. Anything you get at the moment is a free bonus because ClearWin+ was not expected to work under .NET and Visual ClearWin was designed to replace it.

I will not be able to respond to your query for a little while. In the meantime one of our users may be able to help.

Please login to reply.