HaxeFoundation / haxe

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

[cpp] haxeparser crash: "this->base was nullptr" #5040

Closed Gama11 closed 8 years ago

Gama11 commented 8 years ago
-main Main
-cpp out
-lib haxeparser
-debug
import byte.ByteData;
import haxeparser.HaxeParser;

class Main {
    public static function main() {
        new HaxeParser(ByteData.ofString('class Foo implements Interface {}'), "Foo.hx").parse();
    }
}
Exception thrown: read access violation.

this->base was nullptr.
>   Main-debug.exe!cpp::VirtualArray_obj::concat(cpp::VirtualArray inTail) Line 385 C++
    Main-debug.exe!haxeparser::HaxeParser_obj::parseTypeDecl() Line 1129    C++
    Main-debug.exe!haxeparser::HaxeParser_obj::parseTypeDecls(Array<String> pack, Array<Dynamic> acc) Line 994  C++
    Main-debug.exe!haxeparser::HaxeParser_obj::parseFile() Line 943 C++
    Main-debug.exe!haxeparser::HaxeParser_obj::parse() Line 170 C++
    Main-debug.exe!Main_obj::main() Line 41 C++
    Main-debug.exe!__hxcpp_main() Line 22   C++
    Main-debug.exe!main(int argc, char * * argv) Line 87    C++
    [External Code] 
    [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]  

Doesn't crash on 3.2.1.

Should probably be isolated further, but maybe you know what's going on already.

Simn commented 8 years ago

Oh boy...

Simn commented 8 years ago

I tried reducing this without any luck...

Gama11 commented 8 years ago

Getting a similar crash in Flixel (basic flixel games now compile again :)).

Exception thrown: read access violation.

this->base was nullptr.
    Mode.exe!cpp::VirtualArray_obj::__get(int inIndex) Line 462 C++
