Strange common-dialog-crashes

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
art-ganseforth
Earned some good credits
Earned some good credits
Posts: 147
Joined: Mon Sep 01, 2014 10:14 am

Strange common-dialog-crashes

Post by art-ganseforth »

Hello,

i maybe need some help in a quiet complex thing. My application crasches when i call any common dialog-window like wxMessegaBox or wxOpenFileDialog from a specific function.

In my wxWidgets/OpenGL application i have coded a script-interpreter, which i use to for various things like creating and managing wxWidgets-controls, calling OpenGL-functions and also basic math- and string-operations. This interpreter is a quiet buggy "prototyope" and i will have to replace it later by a faster one but currently i need a soluion for a strange program-crash.
This problem may be a deep system thing and - sorry - for different reasons a debugger doesn't work.

To understand the problem, you need to know the following:
1. The interpreter is coded as an object (clsParser)
2. Data (only (arrays of) float(GLfloat) or single char*) is kept in simple reference-counting container-objects
3. At program-start, there is created a basic instance of clsParser (=>1.) the and a lot of nested children - one per wxControl in the user-interface, and for other objects.
4. This creation-process is executed by the outer global parser. So the user-interface of my program is completly created by interpreting a JavaScript-like string. Here is most of the script, which is interpreted at beginning (don't read this compleatly, it's just for understading the complexity):

Code: Select all

texture Texture2d(w=1, h=1) {
    var Size         [w, h];  
    var Render3d     = 0;  
};

// Basic controls

control outScreen(x, y, w=1024, h=600) {
    var Type         = 'SCREEN';
    //var Title        = caller.Title;
    var Position     [x, y];
    var Size         [w, h];
    var Link         = "";
//    var WindowStyle  = C_BORDER_NONE;
};

control anyDisplay(x, y, w=8, h=2) {
    var Type         = 'DISPLAY';
    //var Title        = caller.Title;
    var Position     [x, y];
    var Size         [w, h];
    var WindowStyle  = C_BORDER_NONE;
};

control texStatic(x, y, w=8, h=2) {
    var Type         = 'DISPLAY';
    //var Title        = caller.Title;
    var Position     [x, y];
    var Size         [w, h];
    var WindowStyle  = C_BORDER_NONE;
    var ModuleTypes  = 'Shader-control|Texture|TexEnv|Renderer';
    caller:var Buffer = new Texture2d(1,1);
    var OnRightUp    = 'print("hallo");
        caller:var File=OpenFileDialog(File, "Open Image-file", "JPEG files (*.jpg;*.jpeg)|*.jpg;*.jpeg|BMP and GIF files (*.bmp;*.gif)|*.bmp;*.gif|PNG files (*.png)|*.png");
        caller:Buffer:Set(File);Refresh();
'; 
    caller:Set(File);
    var OnDraw       = ';';
};

control anyScope(x, y, w=4, h=1) {
    var Type         = 'SCOPE';
    var Title        = '';//caller.Title;
    var Position     [x, y];
    var Size         [w, h];
    var WindowStyle  = C_BORDER_NONE;
};

shader BasicShader(x, y) {
    var Type         = 'SHADER';
    var Position     [x, y];
    var Size         [3, 1];
    var WindowStyle  = C_BORDER_NONE;
    var CompileState = 0;
    var ErrorMessage = '';
    var System       = _SHADER_SYSTEM;
    var Header       = _SHADER_GLOBALS;
    var Presets      = _SHADER_PRESETS;
    var Vertex       = _V_SHADER;
    var TessCtrl     = _TC_SHADER;
    var TessEval     = _TE_SHADER;
    var Geometry     = _G_SHADER;
    var Fragment     = _F_SHADER;
};

control valAny (Title,  x, y, w = 3, min=0, max=1, step=0.01, Value=0.33) {
    var Type         = 'VALUE';
    var WindowStyle  = C_BORDER_NONE;
    var Position     [x, y];
    var Size         [w, 1];
    var Range        [min, max, step];
};

color colorBase (Title,  x, y, w = 6, h = 240, s = 255, v = 255) {
    var Type         = 'COLORBASE';
    var WindowStyle  = C_BORDER_NONE;
    var Position     [x, y];
    var Size         [w, 1];
    var Color        [0,0,0,1,h/360, s/255, v/255,1]
};

color colorAnyHSV (Title,  x, y, w = 6, h = 240, s = 255, v = 255) {
    var Type         = 'COLOR';
    var WindowStyle  = C_BORDER_NONE;
    var Position     [x, y];
    var Size         [w, 1];
    var Color        [0,0,0,1,h/360, s/255, v/255,1]
};

control sel3dThrough(x, y, w) {
    var Type         = 'SELECT';
    var WindowStyle  = C_BORDER_NONE;
    var Position     [x, y];
    var Size         [w, 1];
//    var List         = 'OFF';
    var ModuleTypes  = '3d through';
    var Selection    = 'OFF';
};

control selModule (Title,  x, y, w, ModuleTypes, Selection) {
    var Type         = 'SELECT';
    var WindowStyle  = C_BORDER_NONE;
    var Position     [x, y];
    var Size         [w, 1];
};

control valAngel (Title, x, y, w = 3, rng = 180, stp = 1, Value = 0) {
    var Type         = 'VALUE';
    var WindowStyle  = C_BORDER_NONE;
    var Position     [x, y];
    var Size         [w, 1];
    var Range        [-rng, rng, stp];
};

control selList (Title, x, y, w, List, Selection) {
    var Type         = 'SELECT';
    var WindowStyle  = C_BORDER_NONE;
    var Position     [x, y];
    var Size         [w, 1];
};

control textEdit (Title, x, y, w=16, h=1, Text) {
    var Type         = 'TEXT';
    var WindowStyle  = C_BORDER_NONE + C_TE_MULTILINE + C_TE_NO_VSCROLL;// + C_TE_DONTWRAP;
    var Position     [x, y];
    var Size         [w, h+0.1];
};

control lineEdit (Title, x, y, w=16, h=1, Text) {
    var Type         = 'TEXT';
    var WindowStyle  = C_BORDER_NONE + C_TE_NO_VSCROLL;// + C_TE_DONTWRAP;
    var Position     [x, y];
    var Size         [w, h+0.1];
};

texture DisplayedTexture2d (yo = 0, texW = 24, texH = 24) {
    var Size         [texW, texH];  
    var Render3d     = 0;  
    caller:var vcSync       = new valAny     ('1/96 Sync',   0,   0+Buffer.yo,  2,    0,    96,   1,   0);
    caller:var Display      = new anyDisplay (               2,   0+Buffer.yo, 10,    2.5);
    caller:var vcWidth      = new valAny     ('Width',      12,   0+Buffer.yo,  3.5,  1,  2048,   1,   Buffer.texW);
    caller:var vcHeight     = new valAny     ('Height',     12,   1+Buffer.yo,  3.5,  1,  2048,   1,   Buffer.texH);
    caller:vcWidth: var OnChange = 'caller:Buffer:var Size[caller.vcWidth.Get(), caller.vcHeight.Get()];';
    caller:vcHeight:var OnChange = 'caller:Buffer:var Size[caller.vcWidth.Get(), caller.vcHeight.Get()];';
};


