mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 09:46:02 +08:00
[sdl] Better leak detection in example
This commit is contained in:
parent
dcaa4f935e
commit
d3c8ccbfc1
@ -29,14 +29,20 @@
|
|||||||
|
|
||||||
#include <spine-sdl-cpp.h>
|
#include <spine-sdl-cpp.h>
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
#include <spine/Debug.h>
|
||||||
#undef main
|
#undef main
|
||||||
|
spine::DebugExtension dbgExtension(spine::SpineExtension::getInstance());
|
||||||
|
extern spine::SkeletonRenderer *skeletonRenderer;
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main() {
|
||||||
|
spine::SpineExtension::setInstance(&dbgExtension);
|
||||||
|
{
|
||||||
if (SDL_Init(SDL_INIT_VIDEO)) {
|
if (SDL_Init(SDL_INIT_VIDEO)) {
|
||||||
printf("Error: %s", SDL_GetError());
|
printf("Error: %s", SDL_GetError());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
SDL_Window *window = SDL_CreateWindow("Spine SDL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, 0);
|
SDL_Window *window = SDL_CreateWindow("Spine SDL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600,
|
||||||
|
0);
|
||||||
if (!window) {
|
if (!window) {
|
||||||
printf("Error: %s", SDL_GetError());
|
printf("Error: %s", SDL_GetError());
|
||||||
return -1;
|
return -1;
|
||||||
@ -88,5 +94,9 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
delete skeletonData;
|
||||||
|
}
|
||||||
|
delete skeletonRenderer;
|
||||||
|
dbgExtension.reportLeaks();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,10 +33,11 @@
|
|||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
|
||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
|
#include <spine/Debug.h>
|
||||||
|
|
||||||
using namespace spine;
|
using namespace spine;
|
||||||
|
|
||||||
SkeletonRenderer skeletonRenderer;
|
SkeletonRenderer *skeletonRenderer = nullptr;
|
||||||
|
|
||||||
SkeletonDrawable::SkeletonDrawable(SkeletonData *skeletonData, AnimationStateData *animationStateData) {
|
SkeletonDrawable::SkeletonDrawable(SkeletonData *skeletonData, AnimationStateData *animationStateData) {
|
||||||
Bone::setYDown(true);
|
Bone::setYDown(true);
|
||||||
@ -61,14 +62,15 @@ void SkeletonDrawable::update(float delta, Physics physics) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void toSDLColor(uint32_t color, SDL_Color *sdlColor) {
|
inline void toSDLColor(uint32_t color, SDL_Color *sdlColor) {
|
||||||
sdlColor->r = (color >> 24) & 0xFF;
|
sdlColor->a = (color >> 24) & 0xFF;
|
||||||
sdlColor->g = (color >> 16) & 0xFF;
|
sdlColor->r = (color >> 16) & 0xFF;
|
||||||
sdlColor->b = (color >> 8) & 0xFF;
|
sdlColor->g = (color >> 8) & 0xFF;
|
||||||
sdlColor->a = color & 0xFF;
|
sdlColor->b = color & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonDrawable::draw(SDL_Renderer *renderer) {
|
void SkeletonDrawable::draw(SDL_Renderer *renderer) {
|
||||||
RenderCommand *command = skeletonRenderer.render(*skeleton);
|
if (!skeletonRenderer) skeletonRenderer = new (__FILE__, __LINE__) SkeletonRenderer();
|
||||||
|
RenderCommand *command = skeletonRenderer->render(*skeleton);
|
||||||
while(command) {
|
while(command) {
|
||||||
float *positions = command->positions;
|
float *positions = command->positions;
|
||||||
float *uvs = command->uvs;
|
float *uvs = command->uvs;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user