Hello all,

This is my first time posting on this forum. I have been having a peculiar problem on my TI-84 Plus CE regarding C++ programs. I am trying to create simple 3D graphics for a game I am working on, but the calculator is crashing when I attempt to run the program The code compiles without errors or warnings on the latest CE Toolchain.

My code is below:

main.cpp:

Code:
//#include <iostream>
#include <tice.h>
#include <graphx.h>

struct point2
{
    int x;
    int y;
};

struct point3
{
    int x;
    int y;
    float z;
};

typedef point2 point2;
typedef point3 point3;

point2 p2from3(point3 p3_1);

class face3
{
public:
    point3 p3_1;
    point3 p3_2;
    point3 p3_3;
    point3 p3_4;

    point2 p2_1 = p2from3(p3_1);
    point2 p2_2 = p2from3(p3_2); // converting 3D points to 2D screen positions
    point2 p2_3 = p2from3(p3_3);
    point2 p2_4 = p2from3(p3_4);

    void draw()
    {

        // gfx_FillTriangle(p2_1.x, p2_1.y, p2_2.x, p2_2.y, p2_3.x, p2_3.y); // 2 triangle generation
        // gfx_FillTriangle(p2_2.x, p2_2.y, p2_3.x, p2_3.y, p2_4.x, p2_4.y);

        gfx_Line(p2_1.x, p2_1.y, p2_2.x, p2_2.y); // drawing lines in the shape of the face outline
        gfx_Line(p2_2.x, p2_2.y, p2_3.x, p2_3.y);
        gfx_Line(p2_3.x, p2_3.y, p2_4.x, p2_4.y);
        gfx_Line(p2_1.x, p2_1.y, p2_4.x, p2_4.y);
    }
};

int main()
{
    gfx_Begin();

    face3 plate;

    plate.p3_1.x = 50;
    plate.p3_1.y = 100;
    plate.p3_1.z = 2;
    plate.p3_2.x = 120;
    plate.p3_2.y = 100;
    plate.p3_2.z = 2;
    plate.p3_3.x = 120;   // setting position and dimensions of the face "plate"
    plate.p3_3.y = 120;
    plate.p3_3.z = 1;
    plate.p3_4.x = 100;
    plate.p3_4.y = 120;
    plate.p3_4.z = 1;

    plate.draw();

    gfx_Line(0, 0, 100, 200); // this line is drawn correctly, interestingly
    while (!os_GetCSC())
    {
    }
    gfx_End();

    return 0;
}

point2 p2from3(point3 p3_1)
{
    point2 p2_1;
    p2_1.x = ((p3_1.x - 160) / p3_1.z) + 160;
    p2_1.y = ((p3_1.x - 120) / p3_1.z) + 120;
    return p2_1;
}


The calculator crashes when I run this program through Asmhook or Cesium. The line from (0, 0) to (100, 200) is drawn correctly, but the lines that I am trying to draw are not working. After I trigger GetCSC() to exit the program, the calculator goes entirely blank for about five seconds and then reboots, showing the "Validating OS" message. I have verified the line positions, and they are all within the screen's boundaries. I have also compiled all the non-graphical parts of the code on GCC, and they work as intended. Does anyone know why this may be happening?

Thank you,

srupuduflupudu
Install nightly for the latest bugfixes.
Not sure why you are trying to include iostream, the internet is telling me that's designed for C++, but hey, you do you.

Code:
//#include <iostream>


Assuming that's the entire code, I think your problem might be that you are missing this header.

Code:
#include <keypadc.h>

And so, the calculator is crashing because it didn't know to load the library for which key input is even registered...
greenturtle537 wrote:
Not sure why you are trying to include iostream, the internet is telling me that's designed for C++, but hey, you do you.

Code:
//#include <iostream>

This is C++. That being said, the iostream header is part of the C++ stdlib, which isn't available with the CE toolchain.

greenturtle537 wrote:
Assuming that's the entire code, I think your problem might be that you are missing this header.

Code:
#include <keypadc.h>

And so, the calculator is crashing because it didn't know to load the library for which key input is even registered...

What?
Missing the header would cause a compiler error, not a runtime crash. The header file has nothing to do with library loading. But it's not even required in this case, they're not using any of the keypadc functions or defines.

Like jacobly said, using the latest nightly build should fix the issue.
Using the latest nightly build prevents it from crashing, but it still doesn't work correctly. All the lines are being drawn from the point (0, 0) now. I am not including <iostream>; that is in a comment, as I was testing the code on my computer first. Thank you for the help so far.
Okay, so there is a new problem: the same code behaves differently each time it is run. sometimes it draws three or four lines, sometimes one, and sometimes none at all. Any ideas on what may be happening?
srupuduflupudu wrote:
Okay, so there is a new problem: the same code behaves differently each time it is run. sometimes it draws three or four lines, sometimes one, and sometimes none at all. Any ideas on what may be happening?


It's probably just compiler bugs producing bad assembly. I actually had a similar problem with structs too, but they mostly went away when I switched to the nightly.
This is not valid C++, like at all (well it is, but the initialization of the variables happens on the face3 plate; line which is before the used variables are initialized). The variables are uninitialized, so of course you will see weird behavior.


Code:
    point2 p2_1 = p2from3(p3_1);
    point2 p2_2 = p2from3(p3_2); // converting 3D points to 2D screen positions
    point2 p2_3 = p2from3(p3_3);
    point2 p2_4 = p2from3(p3_4);


superhelix wrote:
srupuduflupudu wrote:
Okay, so there is a new problem: the same code behaves differently each time it is run. sometimes it draws three or four lines, sometimes one, and sometimes none at all. Any ideas on what may be happening?


It's probably just compiler bugs producing bad assembly. I actually had a similar problem with structs too, but they mostly went away when I switched to the nightly.

No, and people should not assume this.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement