HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.18k stars 655 forks source link

HXCPP_CHECK_POINTER does not work in some situations #7253

Open nulld opened 6 years ago

nulld commented 6 years ago

Expected that in debug mode it must check all pointers it haxe generated code. Is it so?

For eg this code is crashes unexpectedly:

package;

interface ISomeInterface
{
    function getSomeProperty():Float;
}

class SomeClass {
  var nullPointer:ISomeInterface;

  public var someProperty(get, null):Float;

  public function new() {}

  function get_someProperty():Float {
    return nullPointer.getSomeProperty();
  }
}

class Main
{
 public static function main(): Void
 {
      var inst = new SomeClass();
      trace("Begin");
      trace("Begin case 1");
      try {
        var unexistProperty = Reflect.getProperty(inst, "unexistProperty");
        trace(unexistProperty.some); 
      }
      catch(e:Dynamic) {
        trace(e); //Null Object Reference - works as expected
      }
      trace("End case 1");

      trace("Begin case 2");
      try {
        var val = Reflect.getProperty(inst, "someProperty"); //Just crash
        trace(val);
      }
      catch(e:Any) {
        trace(e);
      }
      trace("End case 2");
      trace("Finish");
 }
}
Gama11 commented 6 years ago

This is where it's crashing (even with HXCPP_CHECK_POINTER explicitly defined):

This is an issue for debugging, since it can lead to the entire application crashing when printing properties in the variables view (https://github.com/vshaxe/hxcpp-debugger/issues/8).

EliteMasterEric commented 1 year ago

image image Here's a screenshot of the error I receive in a barebones project based on the source code in the OP. Here's the source for that (I edited it to remove reflection in case that was part of the issue): https://github.com/EliteMasterEric/hxcpp-Issue7253

image image And here's a screenshot of the error I receive in another project (closed source at the moment). It appears in the same circumstances so I strongly suspect it is strongly related, but it may have a slightly different root cause due to the very different call stack