DarthMike / indielib-crossplatform

IndieLib is a cross-platform Game Graphics engine. Main focus is OpenGL ES 2.0 for mobile iOS operating system, and OpenGL desktop. **NOT SUPPORTED ANYMORE**
zlib License
61 stars 27 forks source link

Collisions test does not report collision #104

Closed DarthMike closed 11 years ago

DarthMike commented 11 years ago

For both DirectX and OpenGL

Spotted as a regression. Need to investigate if text is not rendered or there is a real regression.

AlainBridel commented 11 years ago

The problem reside in IND_Entity2d::setBoundingxxxx functions. The string id of the collision is not dynamically allocated but on the function stack, so storing the id is made on a wrong pointer.

I have managed to make this work this way in the IND_Entity2d::setBoundingxxxx functions after reading the CollisionParser::parseCollision : / char stringTemp[128]; char pIdCharTemp = strcpy(stringTemp, pId); / char pIdCharTemp = new char [1+strlen(pId)]; strcpy(pIdCharTemp, pId);

But also,after looking at the CollisionParser::deleteBoundingAreas I have added if (!strcmp((listIter)->id, pId) || !strcmp(pId, "")) { ----> DISPOSE((listIter)->_id); <---- also needs to updatde setBoundingRectangle because of 2 triangles feeding the rectangle with same id DISPOSE((__listIter));

Hope it helps,

Alain.

M-F-K commented 11 years ago

Hi Alain,

Thanks =)

The char ....[128] was probably part of the char* to const* warning fix ( #issue 97 done by me :-( ).

for example look here: https://github.com/DarthMike/indielib-crossplatform/commit/993c30a63f4f13791a2c41eb737f4e9c3c59f2dc

and here:

https://github.com/DarthMike/indielib-crossplatform/commit/993c30a63f4f13791a2c41eb737f4e9c3c59f2dc

or by grepping the source for [128] ....

anyway... DartMike - should we do this fix :

/ char stringTemp[128]; char pIdCharTemp = strcpy(stringTemp, pId); / char pIdCharTemp = new char [1+strlen(pId)]; strcpy(pIdCharTemp, pId);

all the places I have chaged regarding to #issue 97 ?

Regards.

Michael.

DarthMike commented 11 years ago

Hi.

@AlainBridel Thanks a lot! About the DISPOSE fix, you are right, but I would fix it in StructBoundingCollision Let's open another issue for that one.

I searched for ''chartemp" in project. I propose following fix: //Change char* to const char* in following methods CollisionParser::setBoundingRectangle CollisionParser::setBoundingTriangle CollisionParser::setBoundingCircle CollisionParser::deleteBoundingAreas IND_Animation::parseAnimation(..)

In all places where this was introduced: char stringTemp[128]; char *pIdCharTemp = strcpy(stringTemp, pId);

we don't need to create additional temp string, but to change char* to const char* in arguments of method where pldCharTemp is passed, and leave as before.

then I would add the allocation of string inside every one of this method: CollisionParser::setBoundingRectangle CollisionParser::setBoundingTriangle CollisionParser::setBoundingCircle

by calling: if (_b->_id) { delete ; }

_b->_id = new char [1+strlen(pId)]; strcpy(_b->_id, pId);

@M-F-K I assigned you the issue. Could you fix it?

Running the collision test you can test if it works or not.

DarthMike commented 11 years ago

Fixed. I corrected many other mistakes and incoherences related to buffer allocation. Some code was from old Indielib mem. management, which is quite disorganized.