We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3888 - Cannot create custom effect
Summary: Cannot create custom effect
Status: NEW
Alias: None
Product: SDL
Classification: Unclassified
Component: haptic (show other bugs)
Version: 2.0.6
Hardware: x86 Windows 10
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-16 07:59 UTC by Laban
Modified: 2017-10-16 07:59 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Laban 2017-10-16 07:59:30 UTC
Trying to create effect of type SDL_HAPTIC_CUSTOM, returns failure code (-1) and message “Haptic error Unable to create effect”.

Is SDL_HapticCustom.data (Uint16*) really supposed to be unsigned if it is a custom signal? Should be able to have negative values as well?

Trying with gaming wheel 'Thrustmaster T300RS Racing Wheel', windows 10.

Call chain is:
[My code]->
int SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect);
int SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base);
int SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base)
  --> DI_SetError("Unable to create effect", ret);


[My code in effective]
SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC);
int device_index = 0;
SDL_Joystick* joystick = SDL_JoystickOpen(device_index);
assert(SDL_JoystickIsHaptic(joystick));
SDL_Haptic* haptic = SDL_HapticOpen(device_index);

SDL_HapticEffect* effect = new SDL_HapticEffect;
SDL_memset(effect , 0, sizeof(SDL_HapticEffect));
effect->type = SDL_HAPTIC_CUSTOM;
effect->custom.direction.type = SDL_HAPTIC_CARTESIAN;
effect->custom.direction.dir[0] = 1;
effect->custom.length = 5000;
effect->custom.period = 1000;
const int nof_samples = 1000;
effect->custom.channels = 1;
effect->custom.samples = nof_samples;
effect->custom.data = new Uint16[nof_samples];

for(int i = 0; i < nof_samples; ++i) {
  effect->custom.data[i] = Uint16(0); //Or some generated signal
}

assert(SDL_HapticEffectSupported(haptic, effect)); //All ok!

std::cout << SDL_HapticNewEffect(haptic, effect) << std::endl; //Returns -1
std::cout << SDL_GetError() << std::endl; //prints "Haptic error Unable to create effect"