cinetec_tech Posted December 15, 2014 Posted December 15, 2014 hi: I'm trying to open a dialog in my class to let user select a material. but i found using a dialog will cause the instance break some how. it can be reproducible with the unigine sample file ui_00.cpp after modified as attachment. to reproduce: 1: place the attached in your 2.0 sample widgets folder to replace the old one. 2: open the world and click any button. you will see the error in console. it basically render all vector type unusable. I need to know if this is a incorrect use? or workaround ? a bug fix for it? ASAP thanks ui_00.cpp
azagniy Posted December 16, 2014 Posted December 16, 2014 Hi. The "dialogMaterial" function uses a specific wait construct. The "wait" construct is valid when called from a simple function (rather then the member function of the class). In the "ui_00.cpp" sample Window class has a simple function called "callback_redirector". You can use this function to show material dialog and send result as parameter to the "clicked" function: // clicked callback void clicked(string mat_name) { Material material = engine.materials.findMaterial(mat_name); int total = materials.size(); engine.message("mat = %s, total = %i\n",typeinfo(material),total); } // callback redirector void callback_redirector(string func,Window window) { string mat_name = ""; if(dialogMaterial(TR("Select material"),mat_name)) { window.call(func,mat_name); } }
cinetec_tech Posted December 16, 2014 Author Posted December 16, 2014 hi yingaz: thanks , that works for me. any reason why can't call "wait" from a class? is it fixable?
azagniy Posted December 17, 2014 Posted December 17, 2014 Hi, Wait construct can't work with classes methods because only address of the function placed into a list of waiting functions and this list don't know about class instance.
cinetec_tech Posted December 24, 2014 Author Posted December 24, 2014 Hi, Wait construct can't work with classes methods because only address of the function placed into a list of waiting functions and this list don't know about class instance. hi yingaz: I found not use ”Wait“ stil doesn't help. basically all dialog windows has to be called from the redirector function. this is kind of huge limitation.example: if we want user to confirm a Yes or No dialog in the middle to overwrite something... Hope this could be fixed.
unclebob Posted December 25, 2014 Posted December 25, 2014 Hi there! Let me bring some happiness and enlightenment to this topic! Wait construct will only work in script "threads" (not real ones) and in ui callbacks which are the same "threads" basically. First of all, I assume you have that case (feel free to correct me): int update() { if(something is happened) very_important_processing_func(data); return 1; } int very_important_processing_func(some data) { do_step_1(some data); do_step_2(some more data); if(dialogMessageYesNo("Are you sure?")) { // here goes the problem do_very_important_step_3(very cool data); } return 1; } Which could be rewritten to "thread-like" form: int update() { if(something is happened) thread(functionid(very_important_processing_func),data); return 1; } int very_important_processing_func(some data) { do_step_1(some data); do_step_2(some more data); if(dialogMessageYesNo("Are you sure?")) { // no problem here because we're inside script "thread" now do_very_important_step_3(very cool data); } return 1; } See? Not a big deal!
cinetec_tech Posted January 2, 2015 Author Posted January 2, 2015 thanks Bob! will try your solution.
Recommended Posts