>   Mode.exe!flixel::group::FlxTypedGroup_obj::destroy() Line 93    C++
    Mode.exe!flixel::effects::particles::FlxTypedEmitter_obj::destroy() Line 181    C++
    Mode.exe!flixel::group::FlxTypedGroup_obj::destroy() Line 97    C++
    Mode.exe!flixel::FlxState_obj::destroy() Line 143   C++
    Mode.exe!MenuState_obj::destroy() Line 297  C++
    Mode.exe!flixel::FlxGame_obj::switchState() Line 609    C++
    Mode.exe!flixel::FlxGame_obj::update() Line 773 C++
    Mode.exe!flixel::FlxGame_obj::step() Line 675   C++
    Mode.exe!flixel::FlxGame_obj::onEnterFrame(Dynamic _) Line 546  C++
    Mode.exe!flixel::__FlxGame_objonEnterFrame(hx::Object * inObj, const Dynamic & inArg0) Line 560 C++
    Mode.exe!hx::CMemberFunction1::__run(const Dynamic & inArg0) Line 138   C++
    Mode.exe!Dynamic::operator()(const Dynamic & inArg0) Line 262   C++
    Mode.exe!openfl::_legacy::events::EventDispatcher_obj::dispatchEvent(hx::ObjectPtr<openfl::_legacy::events::Event_obj> event) Line 160  C++
    Mode.exe!openfl::_legacy::display::DisplayObject_obj::_hx___dispatchEvent(hx::ObjectPtr<openfl::_legacy::events::Event_obj> event) Line 291 C++
    Mode.exe!openfl::_legacy::display::DisplayObject_obj::_hx___broadcast(hx::ObjectPtr<openfl::_legacy::events::Event_obj> event) Line 267 C++
    Mode.exe!openfl::_legacy::display::DisplayObjectContainer_obj::_hx___broadcast(hx::ObjectPtr<openfl::_legacy::events::Event_obj> event) Line 560    C++
    Mode.exe!openfl::_legacy::display::Stage_obj::_hx___render(bool sendEnterFrame) Line 1156   C++
    Mode.exe!openfl::_legacy::display::Stage_obj::_hx___checkRender() Line 383  C++
    Mode.exe!openfl::_legacy::display::Stage_obj::_hx___pollTimers() Line 1141  C++
    Mode.exe!openfl::_legacy::display::Stage_obj::_hx___doProcessStageEvent(Dynamic event) Line 438 C++
    Mode.exe!openfl::_legacy::display::Stage_obj::_hx___processStageEvent(Dynamic event) Line 580   C++
    Mode.exe!openfl::_legacy::display::__Stage_obj_hx___processStageEvent(hx::Object * inObj, const Dynamic & inArg0) Line 585  C++
    Mode.exe!hx::CMemberFunction1::__run(const Dynamic & inArg0) Line 138   C++
    Mode.exe!val_call1(hx::Object * arg1, hx::Object * arg2) Line 622   C++
    lime-legacy.ndll!02c9f931() Unknown
    [Frames below may be incorrect and/or missing, no symbols loaded for lime-legacy.ndll]  
    lime-legacy.ndll!02c901d9() Unknown
    lime-legacy.ndll!02c66a38() Unknown
    lime-legacy.ndll!02c66fe9() Unknown
    lime-legacy.ndll!02edba9b() Unknown
    lime-legacy.ndll!02ca176a() Unknown
    lime-legacy.ndll!02edbddb() Unknown
    Mode.exe!ExternalPrimitive::__Run(const Array<Dynamic> & inArgs) Line 180   C++
    Mode.exe!Dynamic::operator()(const Dynamic & inArg0, const Dynamic & inArg1, const Dynamic & inArg2, const Dynamic & inArg3, const Dynamic & inArg4, const Dynamic & inArg5) Line 542   C++
    Mode.exe!openfl::_legacy::Lib_obj::create(Dynamic onLoaded, int width, int height, hx::Null<double> __o_frameRate, hx::Null<int> __o_color, hx::Null<int> __o_flags, String __o_title, hx::ObjectPtr<openfl::_legacy::display::BitmapData_obj> icon, hx::ObjectPtr<hx::Class_obj> stageClass) Line 282  C++
    Mode.exe!ApplicationMain_obj::main() Line 158   C++
    Mode.exe!__hxcpp_main() Line 22 C++
    Mode.exe!WinMain(void * hInstance, void * hPrevInstance, char * lpCmdLine, int nCmdShow) Line 87    C++
    [External Code] 
hughsando commented 8 years ago

Actually, fixed the first bug - need to test second one.

Simn commented 8 years ago

It no longer crashes! I'll let @Gama11 confirm that the real case is fixed too.

Gama11 commented 8 years ago

I can still reproduce the crash in Flixel's Mode demo in VirtualArray_obj::__get() (albeit the game seems to run slightly longer before the crash happens, could be coincidental though).

Gama11 commented 8 years ago

The original "isolated" case with haxeparser now runs through.

However, when running haxe-checkstyle (which the first example was isolated from) I now get a different callstack:

>   Main-debug.exe!cpp::VirtualArray_obj::indexOf(Dynamic inValue, Dynamic fromIndex) Line 374  C++
    Main-debug.exe!checkstyle::checks::naming::NameCheckBase_obj::hasToken(Dynamic token) Line 58   C++
    Main-debug.exe!checkstyle::checks::naming::ConstantNameCheck_obj::checkField(Dynamic f, hx::ObjectPtr<hx::EnumBase_obj> t, Dynamic e, Dynamic p) Line 161   C++
    Main-debug.exe!checkstyle::checks::naming::ConstantNameCheck_obj::checkFields(Array<Dynamic> d, Dynamic p) Line 130 C++
    Main-debug.exe!checkstyle::checks::naming::ConstantNameCheck_obj::checkClassType(hx::ObjectPtr<hx::EnumBase_obj> decl, Dynamic d, Dynamic pos) Line 78  C++
    Main-debug.exe!checkstyle::checks::naming::NameCheckBase_obj::checkClassFields() Line 93    C++
    Main-debug.exe!checkstyle::checks::naming::NameCheckBase_obj::actualRun() Line 75   C++
    Main-debug.exe!checkstyle::checks::Check_obj::run(hx::ObjectPtr<checkstyle::Checker_obj> checker) Line 93   C++
    Main-debug.exe!checkstyle::Checker_obj::runCheck(hx::ObjectPtr<checkstyle::checks::Check_obj> check) Line 633   C++
    Main-debug.exe!checkstyle::Checker_obj::run() Line 495  C++
    Main-debug.exe!checkstyle::Checker_obj::process(Array<Dynamic> files, hx::ObjectPtr<haxe::ds::StringMap_obj> excludesMap) Line 389  C++
    Main-debug.exe!checkstyle::Main_obj::start() Line 935   C++
    Main-debug.exe!checkstyle::Main_obj::processArgs() Line 421 C++
    Main-debug.exe!checkstyle::Main_obj::run(Array<String> args) Line 367   C++
    Main-debug.exe!checkstyle::Main_obj::main() Line 1119   C++
    Main-debug.exe!__hxcpp_main() Line 22   C++
    Main-debug.exe!main(int argc, char * * argv) Line 87    C++
    [External Code] 
    [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]  