control SimShader(x, y, oy=0) {
    var Type         = "MACRO";
    var Title        = 'Shader';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
    var Shader       = new BasicShader ( 0, 1+oy);
    var Ctrl1        = new valAny      ('Ctrls1.X',  0, 0+oy,  3, 0, 1, 0.01, 0.0);
    var Ctrl2        = new valAny      ('Ctrls1.Y',  3, 0+oy,  3, 0, 1, 0.01, 0.3);
    var Ctrl3        = new valAny      ('Ctrls1.Z',  6, 0+oy,  3, 0, 1, 0.01, 0.3);
    var Ctrl4        = new valAny      ('Ctrls1.R',  9, 0+oy,  3, 0, 1, 0.01, 0.0);
    var Color        = new colorAnyHSV ('Ctrls2', 12, 0+oy,  4, 1, 240, 255, 32);
    var Texture      = new selModule   ('Texture 1', 3, 1+oy, 13, 'Shader-control|Shader|Texture|TexEnv|Renderer', 'Stock texture');

    var OnApply      = 'Color.UpdateRGB(); 
        Shader.SetUniforms("Texture", 2, "
uniform vec4 Ctrls0;
uniform vec4 Ctrls1;"); 
        glUniform("Ctrls0", Ctrl1.Value, Ctrl2.Value, Ctrl3.Value, Ctrl4.Value); glUniform4fv("Ctrls1", Color.Color);
Texture.Apply();
    ';
};
RegisterMacro('SimShader', 'Shader');

function Texture4(ST_yo=0, ST_w=16, ModuleTypes='Shader|Texture|TexEnv|Renderer', Selection = 'OFF') {
    var Texture1  = new selModule  ('Texture 1',  0,   ST_yo    , 0+ST_w,   ModuleTypes, Selection);
    var Texture2  = new selModule  ('Texture 2',  0,   ST_yo + 1, 0+ST_w,   ModuleTypes, Selection);
    var Texture3  = new selModule  ('Texture 3',  0,   ST_yo + 2, 0+ST_w,   ModuleTypes, Selection);
    var Texture4  = new selModule  ('Texture 4',  0,   ST_yo + 3, 0+ST_w,   ModuleTypes, Selection);
};
function VisibleRows_(VR_yo=0, VR_xo=16, VR_w = 1.4, VR_ofs=0, VR_min=1, VR_max=4, VR_step=1, VR_Value=1) {
    var VisibleRows          = new valAny  ('Active rows', VR_xo,  VR_yo, VR_w, VR_min, VR_max, 1, VR_Value);
    VisibleRows:var Offset   = caller:VR_ofs + VR_yo;
    VisibleRows:var Step     = caller:VR_step;
    VisibleRows:var OnChange ='caller.SetRows(VisibleRows:Get() * Step + Offset);';
    //SetRows(VisibleRows:Get() * Step + Offset);
};
function VisibleRows(VR_Value=1, VR_yo=0, VR_xo=16, VR_w = 1.4, VR_ofs=0, VR_min=1, VR_max=4, VR_step=1) {
    var VisibleRows          = new valAny  ('Active rows', VR_xo,  VR_yo, VR_w, VR_min, VR_max, 1, VR_Value);
    VisibleRows:var Offset   = caller:VR_ofs + VR_yo;
    VisibleRows:var Step     = caller:VR_step;
    VisibleRows:var OnChange ='caller.SetRows(VisibleRows:Get() * Step + Offset);';
    //SetRows(VisibleRows:Get() * Step + Offset);
};

control TestPanel(x, y):VisibleRows(1,3):Texture4(3) {
    var Type         = "MACRO";
    var Title        = 'Test';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 7];
 //   var text         = new textEdit     ('', 0,1,16,2);
    var Color        = new colorBase('', 6,  1);
//    var Texture1     = new selModule  ('Texture', 0,  1, 6, 'Shader|Texture|TexEnv|Renderer', 'Stock texture');
//    var Buffer       = new Texture2d  (60, 10);
//    var Display      = new anyDisplay ( 0,  2);
//    var Shader       = new BasicShader( 9,  0);
////    var OnUpdatePlane = 'for Plane[][][0] { _=pRotateX(_, Ctrl1.Value*4); };';
//    var OnUpdatePlanePointwise = '_ = pRotateX(_, Ctrl1.Value * 4);';
//    var OnDraw       = 'Color.UpdateRGB(); Shader.Apply(); Texture1.Apply(); glUniform("Ctrls0", Ctrl1.Value, 0, 0, 0);';
//    var OnRefresh    = 'Display.Refresh();';
};
RegisterMacro('TestPanel', 'Texture');


control TestRenderer(x, y) : SimShader(0, 0,2) {
    var Type         = "MACRO";
    var Title        = 'Test';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 4];
//alert(Shader);
   // var Shader       = new BasicShader( 0, 0);
    var Display      = new anyDisplay ( 3, 0);
    var Width        = new valAny     ('Width',  11, 0, 3, 8, 2000, 8, 1920);
    var Height       = new valAny     ('Height', 11, 0, 3, 8, 1500, 8, 1024);
//var test = new SimShader(0, 2);
//    var Texture     = new selModule ('Texture', 0, 2, 16, 'Shader|Texture|TexEnv|Renderer', 'Stock texture');
    var Buffer       = new Texture2d  (Width.Get(), Height.Get());
    var OnDraw       = 'Color.UpdateRGB(); Shader.Apply(); Buffer.SetTarget(); 
Texture.Apply();glUniform("Ctrls0", Ctrl1.Value, Ctrl2.Value, Ctrl3.Value, 0); glUniform4fv("Ctrls1", Color.rgb);';
    var OnRefresh    = 'Display.Refresh();';
    var OnApply      = 'Buffer.Size[1] = Width.Get(); Buffer.Size[2] = Height.Get(); 
                        Shader.SetUniforms("Texture", 2, "uniform vec4 Ctrls0; uniform vec4 Ctrls1;");
                         ';
};
RegisterMacro('TestRenderer', 'Renderer');

control Rot(x, y) {
    var Type         = "MACRO";
    var Title        = 'Curver';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 3];
//    var CallBefore   = new sel3dThrough(0, 0, 16);
    var AngelX       = new valAngel ('Angel X',  0, 0, 3, 180, 1, 0);
    var AngelY       = new valAngel ('Angel Y',  3, 0, 3, 180, 1, 0);
    var AngelZ       = new valAngel ('Angel Z',  6, 0, 3, 180, 1, 0);
    var OnApply      = '
glRotatef(AngelX.Get(), 1, 0, 0);
glRotatef(AngelY.Get(), 0, 1, 0);
glRotatef(AngelZ.Get(), 0, 0, 1);
';
    var OnUpdatePlanePointwise= '
pRotateX   (_, AngelX.Get01());
pRotateY   (_, AngelY.Get01()); 
pRotateZ   (_, AngelZ.Get01()); 
';
};
//RegisterMacro('Rot', 'Position');

control Position(x, y) : VisibleRows(2, 0) {

    var Type         = "MACRO";
    var Title        = 'Position';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
//  var CallBefore   = new sel3dThrough(0, 0, 16);
    var vcOfsX0      = new valAny   ('X-Position',  0, 1, 3,  -1, 1, 0.01,  0);
    var vcOfsY0      = new valAny   ('Y-Position',  3, 1, 3,  -1, 1, 0.01,  0);
    var vcOfsZ0      = new valAny   ('Z-Position',  6, 1, 3,  -1, 1, 0.01,  0);
    var vcOfsF0      = new valAny   ('Factor',      9, 1, 3,   0, 4, 0.01,  1);
    var vcRotX0      = new valAngel ('Angel X',     0, 0, 3, 180, 5, 0);
    var vcRotY0      = new valAngel ('Angel Y',     3, 0, 3, 180, 5, 0);
    var vcRotZ0      = new valAngel ('Angel Z',     6, 0, 3, 180, 5, 0);

    var vcOfsX1      = new valAny   ('X-Position',  0, 3, 3,  -1, 1, 0.01,  0);
    var vcOfsY1      = new valAny   ('Y-Position',  3, 3, 3,  -1, 1, 0.01,  0);
    var vcOfsZ1      = new valAny   ('Z-Position',  6, 3, 3,  -1, 1, 0.01, -1);
    var vcOfsF1      = new valAny   ('Factor',      9, 3, 3,   0, 4, 0.01,  1);
    var vcRotX1      = new valAngel ('Angel X',     0, 2, 3, 180, 5, 0);
    var vcRotY1      = new valAngel ('Angel Y',     3, 2, 3, 180, 5, 0);
    var vcRotZ1      = new valAngel ('Angel Z',     6, 2, 3, 180, 5, 0);

    var OnApply      = 'SYS.Position';
};
RegisterMacro('Position', '3d through-pos');

control Rotate(x, y) {
    var Type         = "MACRO";
    var Title        = 'Rotate';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
//  var CallBefore   = new sel3dThrough(0, 0, 16);
    var vcRotX0      = new valAngel ('Angel X',     0, 1, 3, 180, 5, 0);
    var vcRotY0      = new valAngel ('Angel Y',     3, 1, 3, 180, 5, 0);
    var vcRotZ0      = new valAngel ('Angel Z',     6, 1, 3, 180, 5, 0);

    var OnApply      = 'SYS.Position';
};
RegisterMacro('Rotate', '3d through-pos');

