Skip to content

Commit

Permalink
UPBGE: Fix crash when calling Texture_init with material without text…
Browse files Browse the repository at this point in the history
…ure.

Previously if the texture index was pointing to an invalid RAS_Texture
a memory exeption was raised, because the Texture class in function
Texture_init was not checking if the RAS_Texture was valid before acces
to its datas.

To solve this a check is made and a new exeption TextureNotAvail is raised.
This exeption print the error message:
Texture is not available.
  • Loading branch information
youle31 authored and panzergame committed Sep 18, 2016
1 parent 460aef6 commit 5bc53ec
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions source/gameengine/VideoTexture/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ void registerAllExceptions(void)
{
errGenerDesc.registerDesc();
errNFoundDesc.registerDesc();
TextureNotAvailDesc.registerDesc();
MaterialNotAvailDesc.registerDesc();
ImageSizesNotMatchDesc.registerDesc();
ImageHasExportsDesc.registerDesc();
Expand Down
1 change: 1 addition & 0 deletions source/gameengine/VideoTexture/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class Exception : public std::exception
};

extern ExpDesc MaterialNotAvailDesc;
extern ExpDesc TextureNotAvailDesc;
extern ExpDesc ImageSizesNotMatchDesc;
extern ExpDesc ImageHasExportsDesc;
extern ExpDesc InvalidColorChannelDesc;
Expand Down
6 changes: 6 additions & 0 deletions source/gameengine/VideoTexture/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ static void Texture_dealloc(Texture *self)
ExceptionID MaterialNotAvail;
ExpDesc MaterialNotAvailDesc(MaterialNotAvail, "Texture material is not available");

ExceptionID TextureNotAvail;
ExpDesc TextureNotAvailDesc(TextureNotAvail, "Texture is not available");

// Texture object initialization
static int Texture_init(Texture *self, PyObject *args, PyObject *kwds)
{
Expand Down Expand Up @@ -242,6 +245,9 @@ static int Texture_init(Texture *self, PyObject *args, PyObject *kwds)
{
// get blender material texture
self->m_matTexture = mat->GetTexture(texID);
if (!self->m_matTexture) {
THRWEXCP(TextureNotAvail, S_OK);
}
self->m_imgTexture = self->m_matTexture->GetImage();
self->m_useMatTexture = true;
}
Expand Down
1 change: 1 addition & 0 deletions source/gameengine/VideoTexture/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,6 @@ short getMaterialID(PyObject *obj, const char *name);

// Exceptions
extern ExceptionID MaterialNotAvail;
extern ExceptionID TextureNotAvail;

#endif

0 comments on commit 5bc53ec

Please sign in to comment.