hughsando commented 8 years ago

Having quite a bit of trouble getting flixel-demo to compile. Will try haxe-checkstyle

Gama11 commented 8 years ago

What problems are you running into?

hughsando commented 8 years ago

The haxe-checkstyle exe looks like it might be running into issues to do with the stack size - maybe a recursive algorithm gone too deep? Could be a bug in some stopping condition. I did not get the above crash on windows, so could be a bug. The VirtualArray::indexOf looks suspicious. -cmd cpp\Main-debug.exe -s src -s test -p resources/static-analysis.txt

Flixel is giving:

E:/Hugh/dev/code.google/flixel/flixel/system/layer/TileSheetExt.hx:87: characters 2-10 : Unknown identifier : __handle
E:/Hugh/dev/code.google/flixel/flixel/system/frontEnds/BitmapFrontEnd.hx:424: characters 24-47 : openfl.IAssetCache has no field bitmapData
E:/Hugh/dev/code.google/flixel/flixel/system/frontEnds/BitmapFrontEnd.hx:427: characters 14-29 : You can't iterate on a Dynamic value, please specify Iterator or Iterable
E:/Hugh/dev/code.google/flixel/flixel/util/loaders/CachedGraphics.hx:76: characters 3-18 : flash.display.BitmapData has no field dumpBits
E:/Hugh/dev/code.google/flixel/flixel/util/FlxSave.hx:186: characters 8-23 : Only inline or read-only (default, never) fields can be used as a pattern
E:/Hugh/dev/code.google/flixel/flixel/text/FlxText.hx:292: characters 2-28 : Float should be Null<Int>
E:/Hugh/dev/code.google/flixel/flixel/text/FlxText.hx:292: characters 2-28 : Float should be Int
E:/Hugh/dev/code.google/flixel/flixel/text/FlxText.hx:422: characters 2-28 : Float should be Null<Int>
E:/Hugh/dev/code.google/flixel/flixel/text/FlxText.hx:422: characters 2-28 : Float should be Int
source/MenuState.hx:59: characters 2-16 : flixel.effects.particles.FlxEmitter has no field velocity
source/MenuState.hx:60: characters 2-23 : flixel.effects.particles.FlxEmitter has no field angularVelocity
source/MenuState.hx:62: characters 2-21 : flixel.effects.particles.FlxEmitter has no field loadParticles
source/MenuState.hx:63: characters 2-20 : Float has no field set
source/MenuState.hx:115: characters 15-22 : Too many arguments
source/MenuState.hx:131: characters 19-30 : Class<flixel.FlxG> has no field random
source/MenuState.hx:132: characters 19-30 : Class<flixel.FlxG> has no field random
source/MenuState.hx:139: characters 20-26 : Unknown identifier : CENTER
source/MenuState.hx:145: characters 20-26 : Unknown identifier : CENTER
source/MenuState.hx:223: characters 34-45 : Class<flixel.FlxG> has no field random
source/PlayState.hx:29: characters 9-44 : Type not found : FlxTypedGroup
source/MenuState.hx:14: lines 14-251 : Defined in this class
source/MenuState.hx:201: characters 7-45 : ButtonID : Int -> Bool has no field A
source/MenuState.hx:113: lines 113-205 : Field update overloads parent class with different or incomplete type
E:/Hugh/dev/code.google/flixel/flixel/group/FlxTypedGroup.hx:92: lines 92-106 : Base field is defined here
source/MenuState.hx:14: lines 14-251 : Defined in this class
source/MenuState.hx:113: lines 113-205 : Different number of function arguments

