DragoniteSpam / Emu

UI for GameMaker. Looks like Windows Forms. Use this if you're not making a game, or otherwise if you want your game to look like tax software or something.
https://dragonite.itch.io/emu
MIT License
40 stars 3 forks source link

Error when Clicking on a Textbox #3

Closed PoshoDev closed 4 years ago

PoshoDev commented 4 years ago

Hey Michael,

I finally got time to use this life-saving extension and I encountered an error I don't understand. 🤔

When I click in one of my text boxes I get this error:

############################################################################################
ERROR in
action number 1
of Create Event
for object obj_global_3:

Unbalanced surface stack. You MUST use surface_reset_target() for each set.############################################################################################

I looked everywhere in the included obj_emu_demo for surface_reset_target() and it is never referenced so I don't know what's happening.

This is how I'm adding the textbox, if it helps:

tab_newtask.AddContent([
    new EmuText(32, EMU_AUTO, 512, 32, "New Task"),
    new EmuTextbox_H(32, EMU_AUTO, 512, 32, "Title:", task_new.title, "Empty", 32, E_InputTypes.STRING, function()
        { task_new.title = value })
]);

Hope you can help me with this. I'm enjoying this extension so far! 😄

Cheers, Posho

DragoniteSpam commented 4 years ago

Interesting. The input rectangles are each their own surface (this makes it easier to do things like keep text from spilling out-of-bounds and looking bad), but they should handle themselves without any outside interference. Does this happen when you do something specific, or for any and all input boxes?

PoshoDev commented 4 years ago

Any input box. I've been using EmuTextbox_H just as you use them in the demo. They draw fine but as soon as I click it it crashes.

DragoniteSpam commented 4 years ago

Poked around a bit, nothing stood out. Could you send an example project?

PoshoDev commented 4 years ago

Here's the commit when I last worked with Emu. Press 'N' to bring up the Emu container. I'm pretty sure this has to be an issue on my behalf, just don't know what it is. Also, please ignore the spaghetti. 👉👈🍝 Project.zip

DragoniteSpam commented 4 years ago

Oh, I see what's going on. The callback methods run in the scope of the instance they've been attached to, which in this case would be the text box. I'm not sure why yours was complaining about the surface stack (I just got Variable EmuTextbox_H.task_new(100408, -2147483648) not set before reading it), but the variable task_new doesn't exist in the scope of the function because that's already the struct that's running the code - imagine using the with() statement on an instance in old GameMaker.

GameMaker allows you to define instance variables anywhere so you can always just attach your own variables to the text box:

// New Task Tab
var textbox = new EmuTextbox_H(32, EMU_AUTO, 512, 32, "Title:", task_new.title, "Empty", 32, E_InputTypes.STRING, function() { task.title = value; });
textbox.task = task_new;

tab_newtask.AddContent([
    new EmuText(32, EMU_AUTO, 512, 32, "New Task"),
    textbox,
]);

There are some other things you can do like making task_new globally accessible but that's probably the most straightforward.

PoshoDev commented 4 years ago

Ooh, it makes sense. Thank you so much for your troubles!