Author Topic: General Ndless Questions and Support  (Read 116794 times)

0 Members and 2 Guests are viewing this topic.

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: General Ndless Questions and Support
« Reply #105 on: December 16, 2012, 04:12:34 am »
Is there a limit to array size?
When I try to store large map data in an array, it crashes the emulator when it is too big
It depends what type of array you're trying to initialize. If you're putting this as a global variable this can be the cause.

Quote
Also it doesn't recognize bool as a type :P
Booleans have been introduced in c99 with a simple enum but are highly unportable since in C, any value is true and 0 is false.
In C++ it has became a specific type with operators overloading enabling this behavior to be standard.
I suggest you not to use the BOOL macros of Ndless and use int, short or char as your boolean.
« Last Edit: December 16, 2012, 04:15:13 am by Levak »
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: General Ndless Questions and Support
« Reply #106 on: December 16, 2012, 11:07:51 am »
It's inside of main(); so I think that's local.
It's defined as
int map[36][4][7][10]
Even though two of those dimentions are redundant.
Shortening it to
int map[252][40] causes it to crash, but that just may be from something in my code.
« Last Edit: December 16, 2012, 11:08:27 am by epic7 »

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: General Ndless Questions and Support
« Reply #107 on: December 16, 2012, 11:12:08 am »
int map[252][40] causes it to crash, but that just may be from something in my code.
You can use bkpt() to put a breakpoint and see what line causes the crash (using the emulator and the 'c' command).
« Last Edit: December 16, 2012, 11:12:46 am by Levak »
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: General Ndless Questions and Support
« Reply #108 on: December 16, 2012, 11:16:31 am »
Arrays on the stack cannot be larger than the size of the stack allocated to your program.

Code: [Select]
int map[36][4][7][10]General note: you should avoid multiple-dimension arrays (especially with such high dimension !), for efficiency reasons. Write your maps as a single-dimension array, and use accessor macros: this will avoid a huge amount of pointers ;)
« Last Edit: December 16, 2012, 11:16:44 am by Lionel Debroux »
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: General Ndless Questions and Support
« Reply #109 on: December 16, 2012, 12:25:53 pm »
I guess I'll see if int map[10080] works.

What are accessor macros?

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: General Ndless Questions and Support
« Reply #110 on: December 16, 2012, 12:32:42 pm »
I guess I'll see if int map[10080] works.
You may use malloc() if you still have issues

Quote
What are accessor macros?
Code: [Select]
#define WIDTH 100
#define GET(Tab, X, Y) ((Tab)[(X) * WIDTH + (Y))
....

int tile = GET(my_tab, 69, 42);
« Last Edit: December 16, 2012, 12:33:11 pm by Levak »
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: General Ndless Questions and Support
« Reply #111 on: December 16, 2012, 01:44:16 pm »
Tab being the array?

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: General Ndless Questions and Support
« Reply #112 on: December 16, 2012, 01:47:58 pm »
Nope, leave it like that : #define GET(Tab, X, Y) ((Tab)[(X) * WIDTH + (Y))
my_tab is your array, yes
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: General Ndless Questions and Support
« Reply #113 on: December 21, 2012, 09:35:57 pm »
How would I go about reading/writing an array to a file?
For writing, I have
   FILE * f = fopen("/documents/miner/mapdata.tns", "w+");
   for(j = 0; j < sizeof(map); j++)
      fprintf(f, "%d", map[j]);
   fclose(f);
   refresh_osscr();

but it crashes.
I don't know what I'm doing :P

Offline ExtendeD

  • Project Author
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: General Ndless Questions and Support
« Reply #114 on: December 24, 2012, 04:14:25 am »
It seems correct. Are you sure that this is the piece of code which crashes?
Also can you try without refresh_osscr()?
Ndless.me with the finest TI-Nspire programs

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: General Ndless Questions and Support
« Reply #115 on: December 24, 2012, 10:33:55 am »
sizeof gives size in bytes, not number of elements. You should really do:

for(j = 0; j < sizeof(map)/sizeof(map[0]); j++)

Edit: Also, I think your fprintf should probably print some whitespace too so you can actually read the numbers back later instead of getting an incomprehensible giant string of digits.
« Last Edit: December 24, 2012, 10:38:19 am by calc84maniac »
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: General Ndless Questions and Support
« Reply #116 on: December 24, 2012, 03:39:29 pm »
My new code is

   int map[10120];
   //stuff
   FILE * f = fopen("/documents/miner/mapdata.tns", "w+");
   for(j = 0; j < 10120; j++)
      fprintf(f, "%d ", map[j]);
   fclose(f);
   //refresh_osscr(); removing this line fixes it


And that works. So it seems that refresh screws it up. Now how do I read this back into the array?
« Last Edit: December 24, 2012, 03:44:00 pm by epic7 »

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: General Ndless Questions and Support
« Reply #117 on: December 24, 2012, 03:46:19 pm »
FILE * f = fopen("/documents/miner/mapdata.tns", "r");
for(j = 0; j < 10120; j++)
   fscanf(f, "%d", &map[j]);
fclose(f);
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: General Ndless Questions and Support
« Reply #118 on: December 24, 2012, 04:15:22 pm »
Does ndless support fscanf?
It throws an implicit declaration, and it also isn't included here

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: General Ndless Questions and Support
« Reply #119 on: January 01, 2013, 09:04:13 pm »
My my, someone should update the first post for Ndless 3 at some point...