control Translate(x, y) {
    var Type         = "MACRO";
    var Title        = 'Translate';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
//  var CallBefore   = new sel3dThrough(0, 0, 16);
    var vcOfsX0      = new valAny ('X-Position',      0, 0, 3,  -1, 1, 0.01,  0);
    var vcOfsY0      = new valAny ('Y-Position',      3, 0, 3,  -1, 1, 0.01,  0);
    var vcOfsZ0      = new valAny ('Z-Position',      6, 0, 3,  -1, 1, 0.01, -1);
    var vcOfsF0      = new valAny ('Position factor', 9, 0, 3,   0, 4, 0.01,  1);

    var OnApply      = 'SYS.Position';
};
RegisterMacro('Translate', '3d through-pos');

control Scale(x, y) {
    var Type         = "MACRO";
    var Title        = 'Scale';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
//  var CallBefore   = new sel3dThrough(0, 0, 16);
    var vcScaleX0    = new valAny ('X-Size',          0, 0, 3,  -1, 1, 0.01,  1);
    var vcScaleY0    = new valAny ('Y-Size',          3, 0, 3,  -1, 1, 0.01,  1);
    var vcScaleZ0    = new valAny ('Z-Size',          6, 0, 3,  -1, 1, 0.01,  1);
    var vcScaleF0    = new valAny ('Size factor',     9, 0, 3,   0, 4, 0.01,  1);

    var OnApply      = 'SYS.Position';
};
RegisterMacro('Scale', '3d through-pos');

control Curver(x, y) {
    var Type         = "MACRO";
    var Title        = 'Curver';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 3];
    var CallBefore   = new sel3dThrough( 0, 0, 16);
    var selCtSrc     = new selList     ('Counter',  6, 2, 6, 'Index|Position', 'Index');
    var vcAngelX     = new valAngel    ('Angel X',  0, 1, 3, 360, 5, 360);
    var vcAngelY     = new valAngel    ('Angel Y',  3, 1, 3, 360, 5, 360);
    var vcAngelZ     = new valAngel    ('Angel Z',  6, 1, 3, 360, 5, 0);
    var vcDecenter   = new valAny      ('Decenter', 9, 1, 3,   0, 8, 0.05, 2);
    var vcOfsX       = new valAngel    ('Offset X', 0, 2, 3, 180, 5, 0);
    var vcOfsY       = new valAngel    ('Offset Y', 3, 2, 3, 180, 5, 0);
    var OnApply      = 'SYS.Curver';
//    var __OnUpdatePlanePointwise= '
//pTranslate (_, 0, 1, 0);
//pRotateX   (_, AngelY.Get()/360 *_[3] + _[1]);
//pTranslate (_, 0, 0, -Decenter.Get());
//pRotateY   (_, AngelX.Get()/360*_[4]+_[0]); 
//';
//var tmp = AngelY.Get() *_[3] - _[1]; 
//pRotateX   (_, AngelY.Get()/360*_1[0]-_[0]); 
//pRotateY   (_, AngelX.Get()/360*_2[0]-_[1]); 
};
RegisterMacro('Curver', '3d through');

control Waves(x, y) {
    var Type         = "MACRO";
    var Title        = 'Waves';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
    var PosX         = 0;
    var PosY         = 0;
    var selCtSrc     = new selList    ('Counter',   0, 0, 6, 'Index|Position', 'Index');
    var ccColor      = new colorAnyHSV('Direction', 6, 0, 6, 1, 240, 255, 255);
    var vcShF        = new valAny     ('Factor',   12, 0, 3,  0.00, 2.0, 0.05, 0.25);
    var vcOfs        = new valAny     ('Offset',    0, 1, 3, -1.00, 1.0, 0.05, 0.0);
    var vcRing       = new valAny     ('Ring',      3, 1, 2.5,  0.00, 8.0, 0.1,  1.0);
    var vcForm       = new valAny     ('Form',      5.5, 1, 2.5, -4.00, 4.0, 0.1,  0.0);
    var vcEdge       = new valAny     ('Edge',      8, 1, 3,  0.25, 4.0, 0.05, 1.0);
    var OnApply      = 'SYS.Waves';
};
RegisterMacro('Waves', '3d through');

control Lines(x, y) {
    var Type         = "MACRO";
    var Title        = 'Lines';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
    var selCtSrc     = new selList     ('Counter',     0, 0, 6, 'Index|Position', 'Index');
    var ccColor      = new colorAnyHSV ('Direction',   6, 0, 6, 1, 240, 255, 255);
    var selMirror    = new selList     ('Mirror',      0, 1, 2, '-|X|Y|Both');
    var vcLiW        = new valAny      ('X-Scaling',   2, 1, 2,  0.00, 99.0, 1.0, 1.0);
    var vcLiH        = new valAny      ('Y-Scaling',   4, 1, 2,  0.00, 99.0, 1.0, 1.0);
    var vcEdge       = new valAny      ('Edge',        6, 1, 3,  0.25, 4.0, 0.05, 1.0);
    var vcLiF        = new valAny      ('Factor',     12, 0, 3,  0.00, 2.0, 0.05, 0.25);
    var OnApply      = 'SYS.Lines';
};
RegisterMacro('Lines', '3d through');

control Cutter(x, y) {
    var Type         = "MACRO";
    var Title        = 'Cutter';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
    var selMirror    = new selList ('Mirror',    0, 1, 2, 'X|Y|Z');
    var vcZMin       = new valAny  ('Limit 1',   3, 1, 3, -4.0, 4.0, 0.01, -0.5);
    var vcFMin       = new valAny  ('Limit 2',   6, 1, 4, -4.0, 4.0, 0.05,  0.0);
    var vcZMax       = new valAny  ('Factor 1', 10, 1, 3, -4.0, 4.0, 0.01,  0.5);
    var vcFMax       = new valAny  ('Factor 2', 13, 1, 4, -4.0, 4.0, 0.05,  0.0);
    var OnApply      = 'SYS.Cutter';
};
RegisterMacro('Cutter', '3d through');

control Power(x, y) {
    var Type         = "MACRO";
    var Title        = 'Power';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
    var vcX          = new valAny  ('X',       3, 1, 3, -1.0, 1.0, 0.05, 1.0);
    var vcY          = new valAny  ('Y',       6, 1, 4, -1.0, 1.0, 0.05, 1.0);
    var vcZ          = new valAny  ('Z',      10, 1, 3, -1.0, 1.0, 0.05, 1.0);
    var vcF          = new valAny  ('Factor', 13, 1, 4, -4.0, 4.0, 0.05, 1.0);
    var OnApply      = 'SYS.Power';
};
RegisterMacro('Power', '3d through');

control Flattern(x, y) {
    var Type         = "MACRO";
    var Title        = 'Flattern';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
    var vcX          = new valAny  ('X', 0, 1, 4,  0.0, 4.0, 0.05, 0.0);
    var vcY          = new valAny  ('Y', 4, 1, 4,  0.0, 4.0, 0.05, 0.0);
    var vcZ          = new valAny  ('Z', 8, 1, 4,  0.0, 4.0, 0.05, 0.0);
    var OnApply      = 'SYS.Flattern';
};
RegisterMacro('Flattern', '3d through');

control Light(x, y) {
    var Type         = "MACRO";
    var Title        = 'Light';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
    var ccBackground = new colorAnyHSV ('Diffuse',  0, 0, 6,   1,     0,   255,      0);
    var ccColor      = new colorAnyHSV ('Specular', 6, 0, 6,   1,   240,   255,    255);
    var vcX          = new valAny      ('Distance', 0, 1, 4,   0.0,   4.0,   0.05,   0.0);
    var vcRotX       = new valAngel    ('Angel X',  4, 1, 3, 180, 5,  0);
    var vcRotY       = new valAngel    ('Angel Y',  7, 1, 3, 180, 5,  0);
    var vcRotZ       = new valAngel    ('Angel Z', 10, 1, 3, 180, 5,  0);
    var pos          [0,0,0,0];
    var OnApply      = '
        ccColor      .UpdateRGB();
        ccBackground .UpdateRGB();
        pos          = [vcX.Get(),0,0,0];
        glEnable     (GL_LIGHTING);
        glEnable     (GL_LIGHT0);
	glPushMatrix ();
	//glTranslatef (1.0, 0, 0);
	glRotatef    (vcRotX.Get(), 1, 0, 0);
	glRotatef    (vcRotY.Get(), 0, 1, 0);
	glRotatef    (vcRotZ.Get(), 0, 0, 1);
	glLightfv    (GL_LIGHT0, GL_POSITION, pos);
        glPopMatrix  ();
        glLightfv    (GL_LIGHT0, GL_DIFFUSE,          ccBackground.Color);
        glLightfv    (GL_LIGHT0, GL_SPECULAR,         ccColor.Color);
';
};
RegisterMacro('Light', 'Light');

control TexMatrix(x, y) {
    var Type         = "MACRO";
    var Title        = 'Texture Matrix';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
    var Texture      = new selModule  ('Texture',    0, 0, 16, 'Shader|Texture|TexEnv|Renderer', 'Stock texture');
    var vcRotate     = new valAngel   ('Rotation',   0, 1, 3, 180, 5, 0);
    var vcOfsX       = new valAny     ('X-Offset',   3, 1, 3,  0.0,  1.0, 0.01, 0.0);
    var vcOfsY       = new valAny     ('Y-Offset',   6, 1, 3,  0.0,  1.0, 0.01, 0.0);
    var vcScaleX     = new valAny     ('X-Scaling',  9, 1, 3,  0.05, 4.0, 0.05, 1.0);
    var vcScaleY     = new valAny     ('Y-Scaling', 12, 1, 3,  0.05, 4.0, 0.05, 1.0);
    var OnApply      = '
        Texture.Apply();
        glMatrixMode    (GL_TEXTURE); 
        glLoadIdentity  (); 
        glTranslatef    (vcOfsX.Value+0.5, vcOfsY.Value+0.5, 0 );
        glScalef        (vcScaleX.Get(),   vcScaleY.Get(),   1 );
        glRotatef       (vcRotate.Get(),   0, 0,   1 );
        glTranslatef    (-0.5, -0.5, 0 );
        glMatrixMode    (GL_MODELVIEW); 
';
};
RegisterMacro('TexMatrix', 'TexEnv');


control BlendMode(x, y) {
    var Type         = "MACRO";
    var Title        = 'Blend Mode';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 3];
    var Texture      = new selModule   ('Texture',          0, 0, 16, 'Shader|Texture|TexEnv|Renderer', 'Stock texture');
    var selBlendMode = new selList     ('Blend mode',       0, 1,  9, 'Texture-mode');
    var ccColor      = new colorAnyHSV ('Color',            9, 1,  7, 1, 240, 255, 255);
    var selBlend1    = new selList     ('Source mode',      0, 2,  7, 'Blend Source');
    var selBlendFnc  = new selList     ('Blend function',   7, 2,  2, 'Blend Function');
    var selBlend2    = new selList     ('Destination mode', 9, 2,  7, 'Blend Destination');
    var OnApply      = '
        Texture      .Apply();
        ccColor      .UpdateRGB(); 
        glEnable     (GL_BLEND);
        glEnable     (GL_COLOR_MATERIAL);
        glEnable     (GL_LIGHTING);
        glEnable     (GL_LIGHT0);
        glBlendFunc  (selBlend1.Get(), selBlend1.Get());
        glBlendEquation (selBlendFnc.Get());
        glTexEnvf       (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,   selBlendMode->Get());
';
};
RegisterMacro('BlendMode', 'TexEnv');

control Text(x, y) : VisibleRows(1,1) {
    var Type         = "MACRO";
    var Title        = 'Text';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 3];
    var Buffer       = new Texture2d   ( 1, 1);
    var vcSync       = new valAny      ('1/96 Sync', 0, 0,  2, 0,  96,   1,   0);
    var selFont      = new selList     ('Font',      2, 0,  7, 'Arial|Comic Sans MS|Consolas|Courier New|Fixedsys|Gabriola|Georgia|Impact|Microsoft Sans Serif|Script|Segoe Print|Segoe Script|Small Fonts|System|Tahoma|Times New Roman');
    var vcSize       = new valAny      ('Size',      9, 0,  2, 7,  80,   1,  20);
    var ccColor      = new colorAnyHSV ('Color',    11, 0,  5, 1, 240, 255, 255);
    var edText       = new textEdit    ('',          0, 1, 16, 2, 'glLive3d');
    VisibleRows:var OnChange = 'caller.SetRows(VisibleRows:Get() * Step + Offset); caller.edText.SetRows(caller.VisibleRows:GetInt() * Step-1.35);';
    var OnDraw      = 'SYS.Text';
};
RegisterMacro('Text', 'Texture');

control Grabber(x, y) {
    var Type         = "MACRO";
    var Title        = 'Grabber';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 3];
    var vcSync       = new valAny     ('1/96 Sync',  0, 0,  2, 0,  96,   1,   0);
    var Display      = new anyDisplay ( 2, 0, 11, 3);
    var Width        = new valAny     ('Width',  13, 0,  3, 8, 2000, 8, 320);
    var Height       = new valAny     ('Height', 13, 1,  3, 8, 1500, 8, 200);
//    var Width        = new valAny     ('Width',  11, 0, 3, 8, 2000, 8, 1920);
//    var Height       = new valAny     ('Height', 11, 0, 3, 8, 1500, 8, 1024);
    var Buffer       = new Texture2d  (Width.Get(), Height.Get());
    var OnDraw      = 'SYS.Grab';
};
RegisterMacro('Grabber', 'Texture');

control TextureBank(x, y) : VisibleRows(1,1) : Texture4 (1) {
    var Type         = "MACRO";
    var Title        = 'Texture Bank';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
    var vcIdx        = new valAny    ('Selection',  2, 0,  2, 1,  4,   1,   1);
    VisibleRows:var OnChange = 'caller.SetRows(VisibleRows:Get() * Step + Offset); caller.vcIdx.SetRange(1,VisibleRows:Get() - 1 + Offset, 1);';
    var OnApply      = 'SYS.TexBank';
//var idx=vcIdx.Get();
//if      (idx==1)Texture1.Apply();
//else if (idx==2)Texture2.Apply();
//';
};
RegisterMacro('TextureBank', 'Texture');

control VertexMap(x, y)  : VisibleRows(1,1) {
    var Type         = "MACRO";
    var Title        = 'Vertex Map';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 3];
    var vcSync       = new valAny     ('1/96 Sync',      0,   0,  2,   0,  96,   1,     0);
    var vcInterpol   = new valAny     ('Interpolation',  2,   0,  2,   0,   1,   0.05,  0);
    var vcW          = new valAny     ('Width',          4,   0,  2.5, 1,  99,   1,    12);
    var vcH          = new valAny     ('Height',         6.5, 0,  2.5, 1,  99,   1,    12);
    var vcScaleX     = new valAny     ('X-Scaling',      9,   0,  2.5, 0,   4, 0.1,     1);
    var vcScaleY     = new valAny     ('X-Scaling',     11.5, 0,  2.5, 0,   4, 0.1,     1);
    var selCenter    = new selList    ('Center',        14,   0,  2,   ' -|X');
    var selFnc1      = new selModule  ('Function 1',     0,   1, 16,   '3d through|3d through-pos|Shader|Texture|TexEnv|Renderer', 'OFF');
    var selFnc2      = new selModule  ('Function 2',     0,   2, 16,   '3d through|3d through-pos|Shader|Texture|TexEnv|Renderer', 'OFF');
    var selFnc3      = new selModule  ('Function 3',     0,   3, 16,   '3d through|3d through-pos|Shader|Texture|TexEnv|Renderer', 'OFF');
    var selFnc4      = new selModule  ('Function 4',     0,   4, 16,   '3d through|3d through-pos|Shader|Texture|TexEnv|Renderer', 'OFF');

    var OnApply      = 'SYS.VertexMap';
};
RegisterMacro('VertexMap', 'Vertex source');

control VBO(x, y) {
    var Type         = "MACRO";
    var Title        = 'VBO';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 4];
    var vcSync       = new valAny     ('1/96 Sync',             0,   0,  2,   0,  96,   1,     0);
    var selDrawTB    = new selList    ('Top / bottom',          2,   0,  6,   'OFF|Top|Bottom|Both', 'Top');
    var selDrawSides = new selList    ('Sides',                 8,   0,  4,   'OFF|L---|--R-|L-R-|-B--|LB--|-BR-|LBR-|---F|L--F|--RF|L-RF|-B-F|LB-F|-BRF|LBRF', 'OFF');
    var selVertData  = new selList    ('Modulate',             12,   0,  4,   'OFF|Rotation|Scaling|Both', 'OFF');
    var selTopMode   = new selList    ('Top-mode',              0,   1,  4,   'Std|Flat|Normal', 'Std');
    var selRotMode   = new selList    ('Bottom-mode',           4,   1,  4,   'Std|Flat|Mirror|Mirr.Flat|Based', 'Std');
    var vcPrimScale  = new valAny     ('Primitive scaling',     8,   1,  3,   0,   2,   0.01,  1);
    var vcPrimRatio  = new valAny     ('Primitive X/Y-ratio',  11,   1,  3,  -1,   1,   0.01,  0);
    var vcPrimHeight = new valAny     ('Primitive height',     14,   1,  3,  -2,   2,   0.01,  0.2);
    var selCloseEnds = new selList    ('Close ends',            0,   2,  4,   'OFF|Top|Bottom|Both|Polygon:|Top|Bottom|Both', 'OFF');
    var selUseLights = new selList    ('Use lights',            4,   2,  2,   ' -| X', ' -');
    var selSmooth    = new selList    ('Smooth',                6,   2,  2,   ' -| X', ' -');
    var selTexSize   = new selList    ('Texture scaling',       8,   2,  4,   'Full object|Per primitive', 'Full object');
    var selDrawType  = new selList    ('Primitive type',       12,   2,  4,   'Draw type');
    var selMap       = new selModule  ('Vertex map',            0,   3, 16,   'Vertex source|Texture|Renderer', 'VertexMap');

    var OnApply      = 'SYS.VBO';
};
RegisterMacro('VBO', 'VBO');

control Object(x, y) {
    var Type         = "MACRO";
    var Title        = 'Object';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 5];
    var vcSync       = new valAny      ('1/96 Sync',    0,   0,  2,   0,  96,   1,     0);
    var selLevel     = new selList     ('Depth level',  2,   0,  7,   'Macro|Foreground|Background|Lanscape|Infinity', 'Foreground');
    var vcScale      = new valAny      ('Size',         9,   0,  3,   0,   4,   0.01,  1);
    var ccColor      = new colorAnyHSV ('Material',     0,   1,  6, 1, 210, 64, 255);
    var vcLight      = new valAny      ('Light',        6,   1,  3,   0,   1,   0.05,  0.5);
    var vcEdge       = new valAny      ('Edge',         9,   1,  3,   0,   1,   0.05,  0.8);
    var selTexture   = new selModule   ('Texture',      0,   2, 16,   'Shader|Texture|TexEnv|Renderer', 'Stock texture');
    var selVBO       = new selModule   ('VBO',          0,   3, 16,   'VBO', 'VBO');
    var selPosition  = new selModule   ('Position',     0,   4, 16,   'Position|3d through-pos', 'Position');

    var OnApply      = 'SYS.Object';
};
RegisterMacro('Object', 'Objects');

control Layer(x, y) : VisibleRows(1,5) {
    var Type         = "MACRO";
    var Title        = 'Layer';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 6];
    var vcSync       = new valAny      ('1/96 Sync',          0,   0,  2,   0,    96,    1,     0   );
    var selTexMode   = new selList     ('Texture-mode',       2,   0,  4,   'Texture-mode',      'Decal');
    var selBlendSrc  = new selList     ('Blend-source',       6,   0,  5,   'Blend Source',      'One');
    var selBlendDst  = new selList     ('Blend-destination', 11,   0,  5,   'Blend Destination', 'Zero');
    var ccSky        = new colorAnyHSV ('Sky',                0,   1,  6,   1,   240,   255,    0   );
    var ccGround     = new colorAnyHSV ('Ground',             6,   1,  6,   1,   240,   255,    0   );
    var selCutting   = new selList     ('Cutting',           12,   1,  2,   ' -| X', ' -');
    var ccAmbient    = new colorAnyHSV ('Ambient',            0,   2,  6,   1,     0,     0,   32   );
    var ccFogColor   = new colorAnyHSV ('Fog',                6,   2,  6,   1,   240,   255,    0   );
    var vcFog        = new valAny      ('Fog density',       12,   2,  3,   0,     4,     0.1, 0   );
    var selPosition  = new selModule   ('Position',           0,   3, 16,   'Position|3d through-pos', 'Position');
    var selLight     = new selModule   ('Light',              0,   4, 16,   'Light',   'Light');
    var selObj0      = new selModule   ('Object 1',           0,   5, 16,   'Objects', 'Object');
    var selObj1      = new selModule   ('Object 2',           0,   6, 16,   'Objects', 'OFF');
    var selObj2      = new selModule   ('Object 3',           0,   7, 16,   'Objects', 'OFF');
    var selObj3      = new selModule   ('Object 4',           0,   8, 16,   'Objects', 'OFF');

    var OnApply      = 'SYS.Layer';

    var ______OnApply      = '
        ccSky.updateRGB();            ccGround.updateRGB();           ccAmbient.updateRGB();        ccFogColor.updateRGB();

        selPosition     .Apply();

        glEnable        (GL_DEPTH_TEST);                                        
        glShadeModel    (GL_SMOOTH);
        glEnable        (GL_DITHER);        
        glEnable        (GL_FOG);
    
        glFogf          (FOG_DENSITY, vcFog.Value/10); glFogf(FOG_COLOR, ccFog.rgb);

        glPushMatrix    ();
        glScalef        (10, 10, 10);
';
};
RegisterMacro('Layer', 'Layer');


control SeqMap(x, y) {
    var Type         = "MACRO";
    var Title        = 'Sequence Map';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
    var vcSync       = new valAny     ('1/96 Sync',      0,   0,  2.5, 0,    96,   1,   12);
    var vcInterpol   = new valAny     ('Interpolation',  2.5, 0,  2.5, 0,     1,   0.1,  0.4);
    var vcFakt       = new valAny     ('Scaling',        5,   0,  3,   0.25,  2,   0.05, 1.5);
    var selTexture   = new selModule  ('Source',         8,   0,  8,   'Shader|Texture|TexEnv|Renderer', 'Stock texture');
    var vcPosX       = new valAny     ('X-Position',     0,   1,  4,   0,     1,   0.01, 1.5);
    var vcPosY       = new valAny     ('Y-Position',     4,   1,  4,   0,     1,   0.01, 1.5);
    var Scope        = new anyScope   ( 8,   1,  8,   1);

    var vcRet0       = new valAny     ('Red',    0,   0,  0,   0,     1);
    var vcRet1       = new valAny     ('Green',  0,   0,  0,   0,     1);
    var vcRet2       = new valAny     ('Blue',   0,   0,  0,   0,     1);

    var OnNext       = 'SYS.SeqMap';
};
RegisterMacro('SeqMap', 'Function');

control Render3D(x, y) : VisibleRows(1,4) {
    var Type         = "MACRO";
    var Title        = 'Render 3d';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 5];
