Qbasicnews.com

Full Version: Problem with COMMON and some arrays... (help me, v1c.)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hmm... I'm not quite sure how to explain this, so I'll start off simple. I've got two arrays that need to be shared between modules. They are both of type SDL_Surface POINTER. They are named Tileset() and Layers(). Their declarations are as follows:

Code:
COMMON SHARED Tileset()
DIM SHARED Tileset() AS SDL_Surface POINTER

COMMON SHARED Layers()
DIM SHARED Layers(1 TO 5) AS SDL_Surface POINTER

Note: adding "AS SDL_Surface POINTER" to the COMMON statements crashes the compiled program.

Tileset() is used by a SUB that automatically REDIM's the array as needed. Layers() is statically dimensioned to 5 elements (see above, 1 TO 5.) Tileset()'s contents are available in every one of my code modules (BAS files) when I compile, and the array works as expected (I can SDL_BlitSurface the elements of Tileset() to my screen just fine.) However, Layers()'s contents are not available to my other modules (BAS files) when I compile. When I initialize Layers()'s elements to SDL surfaces, and then try to use the contents of the array in a function in another file, Layer(X) returns 0. I can't determine why, either.

Somehow, I think that COMMON variables and arrays are only shared between the module currently being compiled and the previous modules having been compiled. Since my engine.bas file is compiled first, it gets its own copy of Layers(), but since sdlwrap.bas (which utilizes Tileset()) is compiled later, the previous modules get the same copy of Tileset() that sdlwrap.bas does, which lets the Tileset() array be shared correctly.

My compile.bat batch file is organized as follows:

Code:
adg -o declare.bi -h -p "Simple Mario Clone Declarations" -v 0.1 -a "Steven Hidy" *.bas
..\..\..\fbc -x mario.exe engine.bas sprites.bas map.bas sdlwrap.bas layout.bas

(ADG is my automatic declaration generator. Ignore that line ;-))
I'm using FBC 0.09.

See how the compiler is called: engine.bas is compiled before sdlwrap.bas. If I move the files around, so that engine.bas is in another compile position, the startup code I have placed in engine.bas is never run, and the program stops as soon as it starts (because there's no code to execute.)

To fix this, I attempted to use the "-m engine" option that FBC has. When I try to use this option, I get: "C:\FB\bin\ld.exe: warning: cannot find entry symbol engine; defaulting to 00401000."

Anyway, this problem is racking my brain. Please, someone help me out - I was on a roll earlier with my coding, but I just had to hit this huge brick wall. Argh! Haha.

Oh, yeah, v1c, is 0.11 a huge upgrade from 0.10? (0.10 seemed to have many, many problems.)
Known error fixed since 2 weeks ago or so:

Quote:[fixed] COMMON arrays shared between different sources had different descriptor names (v1c)

Patch will be on the next release, of course.

That's why the surface ptr crashes when accessed on different modules.

The -m option was bad too, you had to pass the full entry point name, now you have -entry if you really wants an non-standard entry--point and -m will use the main module to create the name, sorry -- doing: -m fb_engine_entry will fix it til the version 0.11 is released.
Thanks, v1c. You always save the day. :-D
So I guess I'll just sit back and wait patiently for 0.11, then. What a glorious day that will be. :-)

Thanks again; I thought I was breaking it with my insane code.