[SOLVED] Why this function call is throwing a trace overflow?

Hello,

I’m trying to do a very basic event/signal class (like my previous topic, some months ago), even when there are great libs I want to learn the inner workings and at the same time create my simple version.

For simplicity I recreated only the problematic code and occurs at least when targeting neko and cpp:

package ;

import openfl.display.Sprite;
import openfl.events.MouseEvent;

class NewClass extends Sprite {
    public function new() {
        super();
        start();
    }
    
    public function start():Void {
        var obj:Sprite;
        obj = new Sprite();
        obj.x = 100;
        obj.y = 75;
        
        obj.graphics.beginFill(0x004953, 1);
        obj.graphics.drawRect(0, 0, 150, 100);
        obj.graphics.endFill();
        
        addChild(obj);
        
        LaunchPad.store("MouseClick", tracer);
        
        obj.buttonMode = true;
        obj.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    }
    
    public function onMouseUp(evt:MouseEvent) {
        LaunchPad.execute("MouseClick", "Clicked!");
    }
    
    public function tracer(str:String):Void {
        tracer(str);
    }
}


class LaunchPad {
    private static var storedTasks = new Map<String, Dynamic->Void>();
    private static var storedObjects = new Map<String, Dynamic>();
    
    public function new() {}
    
    public static function store(taskName:String, task:Dynamic->Void, ?object:Dynamic):Void {
        storedTasks.set(taskName, task);
    }
    
    public static function release(taskName:String):Void {
        if (storedTasks.exists(taskName)) {
            storedTasks.remove(taskName);
        }
    }
    
    public static function execute(taskName:String, ?params:Dynamic, ?object:Dynamic) {
        var tempExec:Dynamic;
        
        if (storedTasks.exists(taskName)) {
            tempExec = storedTasks.get(taskName);
                        
            tempExec(params);
            trace("executed!");
        }
    }
}

So in theory my attempt looks good, but idk why is kinda looping and instead of making one trace for each click, it makes tens or hundreds of trace calls in a sec that crashes the app.

Anyone can tell me why?

What version are you using? What happens when you test in Flash?

You’re triggering the tracer method indefinitely here instead of calling trace

Might want to think about renaming tracer to something not so close to trace so this doesn’t happen again, perhaps print… or see if you can’t figure out a way to use trace directly…

@Driklyn I think I need to take some rest lol, couldn’t see I was calling my own method instead of the proper trace. Thanks a lot and will try to remember this, I’m used to ‘label’ simple names while prototyping but I need to take more attention to it, thanks again.

@singmajesty I’m using Haxe 3.2.0 and OpenFL 3.1.0