Why does this Haxe try-catch block still fail when using Release mode for a C ++ target

I have a HaxeFlixel project that works fine in debug mode for various purposes including flash, neko and windows. But Targeting Windows in release mode , I have an unexpected crash and it is surprising that this happens inside a try-catch block. Here's the drop function:

/**
 * Will safely scan a parent node children, search for a child by name, and return it text.
 * @param   parent an Fast object that is parent of the `nodeNamed` node
 * @param   nodeName the node name or a comma-separated path to the child (will scan recursively)
 * @return node text as String, or null if child is not there
 */
public static function getNodeText(parent:Fast, nodeName:String):String {

    try {
        var _node : Fast = getNodeNamed(parent, nodeName);

        //if (_node == null)
        //  return null;

        // next line will crash if _node is null
        var it :Iterator<Xml> = _node.x.iterator();
        if ( it == null || !it.hasNext() )
            return null;
        var v = it.next();
        var n = it.next();
        if( n != null ) {
            if( v.nodeType == Xml.PCData && n.nodeType == Xml.CData && StringTools.trim(v.nodeValue) == "" ) {
                var n2 = it.next();
                if( n2 == null || (n2.nodeType == Xml.PCData && StringTools.trim(n2.nodeValue) == "" && it.next() == null) )
                    return n.nodeValue;
            }
            //does not only have data (has children)
            return null;
        }
        if( v.nodeType != Xml.PCData && v.nodeType != Xml.CData )
            //does not have data";
            return null;
        return v.nodeValue;
    }catch (err:Dynamic) {
        trace("Failed parsing node Text [" + nodeName+"] " + err );
        return null;
    }
}

      

By including the line if (_node == null) return null;

, it works safely again. Catching errors like Dynamic

I thought I needed to catch every possible type of error! Why is this happening? And why does it appear in release mode?

My IDE is FlashDevelop and I am using HaxeFlixel 3.3.6, lime 0.9.7 and openFL 1.4.0 if it matters

EDIT: I suspect it has something to do with how the translated C ++ code missed the Dynamic

Exception. Equivalent generated C ++ code:

STATIC_HX_DEFINE_DYNAMIC_FUNC2(BaxXML_obj,_getNodeNamed,return )

::String BaxXML_obj::getNodeText( ::haxe::xml::Fast parent,::String nodeName){
    HX_STACK_FRAME("bax.utils.BaxXML","getNodeText",0x4a152f07,"bax.utils.BaxXML.getNodeText","bax/utils/BaxXML.hx",56,0xf6e2d3cc)
    HX_STACK_ARG(parent,"parent")
    HX_STACK_ARG(nodeName,"nodeName")
    HX_STACK_LINE(56)
    try
    {
    HX_STACK_CATCHABLE(Dynamic, 0);
    {
        HX_STACK_LINE(57)
        ::haxe::xml::Fast _node = ::bax::utils::BaxXML_obj::getNodeNamed(parent,nodeName);      HX_STACK_VAR(_node,"_node");
        HX_STACK_LINE(63)
        Dynamic it = _node->x->iterator();      HX_STACK_VAR(it,"it");
        // ...  Let skip the irrelevant code
    }
    catch(Dynamic __e){
        {
            HX_STACK_BEGIN_CATCH
            Dynamic err = __e;{
                HX_STACK_LINE(82)
                ::String _g5 = ::Std_obj::string(err);      HX_STACK_VAR(_g5,"_g5");
                HX_STACK_LINE(82)
                ::String _g6 = (((HX_CSTRING("Failed parsing node Text [") + nodeName) + HX_CSTRING("] ")) + _g5);      HX_STACK_VAR(_g6,"_g6");
                HX_STACK_LINE(82)
                ::haxe::Log_obj::trace(_g6,hx::SourceInfo(HX_CSTRING("BaxXML.hx"),82,HX_CSTRING("bax.utils.BaxXML"),HX_CSTRING("getNodeText")));
                HX_STACK_LINE(83)
                return null();
            }
        }
    }
    HX_STACK_LINE(56)
    return null();
}

      

+3


source to share


3 answers


What haxedefs have you identified?

Adding them to your project.xml file might help:

<haxedef name="HXCPP_CHECK_POINTER"/>  <!--makes null references cause errors-->
<haxedef name="HXCPP_STACK_LINE" />    <!--if you want line numbers-->
<haxedef name="HXCPP_STACK_TRACE"/>    <!--if you want stack traces-->

      



You can also try the crashdumper library: https://github.com/larsiusprime/crashdumper

(Crashdumper will by default include HXCPP_CHECK_POINTER as part of its include.xml and will set hooks for hxcpp errors and openfl / lime open error events)

+3


source


I guess it boils down to how C ++ handles Pointer Exceptions. This is not true!



More details here or here

+2


source


It seems strange, there are some questions that can help in solving it.

  • It looks like you are making quite some assumptions about what the xml looks like (by doing it manually it.next()

    ), why?
  • Why are you using this big ass try-catch block?
  • What getNodeNamed looks like, it seems it can return null

    .
  • Do you have an example xml for testing?
0


source







All Articles