//  var vcSync       = new valAny     ('1/96 Sync',   0,   0,  2,      0,    96,   1,   12);
    var vcAngel      = new valAny     ('Angel',       0,   0,  3,     15,   135,   5,   90);
    var vcRotX       = new valAny     ('X-Rotation',  3,   0,  3,   -180,   180,   5,    0);
    var vcRotY       = new valAny     ('Y-Rotation',  6,   0,  3,   -180,   180,   5,    0);
    var vcRotZ       = new valAny     ('Z-Rotation',  9,   0,  3,   -180,   180,   5,    0);
    var Display      = new anyDisplay ( 0,   1, 12,      3.5);
    var vcWidth      = new valAny     ('Width',      12,   1,  3.5,  320,  2048,   8, 1280);
    var vcHeight     = new valAny     ('Height',     12,   2,  3.5,  200,  2048,   8,  800);
    var Buffer       = new Texture2d  (vcWidth.Get(), vcHeight.Get());
    var selLayer0    = new selModule  ('Layer 1',     0,   4, 16,   'Layer', 'Layer');
    var selLayer1    = new selModule  ('Layer 2',     0,   5, 16,   'Layer', 'OFF');
    var selLayer2    = new selModule  ('Layer 3',     0,   6, 16,   'Layer', 'OFF');
    var selLayer3    = new selModule  ('Layer 4',     0,   7, 16,   'Layer', 'OFF');

    var OnDraw       = 'SYS.3D';
};
RegisterMacro('Render3D', 'Renderer');

control Render2D(x, y) : SimShader(0,0,2) {
    var Type         = "MACRO";
    var Title        = 'Render 2D';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 4];
//    var Display      = new anyDisplay ( 2,   0, 10,      2.5);
//    var vcWidth      = new valAny     ('Width',      12,   0,  3.5,    1,  2048,   1,   24);
//    var vcHeight     = new valAny     ('Height',     12,   1,  3.5,    1,  2048,   1,   24);
    var Buffer       = new DisplayedTexture2d();
//    vcWidth: var OnChange = 'caller:Buffer:var Size[caller.vcWidth.Get(), caller.vcHeight.Get()];';
//    vcHeight:var OnChange = 'caller:Buffer:var Size[caller.vcWidth.Get(), caller.vcHeight.Get()];';
    var OnDraw       = 'SYS.2D';
};
RegisterMacro('Render2D', 'Renderer');

control TexFromMap(x, y) {
    var Type         = "MACRO";
    var Title        = 'Tex fr. Map';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 4];
    var Buffer       = new Texture2d   (1, 1);
    var selMapSrc    = new selModule   ('Source',     0,   0, 16,   'Vertex source|3d through|3d through-pos', 'VertexMap');
    var vcSync       = new valAny      ('1/96 Sync',  0,   1,  2.5, 0,    96,   1,   12);
    var selCtSrc     = new selList     ('Counter',    2.5, 1, 6, 'Position|Rotation|Normals', 'Position');
    var ccColor      = new colorAnyHSV ('Direction',  8.5, 1, 6, 1, 240, 255, 255);
    var Display      = new anyDisplay  ( 0,   2, 14,  2.3);

    var OnDraw       = 'SYS.TexFromMap';
};
RegisterMacro('TexFromMap', 'Renderer');

control ImageFile(x, y, File = "") {
    var Type         = "MACRO";
    var Title        = 'Image-file';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
//    var Buffer = new Texture2d(1,1);

    var Display      = new texStatic   ( 0,   0, 12,  2.3);
};
RegisterMacro('ImageFile', 'Texture');

control MidiIn_1(x, y) {
    var Type         = "MACRO";
    var Title        = 'Midi in';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 5];
    var vcSync       = new valAny     ('1/96 Sync',  0,   0,  2,   0,  96,   1,     0);
    var selLevel     = new selList    ('Level',      2,   0,  7,   'Macro|Foreground|Background|Lanscape|Infinity', 'Foreground');
    var vcScale      = new valAny     ('Scaling',    9,   0,  3,   0,   4,   0.01,  1);
    var selPosition  = new selModule  ('Position',   0,   1, 16,   'Position|3d through-pos', 'Position_1');

//    var OnApply      = 'SYS.Object';
};
//RegisterMacro('MidiIn_1', 'Midi');

control ShaderTexture(x, y) : VisibleRows(2,0) {
    var Type         = "MACRO";
    var Title        = 'Shader texture 4';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
    var Ctrls1       = new selModule  ('Texture 1',  0,   0, 16,   'Shader-control|Shader|Texture|TexEnv|Renderer', 'Stock texture');
    var Ctrls2       = new selModule  ('Texture 2',  0,   1, 16,   'Shader-control|Shader|Texture|TexEnv|Renderer', 'OFF');
    var Ctrls3       = new selModule  ('Texture 3',  0,   2, 16,   'Shader-control|Shader|Texture|TexEnv|Renderer', 'OFF');
    var Ctrls4       = new selModule  ('Texture 4',  0,   3, 16,   'Shader-control|Shader|Texture|TexEnv|Renderer', 'OFF');

    var OnApply      = 'Ctrls1.Apply(); Ctrls2.Apply(); Ctrls3.Apply(); Ctrls4.Apply();';
};
RegisterMacro('ShaderTexture', 'Shader-control');


control MapDisplay(x, y) : VisibleRows(1,4) {
    var Type         = "MACRO";
    var Title        = 'Render 3d';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 3];
    var Display      = new anyDisplay ( 0,   0, 16,      3.5);

    var OnDraw       = 'SYS.Mesh';
    var OnApply      = 'SYS.Mesh';
};

RegisterMacro('MapDisplay', '3d through');



// REIHENFOLGE BEACTEN: Function_2 vorübergehend zuert  
control Function_2(x,y) {
    var Type         = "MACRO";
    var Title        = 'Function';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 1];
    var selFnc       = new selList    ('Function', 0,   0,  6,   'Counter|Sin', 'Sin');
    var v1           = new valAny     ('v1',       6,   0,  3,   0,     1,   0.01, 1.5);
    var v2           = new valAny     ('v2',       9,   0,  3,   0,     1,   0.01, 1.5);
    var Scope        = new anyScope   (                 12,   0,  4,   1);
    var Out          = "vcRet0";
    var vcRet0       = new valAny     ('Out 1',    0,   0,  0,   0,     1);
    var vcRet1       = new valAny     ('Out 2',    0,   0,  0,   0,     1);
    var vcRet2       = new valAny     ('Out 3',    0,   0,  0,   0,     1);
    var fnc          = 0;
    var OnNext       = 'fnc = selFnc.GetInt();
        if      (fnc == 0) { vcRet0.Value = mod(bCT * v1.Value }
        else if (fnc == 1) { vcRet0.Value = sin(bCT * v2.Value); };
';
};
RegisterMacro('Function_2', 'Function');

function Function_1(f_Title, y, Type) {
    var selFnc       = new selList    ("Function "+y,      0,   0+y,  5,   'OFF|Counter|ISin|ICubic|BEAT:|Linear|Sin|Cubic|Fakult.|STATIC:|Scale|SCubic|Manuel', Type);
    selFnc:var OnChange = 'caller.vcRet1.SetTitle(selFnc:GetString());';
//  var Fnc          = new lineEdit   ('Function', 0,   2,  6,   1,     'Out1 = sin(bCT * v2.Value);');
//    var fnc          = 0;
    var fnc          = 0;
    var IntCT        = 0;
    var Val1         = 0.2;
    var Val2         = 0;
    var Val3         = 1;
    var v1           = new valAny     ('v1',       5,   0+y,  3,   0,     1,   0.01, Val1);
    var v2           = new valAny     ('v2',       8,   0+y,  3,   0,     1,   0.01, Val2);
    var v3           = new valAny     ('v3',      11,   0+y,  3,   0,     1,   0.01, Val3);
    var Scope        = new anyScope   (           14,   0+y,  2,   1);
    var Out          = 'vcRet1';
    var Out1         = 0;
    var Out2         = 0;
    var Out3         = 0;
    var vcRet1       = new valAny     (Type,    0,   0+y,  0,   0,     1,   0, Out1);
    var vcRet2       = new valAny     ('Out 2',    0,   0+y,  0,   0,     1,   0, Out2);
    var vcRet3       = new valAny     ('Out 3',    0,   0+y,  0,   0,     1,   0, Out3);

    var Intern       = 'IntCT = IntCT + 0.036; Out1 = scale01(mod  (IntCT * v1.Get() + v2.Get(), 1), v3.Get());';
    var ISin         = 'IntCT = IntCT + 0.036; Out1 = scale01(sin01(IntCT * v1.Get() + v2.Get()), v3.Get());';
    var ICubic       = 'IntCT = IntCT + 0.036; Out1 = scale01(pow01(mirror01(IntCT * 2 * v1.Get()), v2.Get()*v2.Get()*v2.Get()*8), v3.Get());';
    var Linear       = 'IntCT = 0 + bCT;       Out1 = scale01(mod  (IntCT * v1.Get() + v2.Get(), 1), v3.Get());';
    var Sin          = 'IntCT = 0 + bCT;       Out1 = scale01(sin01(IntCT * v1.Get() + v2.Get()), v3.Get());';
    var Cubic        = 'IntCT = 0 + bCT;       Out1 = scale01(pow01(mirror01(IntCT * 2 * v1.Get()), v2.Get()*v2.Get()*v2.Get()*8), v3.Get());';
//    var SModulate    = '                       Out1 = pow(v1.Get() * v2.Get(), 0.5)';
    var SCubic       = '                       Out1 = scale01(pow01(v1.Get(), v2.Get()*v2.Get()*v2.Get()*8), v3.Get());';

    var _OnNext      = 'fnc = selFnc.GetInt(); 
        if      (fnc ==  0) { return 0;        }
        else if (fnc ==  1) { eval(Intern);    }
        else if (fnc ==  2) { eval(ISin);      }
        else if (fnc ==  3) { eval(ICubic);    }
        else if (fnc ==  5) { eval(Linear);    }
        else if (fnc ==  6) { eval(Sin);       }
        else if (fnc ==  7) { eval(Cubic);     }
        else if (fnc ==  8) { Out1 = pow01(Val1, mod((0+bCT) * Val2,1)*2);    }
        else if (fnc == 10) { Out1 = scale01(v1.Get(),v2.Get());  }
        else if (fnc == 11) { eval(SCubic);    };
        Scope.Next(caller.Out1);
';
};


