Fix (unreported) crash in blendkernel unittest in debug builds.
Some `ImagePartialUpdateTest` test are calling code that needs access to a valid `G_MAIN`. So store the generated main there as part of the setup step, and reset G_MAIN to its original value (should be NULL) in the teardown step. NOTE: Things like `ID_BLEND_PATH_FROM_GLOBAL` and `BKE_main_blendfile_path_from_global` are pure evil. It may be necessary in a very few small cases, but their current usages need a lot of strong cleanup. Pull Request: https://projects.blender.org/blender/blender/pulls/108189
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "CLG_log.h"
|
||||
|
||||
#include "BKE_appdir.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_idtype.h"
|
||||
#include "BKE_image.h"
|
||||
#include "BKE_image_partial_update.hh"
|
||||
@@ -24,6 +25,7 @@ constexpr float black_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
class ImagePartialUpdateTest : public testing::Test {
|
||||
protected:
|
||||
Main *bmain;
|
||||
Main *prev_bmain;
|
||||
Image *image;
|
||||
ImageTile *image_tile;
|
||||
ImageUser image_user = {nullptr};
|
||||
@@ -55,6 +57,9 @@ class ImagePartialUpdateTest : public testing::Test {
|
||||
IMB_init();
|
||||
|
||||
bmain = BKE_main_new();
|
||||
/* Required by usage of #ID_BLEND_PATH_FROM_GLOBAL in #add_ibuf_for_tile. */
|
||||
prev_bmain = G_MAIN;
|
||||
G_MAIN = bmain;
|
||||
/* Creating an image generates a memory-leak during tests. */
|
||||
image = create_test_image(1024, 1024);
|
||||
image_tile = BKE_image_get_tile(image, 0);
|
||||
@@ -67,6 +72,9 @@ class ImagePartialUpdateTest : public testing::Test {
|
||||
{
|
||||
BKE_image_release_ibuf(image, image_buffer, nullptr);
|
||||
BKE_image_partial_update_free(partial_update_user);
|
||||
|
||||
/* Restore original main in G_MAIN. */
|
||||
G_MAIN = prev_bmain;
|
||||
BKE_main_free(bmain);
|
||||
|
||||
IMB_moviecache_destruct();
|
||||
|
||||
Reference in New Issue
Block a user