2

I have this variable defined here:

const SDataGridCoord *clickedGridCoord;

and I am populating it in this method:

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid willSelectCellAtCoordinate:(const SDataGridCoord *)gridCoordinate
{
    if ((gridCoordinate.column.displayIndex==5||gridCoordinate.column.displayIndex == 6 || gridCoordinate.column.displayIndex == 7 ) && dataSource.dataForDatabase)
    {
        clickedGridCoord  = gridCoordinate;
        [self CreateCellDateModPopup:gridCoordinate];
    }
}

and I used a break point and see its being populated.

But when I goto call it, its empty:

CellData *cell = [dataSource.cellHolder objectAtIndex:clickedGridCoord.row];

and by empty I mean there is no row or column, but there is when I first populate the SDataGridCoord.

What am I doing wrong, there is nothing else that is overriding the variable.

I have tried this:

SDataGridCoord *clickedGridCoord;

then

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid willSelectCellAtCoordinate:(const SDataGridCoord *)gridCoordinate
{
    if ((gridCoordinate.column.displayIndex==5||gridCoordinate.column.displayIndex == 6 || gridCoordinate.column.displayIndex == 7 ) && dataSource.dataForDatabase)
    {
        clickedGridCoord = (SDataGridCoord *)gridCoordinate;
        [self CreateCellDateModPopup:gridCoordinate];
    }
}

still same result and my app still crashes: Thread 1:EXC_BAD_ACCESS (code = 1, address=0xc000000c)

My .m file:

@interface Controller()
{
     SDataGridCoord *clickedGridCoord;
}

@implementation Controller

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid willSelectCellAtCoordinate:(const SDataGridCoord *)gridCoordinate
{
    if ((gridCoordinate.column.displayIndex==5||gridCoordinate.column.displayIndex == 6 || gridCoordinate.column.displayIndex == 7 ) && dataSource.dataForDatabase)
    {
        clickedGridCoord = (SDataGridCoord *)gridCoordinate;
        [self CreateCellDateModPopup:clickedGridCoord];
    }
}


- (void)ChangeCellWithStringDate :(NSString *)stringDate
{
    //My app crashes here with this error: Thread 1:EXC_BAD_ACCESS (code = 1, address=0xc000000c)
    CellData *cell = [dataSource.cellHolder objectAtIndex:clickedGridCoord.row.rowIndex];
}
Luca Angeletti
  • 58,465
  • 13
  • 121
  • 148
user979331
  • 11,039
  • 73
  • 223
  • 418
  • 1
    Why did you declare `clickedGridCoord` as `const` ? – aytunch Apr 27 '15 at 21:07
  • 1
    because I get an error when I try to assign gridCoordinate to it which is also const – user979331 Apr 27 '15 at 21:50
  • any suggestions anyone? – user979331 Apr 28 '15 at 23:30
  • Please add some information: 1. In which line do you get the exception. I expect in the line you try to access the variable. (A variable is not called.) 2. `clickedGridCoord`has file scope or it is declared inside a `@interface'? I found the documentation for the used framework. You should add a link to the Q to make it public. (No one will find it in a comment.) https://www.shinobicontrols.com/docs/ShinobiControls/ShinobiGrids/2.5.1/Standard/Normal/index.html – Amin Negm-Awad Apr 30 '15 at 11:56
  • clickedGridCoord is defined inside my interface above @implementation – user979331 Apr 30 '15 at 12:45
  • "inside my interface above implementation"? Usually an interface is in a different file. – Amin Negm-Awad Apr 30 '15 at 14:35
  • I have updated my question. My `@interface` and `@implementation` are in the same file. @Amin Negm-Awad – user979331 Apr 30 '15 at 19:24
  • Okay, it is a class continuation, not a regular interface. Usually that is in the same file. You still did not say, in which line the exception is thrown. – Amin Negm-Awad Apr 30 '15 at 19:34
  • Did you check whether the write access to the ivar is in the same instance as the read access (logging with `%p` on `self`)? Why didn't you use properties? – Amin Negm-Awad Apr 30 '15 at 19:36

2 Answers2

2

Are you using some pre-ARC library? If so I suspect that someone (and by someone I mean some code) is manually releasing one more time the object referenced by gridCoordinate.

This cause the object to be deallocated and you end up with a reference to a wrong memory location (because the object is gone).

If you have the source code of SDataGridCoord please add a breakpoint in the dealloc method and look if it gets called before you try to use the object in

- (void)ChangeCellWithStringDate :(NSString *)stringDate

Finally, if this is happening you should create another SDataGridCoord object (a copy that will be only yours) and assigning it to your ivar. It will be managed by ARC and everything will be just fine.

Luca Angeletti
  • 58,465
  • 13
  • 121
  • 148
0

Try adding your variable to the interface of your .m

@interface YOUR_OBJECT ()
{
    SDataGridCoord *_clickedGridCoord;
}
@end
Konrad Wright
  • 1,254
  • 11
  • 24