Make me feel like I have a version conflict somewhere.

~...flixel-demos/Platformers/Mode>haxelib list flixel openfl lime
flixel-addons: 1.0.3 [1.1.0]
flixel-demos: 1.0.2 1.1.1 2.1.0 [dev:e:\Hugh\dev\code.google\flixel-demos]
flixel-ui: [1.0.1]
flixel: 3.3.6 3.3.8 4.0.1 [dev:e:\Hugh\dev\code.google\flixel]
~...flixel-demos/Platformers/Mode>haxelib list openfl
openfl-native: 1.0.1 1.2.2 [1.4.0]
openfl-nme-compatibility: [1.0.2]
openfl-ouya: [1.0.2]
openfl-samples: 1.2.1 [3.3.1]
openfl-tools: 1.0.0 [1.0.10]
openfl: 1.0.1 1.2.2 1.3.0 1.4.0 2.2.1 2.2.2 3.0.0-beta 3.6.1 [dev:e:\Hugh\dev\co
de.google\openfl]
~...flixel-demos/Platformers/Mode>haxelib list lime
lime-samples: [2.6.0]
lime-tools: 1.2.9 [1.5.7]
lime: 0.9.4 0.9.6 0.9.7 2.0.4 2.2.1 2.9.1 [dev:e:\Hugh\dev\code.google\lime]
Gama11 commented 8 years ago

The config / code base you run haxe-checkstyle with might matter. I used flixel (there's a config in the base directory on flixel dev).

That's definitely incompatible versions of flixel libs you got. Sounds like you got a recent version of the demos, but an outdated version of flixel itself that is incompatible with them. What commit / branch are you on there?

Gama11 commented 8 years ago

@hughsando pushed a GC fix (https://github.com/HaxeFoundation/hxcpp/commit/b884ebb71080e71f99bbab2be8100ffd79f81fa1). With that I'm unable to reproduce the crash in Flixel anymore! :+1:

Haxe-Checkstyle still crashes, but only in release mode now, so I have not callstack for that...

hughsando commented 8 years ago

You can use -D HXCPP_DEBUG_LINK to compile in release mode, but still retain the symbols. Some things get messed up by optimizations (like some inlining) but you usually get enough some some debugging with a native call stack.

On Wed, Apr 6, 2016 at 8:55 PM, Gama11 notifications@github.com wrote:

@hughsando https://github.com/hughsando pushed a GC fix ( HaxeFoundation/hxcpp@b884ebb https://github.com/HaxeFoundation/hxcpp/commit/b884ebb71080e71f99bbab2be8100ffd79f81fa1). With that I'm unable to reproduce the crash in Flixel anymore! [image: :+1:]

Haxe-Checkstyle still crashes, but only in release mode now, so I have not callstack for that...

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/HaxeFoundation/haxe/issues/5040#issuecomment-206357498

Gama11 commented 8 years ago

The checkstyle release mode crash is a null object reference in checkstyle itself, which is only try-catchable in debug mode on cpp it I guess.

hughsando commented 8 years ago

You can also do -D HXCPP_CHECK_POINTER to check nulls, with no other optimizations. But a crash into a native debugger on null access is usually pretty handy.

Gama11 commented 8 years ago

Thanks, good to know! No crashes with HXCPP_CHECK_POINTER.

I isolated this last crash to a checkstyle bug (https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/154#issuecomment-206366072). I think all hxcpp issues in this thread are fixed!