gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Illegal byte read

#18827 - JL - Tue Apr 06, 2004 4:03 pm

Hi guys,

I'm using vba for debugging and I ran into the following (from trace.log):

.
.
.
DMA3: s=02000030 d=07000000 c=8400 bytes=00000400
Illegal byte read: 0000000c at 08006a64
Illegal byte read: 0000000c at 08006a64
Illegal byte read: 0000000c at 08006a64


Now, by checking out what's at 0x08006a64 I found out that all I'm doing is calling a (virtual) method from a C++ class, like this:

myObjects[j]->setvisibility(myObjects[0]);

(j is valid, ofcourse... so are the object arrays).

When I remove the call to that function, the illegal reads disappear. So, my question is, what's wrong here? What does illegal read mean in this context, is something not aligned correctly? Can anyone shed some light on this? Thanks in advance!

Grtz,
Niels

#18828 - jma - Tue Apr 06, 2004 4:15 pm

Is myObjects a NULL pointer? That would be my guess. j is just an index into an array (that isn't set AFAICT).

Jeff
_________________
massung@gmail.com
http://www.retrobyte.org

#18833 - JL - Tue Apr 06, 2004 8:26 pm

No, myObjects is definitely not a NULL pointer. It is an array that's declared elsewhere, to be exact I define it in the header of the class:

class LevMan
{
public:
/* snip, irrelevant */

private:
// Objects administration
int myNrObjects;
Object* myObjects[MAX_OBJECTS];
};

The array gets filled with pointers to Objects and I run through the array with a for loop (that's where the j comes in from my previous code snippet, j has a valid value).

Anyway, when I try the code on just the first object (that I KNOW is there), the illegal read happens. Funny thing is, VBA notices it and reports it but there is otherwise no directly noticable effect. The method gets called and my program runs through.

So, can anyone shed any light on my illegal read activities? ;-)

What is meant by illegal byte read and why would it happen when calling a method (or could it be my array subscriptor.....?)? Any help appreciated.

Grtz,
Niels

#18853 - bats - Wed Apr 07, 2004 3:02 am

the format for Illegal Reads or Writes is
Code:

Illegal [Byte/Halfword/Word] Read: (Read Address) from (PC address)
Illegal [Byte/Halfword/Word] Write: (Value) to (Write Address) from (PC address)

although the pc address is off by 2 bytes (at least in my test case).
So, with your read address being 0xc ... it seems like you're dereferencing a NULL pointer. Check your assembly listing.

Ben

#18861 - JL - Wed Apr 07, 2004 9:27 am

Hi guys,

Thanks for all your input, I solved it now! What happened was that I used an if-statement, like this:

if (blabla)
{
myObjects[j]->setvisibility(myObjects[0]);
}

And by removing the call to setvisibility the read error disappeared, however that call was not the problem! Indeed, somewhere in my blabla expression a NULL pointer could be dereff-ed. But the entire if-statement was removed (rightly so) by the optimizer (I use the -O3 compiler setting) when I deleted the call to setvisibility so that's why I initially suspected that call to be the cause.

Thanks again guys!
Niels