control Functions(x,y) : VisibleRows(2,0,16,1.4,0,1,6) {
    var Type         = "MACRO";
    var Title        = 'Function List';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
    var Rows         = 2;
    var OnCreate     = '
        var Fnc1     = new Function_1("Function 1",0,"Beat");
        var Fnc2     = new Function_1("Function 2",1,"Sin");
        var Fnc3     = new Function_1("Function 3",2);
        var Fnc4     = new Function_1("Function 4",3);
        var Fnc5     = new Function_1("Function 5",4);
        var Fnc6     = new Function_1("Function 6",5);
';
    var OnNext       ='Rows = VisibleRows.GetInt();
        Fnc1.eval(_OnNext);
        if(Rows>1){Fnc2.eval(_OnNext);
        if(Rows>2){Fnc3.eval(_OnNext);
        if(Rows>3){Fnc4.eval(_OnNext);
        if(Rows>4){Fnc5.eval(_OnNext);
        if(Rows>5){Fnc6.eval(_OnNext);};};};};};
';
    var Out          = 'Fnc1.vcRet1|Fnc2.vcRet1|Fnc3.vcRet1|Fnc4.vcRet1|Fnc5.vcRet1|Fnc6.vcRet1';
};

RegisterMacro('Functions', 'Function');


function Color_1(f_Title, y, Type) {
    var Color        = new selList    ('Color '+y,  0,   0+y,  3,   'RGB|HSV', 'HSV');
    var v1           = new valAny     ('v1',        3,   0+y,  3,   0,   255,   1,  171);
    var v2           = new valAny     ('v2',        6,   0+y,  3,   0,   255,   1,  255);
    var v3           = new valAny     ('v3',        9,   0+y,  3,   0,   255,   1,  255);
    var fnc          = 0;
    var R            = 0;    var G          = 0;    var B            = 0;
    var H            = 0;    var S          = 0;    var V            = 0;   
    var i            = 0;    var f          = 0;    var p            = 0;
    var q            = 0;    var t          = 0;    var m            = 0;
    var _OnNext       = 'fnc = Color.GetInt();
        if      (fnc == 0) { R = v1.Get01(); G = v2.Get01(); B = v3.Get01();  }
        else if (fnc == 1) { H = v1.Get01(); S = v2.Get01(); V = v3.Get01();
            i  = floor(6 * H);             f  = 6 * H - i;         p  = (1 - S) * V; 
            q  = (1 - f * S) * V;          t  = (1 - (1 - f) * S) * V;
            if      (i < 1) {R = V; G = t; B = p; m=1;}
            else if (i < 2) {R = q; G = V; B = p; m=1;}
            else if (i < 3) {R = p; B = t; G = V; m=1;}
            else if (i < 4) {R = p; B = V; G = q; m=1;}
            else if (i < 5) {R = t; B = V; G = p; m=1;}
            else if (i <=6) {R = V; G = p; B = q; m=1;};
        };
        Color.SetColor(caller.R, caller.G, caller.B);
';
};

control Colors(x,y) : VisibleRows(2,0,16,1.4,0,1,6) {
    var Type         = "MACRO";
    var Title        = 'Color bank';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
    var Rows         = 2;
    var OnCreate     = '
        var Fnc1     = new Color_1("Function 1",0,"HSV");
        var Fnc2     = new Color_1("Function 2",1,"HSV");
        var Fnc3     = new Color_1("Function 3",2);
        var Fnc4     = new Color_1("Function 4",3);
        var Fnc5     = new Color_1("Function 5",4);
        var Fnc6     = new Color_1("Function 6",5);
';
    var OnNext       ='Rows = VisibleRows.GetInt();
        Fnc1.eval(_OnNext);
        if(Rows>1){Fnc2.eval(_OnNext);
        if(Rows>2){Fnc3.eval(_OnNext);
        if(Rows>3){Fnc4.eval(_OnNext);
        if(Rows>4){Fnc5.eval(_OnNext);
        if(Rows>5){Fnc6.eval(_OnNext);};};};};};
';
    var Out          = 'Fnc1|Fnc2|Fnc3|Fnc4|Fnc5|Fnc6';
};
RegisterMacro('Colors', 'Function');

control Screen(x,y) {
    var Type         = "MACRO";
    var Title        = 'Screen';
    var Flags        = '_MD_PG_ACTIVE|_MD_BUTTONS_ALL|_MD_BT_EDIT';    
    var Position     [x, y];
    var Size         [1, 2];
    var Output       = new outScreen(0,0);
    var selSrc       = new selModule  ('Source',  0,   0, 16,   'Renderer|Texture|TexEnv|Shader', 'Render3D');
selSrc:var OnChange = 'caller.Output.Link = caller.selSrc.GetString();';

//var OnDraw='SYS.Screen';
var OnDraw='selSrc.Apply();Output.Refresh();';
};
RegisterMacro('Screen', 'Renderer');

5. After runnung the application various event will cause the clsParser-instances to execute some script-code
6. Also a startable and stopable wxTimer will cause the clsParser-instances to execute some code. This timer is used for OpenGL-rendering. So it normally runs with 60Hz. This is important while my problem only appears if the timer is running.


Now...
In the c-code of clsParser are a lot of nested calls like this:

Code: Select all

ParseLiteral(num1, SRC);
where the function-name may be different but the parameters are the same. "num1" (sorry for the wrong name - it may also conain char*) are clsVar-object-references (=>2) and SRC is a char*& to currectly interpreted position in the script.
Summarized the c-code, where the problem appears is the following:

Code: Select all

clsVar &clsParser::ParseAtom(clsVar& num1, char*& SRC) {          
    [...]
    if      (*SRC == '-' || (*SRC >= '0' && *SRC <= '9'))   num1 = strtod(SRC, &SRC);             
    else if (SRC[0] == '[') {                               
        [...]
    }
    else if (SRC[0] == '(') {                              
        [...]
    }
    else                                                     ParseLiteral(num1, SRC);                                                       
    [...]
}
and

Code: Select all

clsVar &clsParser::ParseLiteral(clsVar& num1, char*& SRC) {
    [...]
}
When i call wxMessageBox (or any common dialog) in the first functuion the message-box is displayed normally in any case. Even this line works:

Code: Select all

    [...]
    else      {   wxMessgaeBox("1");    ParseLiteral(num1, SRC);      wxMessgaeBox("2");         }
    [...]

In the second function a wxMessageBox-call immideately crashes the program if the timer (=>6) is running. If not, also they work fine.

For explaination:
If i use three wxMessaheBox-calls (one before and after the call of "ParseLiteral(num1, SRC);" and one as first line in ParseLiteral, three message-boxes are displayed if the time (=>6) is stopped. If the timer is running, the first wxMessageBox is diplayed while any script which is called by the timer is still executed normally. The timer runs and scripts are executed even while the wxMessageBox is visible, but the second wxMessageBox crashes the program before it is diplayed.

This seems to be very strange: wxMessageBox calles from anywhere in ParseLiteral and any other function called from there, lead to crashes, while calls of wxMessageBox directly before and after ParseLiteral are working. And even more strange: everything works fine while the timer is not running.



Is there anyone who has an idea, where to look what the problem might be?


Best,
Frank
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Strange common-dialog-crashes

Post by doublemax »

Just some general remarks / hints:

if you can't use a debugger, cluster your code with non-intrusive wxLogDebug(...) outputs. It should give you a good idea about the program flow before the crash.

You said you're rendering inside the timer event. Do you actually render (which would probably be bad) or just call Refresh()? Do you make any changes to any data structures in the timer event? Especially, can it be that the pointers that are passed to ParseLiteral() somehow become invalid?

Try what happens if you leave the timer running, but don't do anything inside. If it doesn't crash then, add code piece by piece until you find the code that causes the crash.
Use the source, Luke!
art-ganseforth
Earned some good credits
Earned some good credits
Posts: 147
Joined: Mon Sep 01, 2014 10:14 am

Re: Strange common-dialog-crashes

Post by art-ganseforth »

Thank you. This are some intrestring ideas. (I already kow yoe as an excelent professional...)

Concerning:
Do you actually render (which would probably be bad) or just call Refresh()?
I use a OpenGL-FBOs (textures for GTX-internal rendering) and wxGLCanvas as displays, which are not only refreshd but simply renderd 2d from existing and internally rendered frames. It's a quiet complex logistic which works very good (as long as i do not call dialogs in the specified situation).
Why i'm irritated is especiially, that if one thread of clsParser (called by a user-event) which is interrupted by a mwxMessageBox-call, and another one, called by wxTimer are working good as long as the wxMessageBox is called before calling ParseLiteral() or after returning from it, while not anything is done in between.
The script which shoud be interpreted is:

Code: Select all

    var OnRightUp    = '
        caller:var File=OpenFileDialog(File, "Open Image-file", "JPEG files (*.jpg;*.jpeg)|*.jpg;*.jpeg|BMP and GIF files (*.bmp;*.gif)|*.bmp;*.gif|PNG files (*.png)|*.png");
        caller:Buffer:Set(File);Refresh();
'; 
Currently i blocked everything which i do not need for testing. When entering ParseLiteral(), *SRC points on the first char of "OpenFileDialog" and num1 refers to the clsVar-instance where the result shoud be stored in. Inside of ParseLiteral() nothing is done. Only wxMessageBox(""); is called to test and *SRC is move to the ')' character following "*.png".

I'm not sure i explaind it really good. The point is that i do the following:
1. last call outside ParseLiteral() is a wxMessageBox-call
2. ParseLiteral() is called by "ParseLiteral(num1, SRC);" - so no implicit changes are done on the parameters num1 & SRC while calling ParseLiteral()
3. fist call inside ParseLiteral() is a wxMessageBox-call. Here appears the problem - but only if the timer is running.
4. Between (1) and (3) only system-things (call-stack) are done and things in wxMessageBox.

Therefore i'm wondereing what is happening there. It might be a general pointer-problem but this normally sholud not lead to more unspecific crashes. After some changes in the source and recompiling, i would expect that the crashes appear in different situations, if it woud be a general pointer-problem. But they don't. They exactly appear when i call a dialog. Also a sleep-call i tested instead of a dialog works. The idea was to check what happens if the clsParser-thred is interrupted by other things then a request or user-action. In any tested case the program works.

Concerning:
Try what happens if you leave the timer running, but don't do anything inside. If it doesn't crash then, add code piece by piece until you find the code that causes the crash.
This i will find out now. It's a good idea. I'll also try to integrate the problematic parts of ParseLiteral() into the upper function ParseAtom().

Concerning debugging: i have a more general problem. I'm (i think so) good in coding. That's all. Setting up an IDE or configuring a compiler/makeile?? Puh!!! Where i can't use prepared configurations, it's a trail and error thing for me to find the correct coniguration. Debugging is one o the thngs i never lerned...



Best,
Frank


EDIT: I'll give report after testig...
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Strange common-dialog-crashes

Post by doublemax »

...if one thread of clsParser...
Are there any secondary threads involved?

Do you at least use a debug build of wxWidgets and your code? Maybe the crash is an assert which tells you exactly what's wrong.

BTW: What platform and compiler are you using?
Concerning debugging: i have a more general problem. I'm (i think so) good in coding. That's all. Setting up an IDE or configuring a compiler/makeile?? Puh!!!
So you're not using any IDE? Just a text editor and command line compiler?

Even then, there should be tutorials for debugging. First step is to use a debug build for your application and then run the application under a debugger. If you're lucky, the exact code line where the crash happens will already give you a hint about the cause.
Use the source, Luke!
art-ganseforth
Earned some good credits
Earned some good credits
Posts: 147
Joined: Mon Sep 01, 2014 10:14 am

Re: Strange common-dialog-crashes

Post by art-ganseforth »

While answering and testing lots of your hints (think i first time started a debugger, which had helped with another problem, but which is obviously buggy itself - as some web-posts say) i found the problem like i always find them - with "intelligent" tests...

By testing a non-modal dialog and a GetPopupMenuSelectionFromUser()-call i found out, that the reason for the crash is that the script-execution is interrupted at this point, and not because of showing a dialog-window. I also already knew that the crash does not appear before a specific point in the execution.
Therefore i found out, that the timer-script acesses a pointer which is already in use or later updating from the script startet by the user-event. This is a problem of how strings are processed by the interpreter. For floats i have a working reference-counter, but not for strings. So, if a string-variable is in use, it can't be acessed a second time. The simple solution is, to change the script, on a way that the result of OpenFileDialog() is stored in a temporary variable. After the dialog is closed, the result is written from the temporary variable to the real destination. By this, the real destination is not "blocked" while the dialog is shown.
Thereore the script-line:

Code: Select all

caller:File=OpenFileDialog(File, "Open Image-file", "JPEG files (*.jpg;*.jpeg)|*.jpg;*.jpeg|BMP and GIF files (*.bmp;*.gif)|*.bmp;*.gif|PNG files (*.png)|*.png");
blocks the variable "File", which can't be accessed in between. (I admit that i until now don't exactly know why this "blocking" happens).

Fact is: the program works if i change the script like this:

Code: Select all

var File=OpenFileDialog(caller.File, "Open Image-file", "JPEG files (*.jpg;*.jpeg)|*.jpg;*.jpeg|BMP and GIF files (*.bmp;*.gif)|*.bmp;*.gif|PNG files (*.png)|*.png");
        caller:File=Display.File;
Like this inside of the "object" called "Display" (which is an instance of clsParser that had been run by the user-event and which is representing a wxGLCanvas-control) a variable named "File" is written by the OpenFileDialog-result, which afterards is copied to the variable named "File" in the parent-object ("caller:") after closing the dialog. (The syntax is a little bit strange, but "caller:" will redirect the execution of the following term until ';' to the parent clsParser-object. From there the variable "File" in the child-object called "Display" is accessed by "Display.File"), which is used as temporary variable.

Anyway: Thanks a lot for your support! I first time tried unsed a debugger and found a bug im my program with it. Also this might help later with another unresolved problem which i have with a crashing OpenGL-call.


Best,
Frank
art-ganseforth
Earned some good credits
Earned some good credits
Posts: 147
Joined: Mon Sep 01, 2014 10:14 am

Re: Strange common-dialog-crashes

Post by art-ganseforth »

Hmmm...
Since i removed all testing-functions is again works NOT.

Further analysation follows...
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Strange common-dialog-crashes

Post by doublemax »

By testing a non-modal dialog and a GetPopupMenuSelectionFromUser()-call i found out, that the reason for the crash is that the script-execution is interrupted at this point
I don't see how that is even possible, even if secondary threads were involved. How exactly does the script interpreter work?
Use the source, Luke!
Post Reply